Issue #2915: Rewrite TextDBStaticData class.

Change-Id: I078f9c4a35e0477ee1248bb66f449d7fe4b165a1

Former-commit-id: 6124d62120 [formerly b27d83cc5123d08de450a45edb40ea722fc95c58]
Former-commit-id: 9f50f29a67
This commit is contained in:
David Gillingham 2014-04-01 13:24:48 -05:00
parent 27d2911801
commit c899410f7b
11 changed files with 470 additions and 459 deletions

View file

@ -39,16 +39,19 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
* TODO Add Description * TODO Add Description
* *
* <pre> * <pre>
*
* SOFTWARE HISTORY * SOFTWARE HISTORY
*
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Aug 12, 2008 jkorman Initial creation * Aug 12, 2008 jkorman Initial creation
* Jul 10, 2009 2191 rjpeter Finished implementation. * Jul 10, 2009 2191 rjpeter Finished implementation.
* 06/29/2012 15154 D. Friedman Fix detection of TAF collectives. * Jun 29, 2012 15154 D. Friedman Fix detection of TAF collectives.
* ====================================== * Jul 25, 2012 959 jkorman Modified order of entry for determining
* AWIPS2 DR Work * the data type (standard or collective)
* 07/25/2012 959 jkorman Modified order of entry for determining * for input data.
* the data type (standard or collective) for input data. * Apr 01, 2014 2915 dgilling Support re-factored TextDBStaticData.
*
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
@ -63,9 +66,6 @@ public class TextSeparatorFactory {
private static final String siteId = PropertiesFactory.getInstance() private static final String siteId = PropertiesFactory.getInstance()
.getEnvProperties().getEnvValue("SITENAME"); .getEnvProperties().getEnvValue("SITENAME");
private static final TextDBStaticData staticData = TextDBStaticData
.instance(siteId);
private static Pattern TAF_PTRN = Pattern.compile("^TAF\\s*$"); private static Pattern TAF_PTRN = Pattern.compile("^TAF\\s*$");
/** /**
@ -113,7 +113,7 @@ public class TextSeparatorFactory {
wmoHeader, TextDecoderMode.WARN); wmoHeader, TextDecoderMode.WARN);
break; break;
} }
// These message types fall through. // These message types fall through.
case MSG_UNKNOWN: case MSG_UNKNOWN:
case MSG_DISCARD: case MSG_DISCARD:
default: { default: {
@ -199,11 +199,11 @@ public class TextSeparatorFactory {
// Maintain this order of entry so that Standard Text products // Maintain this order of entry so that Standard Text products
// are checked before collectives. // are checked before collectives.
if ((stdAfosId = staticData.getProductId(ispanId)) != null) { if ((stdAfosId = TextDBStaticData.getProductId(ispanId)) != null) {
msgType = WMOMessageType.STD_TEXT; msgType = WMOMessageType.STD_TEXT;
} else if (staticData.matchStdCollective(dataDes) != null) { } else if (TextDBStaticData.matchStdCollective(dataDes) != null) {
msgType = WMOMessageType.STD_COLLECTIVE; msgType = WMOMessageType.STD_COLLECTIVE;
} else if (staticData.matchUACollective(dataDes) != null) { } else if (TextDBStaticData.matchUACollective(dataDes) != null) {
msgType = WMOMessageType.UA_COLLECTIVE; msgType = WMOMessageType.UA_COLLECTIVE;
} }
@ -211,11 +211,11 @@ public class TextSeparatorFactory {
if (msgType == null) { if (msgType == null) {
if (!hdr.startsWith("SXUS70") if (!hdr.startsWith("SXUS70")
&& !hdr.startsWith("FRUS45") && !hdr.startsWith("FRUS45")
&& (firstLineLen > 6 || && (firstLineLen > 6 || TAF_PTRN.matcher(firstLine)
TAF_PTRN.matcher(firstLine).matches()) .matches())
&& (hdr.startsWith("SA") || hdr.startsWith("SP") && (hdr.startsWith("SA") || hdr.startsWith("SP")
|| hdr.startsWith("FR") || hdr || hdr.startsWith("FR") || hdr
.startsWith("FT"))) { .startsWith("FT"))) {
msgType = WMOMessageType.STD_COLLECTIVE; msgType = WMOMessageType.STD_COLLECTIVE;
} else if (!hdr.startsWith("UAXX") } else if (!hdr.startsWith("UAXX")
&& firstLineLen > 6 && firstLineLen > 6
@ -223,12 +223,12 @@ public class TextSeparatorFactory {
|| hdr.startsWith("UI") || hdr.startsWith("UI")
|| hdr.startsWith("UM") || hdr.startsWith("UM")
|| hdr.startsWith("UP") || hdr || hdr.startsWith("UP") || hdr
.startsWith("US"))) { .startsWith("US"))) {
msgType = WMOMessageType.UA_COLLECTIVE; msgType = WMOMessageType.UA_COLLECTIVE;
} else if (ispanId.startsWith("W") } else if (ispanId.startsWith("W")
|| ("NOUS71KNCF".equals(ispanId) || ("NOUS71KNCF".equals(ispanId)
|| "NTUS96KNCF".equals(ispanId) || "NTUS98KNCF" || "NTUS96KNCF".equals(ispanId) || "NTUS98KNCF"
.equals(ispanId))) { .equals(ispanId))) {
msgType = WMOMessageType.WARN; msgType = WMOMessageType.WARN;
} else { } else {
msgType = WMOMessageType.STD_TEXT; msgType = WMOMessageType.STD_TEXT;
@ -237,7 +237,7 @@ public class TextSeparatorFactory {
if (WMOMessageType.STD_TEXT.equals(msgType) if (WMOMessageType.STD_TEXT.equals(msgType)
&& stdAfosId != null) { && stdAfosId != null) {
if (staticData.isExcluded(stdAfosId)) { if (TextDBStaticData.isExcluded(stdAfosId)) {
logger.debug("NCF_ENTRY " + ispanId + " is skipped"); logger.debug("NCF_ENTRY " + ispanId + " is skipped");
} }
} }

View file

@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import com.raytheon.edex.esb.Headers; import com.raytheon.edex.esb.Headers;
import com.raytheon.edex.plugin.text.impl.TextSeparatorFactory; import com.raytheon.edex.plugin.text.impl.TextSeparatorFactory;
import com.raytheon.edex.textdb.dbapi.impl.TextDBStaticData;
import com.raytheon.edex.textdb.dbapi.impl.WMOReportData; import com.raytheon.edex.textdb.dbapi.impl.WMOReportData;
import com.raytheon.uf.common.site.SiteMap; import com.raytheon.uf.common.site.SiteMap;
import com.raytheon.uf.edex.wmo.message.AFOSProductId; import com.raytheon.uf.edex.wmo.message.AFOSProductId;
@ -46,6 +47,7 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
* Mar 06, 2014 2652 skorolev Corrected rawMsg extraction. * Mar 06, 2014 2652 skorolev Corrected rawMsg extraction.
* Mar 14, 2014 2652 skorolev Changed logging for skipped headers. * Mar 14, 2014 2652 skorolev Changed logging for skipped headers.
* Fixed calculation of message end. * Fixed calculation of message end.
* Apr 01, 2014 2915 dgilling Support re-factored TextDBStaticData.
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
@ -92,7 +94,8 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
protected void createProductId() { protected void createProductId() {
WMOHeader wmoHeader = getWmoHeader(); WMOHeader wmoHeader = getWmoHeader();
String hdr = wmoHeader.getWmoHeader(); String hdr = wmoHeader.getWmoHeader();
String afosId = staticData.matchStdCollective(createDataDes(wmoHeader)); String afosId = TextDBStaticData
.matchStdCollective(createDataDes(wmoHeader));
if (afosId != null) { if (afosId != null) {
// String ccc = SiteMap.getInstance().getCCCFromXXXCode(siteId); // String ccc = SiteMap.getInstance().getCCCFromXXXCode(siteId);
@ -269,8 +272,9 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
// filter out junk characters // filter out junk characters
while (buffer.length() > 0 while (buffer.length() > 0
&& !checkCharNum(buffer.charAt(0))) && !checkCharNum(buffer.charAt(0))) {
buffer.deleteCharAt(0); buffer.deleteCharAt(0);
}
// again, trash data if it is less than 20 bytes // again, trash data if it is less than 20 bytes
if (buffer.length() < MIN_COLL_DATA_LEN) { if (buffer.length() < MIN_COLL_DATA_LEN) {
@ -444,8 +448,9 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
} else if (buffer.charAt(0) == (char) 0x1e) { } else if (buffer.charAt(0) == (char) 0x1e) {
parsedMsg.setLength(parsedMsg.length() - 3); parsedMsg.setLength(parsedMsg.length() - 3);
} else if (buffer.charAt(0) == '=') { } else if (buffer.charAt(0) == '=') {
if (safeStrpbrk(buffer, CSPL)) if (safeStrpbrk(buffer, CSPL)) {
buffer.deleteCharAt(0); buffer.deleteCharAt(0);
}
} else if ((buffer.charAt(0) == EOM) } else if ((buffer.charAt(0) == EOM)
&& (parsedMsg.length() > (MIN_COLL_DATA_LEN - 1))) { && (parsedMsg.length() > (MIN_COLL_DATA_LEN - 1))) {
checkFouHeader = true; checkFouHeader = true;
@ -458,8 +463,9 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
if ((reportType != null) if ((reportType != null)
&& (reportType.equals("METAR") || reportType.equals("SPECI") && (reportType.equals("METAR") || reportType.equals("SPECI")
|| reportType.equals("TESTM") || reportType || reportType.equals("TESTM") || reportType
.equals("TESTS"))) .equals("TESTS"))) {
parsedMsg.insert(0, reportType + " "); parsedMsg.insert(0, reportType + " ");
}
} }
/** /**
@ -483,20 +489,18 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
// If this is a national bit product, then CCC = CCC of the current // If this is a national bit product, then CCC = CCC of the current
// site. // site.
if ("AAA".equals(afos_id.getCcc())) if ("AAA".equals(afos_id.getCcc())) {
CCC_id = SiteMap.getInstance().getCCCFromXXXCode(siteId); CCC_id = SiteMap.getInstance().getCCCFromXXXCode(siteId);
// Otherwise, use the national category table to get the CCC from the } else if ((CCC_id = TextDBStaticData.mapICAOToCCC(XXX_id.toString())) == null) {
// XXX
else if ((CCC_id = staticData.mapICAOToCCC(XXX_id.toString())) == null) {
// We failed to get a CCC from the national_category_table... // We failed to get a CCC from the national_category_table...
// If the XXX is 3 characters, and the origin starts with K, try // If the XXX is 3 characters, and the origin starts with K, try
// prepending K or P (the latter for AK, HI products) // prepending K or P (the latter for AK, HI products)
if (trimmedXXX.length() == 3 && origin.startsWith("K")) { if (trimmedXXX.length() == 3 && origin.startsWith("K")) {
newId = "K" + trimmedXXX; newId = "K" + trimmedXXX;
if ((CCC_id = staticData.mapICAOToCCC(newId)) == null) { if ((CCC_id = TextDBStaticData.mapICAOToCCC(newId)) == null) {
newId = "P" + trimmedXXX; newId = "P" + trimmedXXX;
if ((CCC_id = staticData.mapICAOToCCC(newId)) == null) { if ((CCC_id = TextDBStaticData.mapICAOToCCC(newId)) == null) {
// logger.error("NCF_FAIL to map XXX to CCC: " + // logger.error("NCF_FAIL to map XXX to CCC: " +
// XXX_id); // XXX_id);
subHeadersSkipped subHeadersSkipped
@ -514,7 +518,7 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
// character of the origin. // character of the origin.
else if (trimmedXXX.length() == 3) { else if (trimmedXXX.length() == 3) {
newId = origin.charAt(0) + trimmedXXX; newId = origin.charAt(0) + trimmedXXX;
if ((CCC_id = staticData.mapICAOToCCC(newId)) == null) { if ((CCC_id = TextDBStaticData.mapICAOToCCC(newId)) == null) {
subHeadersSkipped subHeadersSkipped
.put(newWmoHdr, .put(newWmoHdr,
"Product " "Product "
@ -533,7 +537,7 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
+ " is excluded from storage due to incorrect xxxid" + " is excluded from storage due to incorrect xxxid"
+ XXX_id); + XXX_id);
return false; return false;
} else } else {
// If trimmedXXX has 4 characters and not found in // If trimmedXXX has 4 characters and not found in
// national_category_table.template. // national_category_table.template.
subHeadersSkipped subHeadersSkipped
@ -543,6 +547,7 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
+ " is excluded from storage due to " + " is excluded from storage due to "
+ trimmedXXX + trimmedXXX
+ " not present in national_category_table.template"); + " not present in national_category_table.template");
}
return false; return false;
} }
} }
@ -554,10 +559,11 @@ public class StdCollectiveSeparator extends WMOMessageSeparator {
product_id.setNnn(afos_id.getNnn()); product_id.setNnn(afos_id.getNnn());
// Put all three of the id pieces together. // Put all three of the id pieces together.
if (trimmedXXX.length() == 3) if (trimmedXXX.length() == 3) {
product_id.setXxx(trimmedXXX); product_id.setXxx(trimmedXXX);
else } else {
product_id.setXxx(XXX_id.substring(1, 4)); product_id.setXxx(XXX_id.substring(1, 4));
}
return true; return true;
} }
} }

View file

@ -42,6 +42,7 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
* Jul 26, 2011 10043 rferrel Modified identifyReports to * Jul 26, 2011 10043 rferrel Modified identifyReports to
* have checks like A1. * have checks like A1.
* Mar 13, 2014 2652 skorolev Fixed calculation of message end. * Mar 13, 2014 2652 skorolev Fixed calculation of message end.
* Apr 01, 2014 2915 dgilling Support re-factored TextDBStaticData.
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
@ -69,7 +70,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
@Override @Override
protected void createProductId() { protected void createProductId() {
String ispanId = createIspanId(getWmoHeader()); String ispanId = createIspanId(getWmoHeader());
String afosId = staticData.getProductId(ispanId); String afosId = TextDBStaticData.getProductId(ispanId);
if (afosId != null) { if (afosId != null) {
productId = new AFOSProductId(afosId); productId = new AFOSProductId(afosId);
@ -87,11 +88,11 @@ public class StdTextSeparator extends WMOMessageSeparator {
WMOHeader wmoHeader = getWmoHeader(); WMOHeader wmoHeader = getWmoHeader();
String ispanId = createIspanId(wmoHeader); String ispanId = createIspanId(wmoHeader);
String product_id = TextDBStaticData.instance(siteId).getProductId( String product_id = TextDBStaticData.getProductId(ispanId);
ispanId);
// check whether to exclude from decoding for storage // check whether to exclude from decoding for storage
if (product_id != null && staticData.isExcluded(product_id.toString())) { if (product_id != null
&& TextDBStaticData.isExcluded(product_id.toString())) {
logger.debug("NCF_ENTRY " + product_id.toString() + " is skipped"); logger.debug("NCF_ENTRY " + product_id.toString() + " is skipped");
return; return;
} }
@ -196,7 +197,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
} }
// check whether incoming product is excluded from storage // check whether incoming product is excluded from storage
if (staticData.isExcluded(product_id.toString())) { if (TextDBStaticData.isExcluded(product_id.toString())) {
logger.debug("NCF_ENTRY " + product_id.toString() + " is skipped"); logger.debug("NCF_ENTRY " + product_id.toString() + " is skipped");
return true; return true;
} }
@ -354,7 +355,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
// table. // table.
if (stdFlg) { if (stdFlg) {
logger.trace("Mapping from stdflag."); logger.trace("Mapping from stdflag.");
newId = staticData.getProductId(ispanId); newId = TextDBStaticData.getProductId(ispanId);
if (newId == null) { if (newId == null) {
// logger.error("Unable to create AFOS id - ispan table."); // logger.error("Unable to create AFOS id - ispan table.");
return false; return false;
@ -368,7 +369,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
// Check to see if the product is a non-collective METAR (out of // Check to see if the product is a non-collective METAR (out of
// country), and map against the ISPAN table to get the id. // country), and map against the ISPAN table to get the id.
newId = staticData.getProductId(ispanId); newId = TextDBStaticData.getProductId(ispanId);
if (newId == null) { if (newId == null) {
// logger.error("Unable to create AFOS id - ispan table"); // logger.error("Unable to create AFOS id - ispan table");
return false; return false;
@ -381,16 +382,16 @@ public class StdTextSeparator extends WMOMessageSeparator {
// Try to map the nnnId with the bit table for a national bit product; // Try to map the nnnId with the bit table for a national bit product;
// otherwise, check the AFOS table for the ccc value of the origin. // otherwise, check the AFOS table for the ccc value of the origin.
newId = staticData.getSiteIdFromNNN(nnnId); newId = TextDBStaticData.getSiteIdFromNNN(nnnId, siteId);
if (newId == null) { if (newId == null) {
cccId = staticData.getAFOSTableMap(origin); cccId = TextDBStaticData.getAFOSTableMap(origin);
if (cccId == null) { if (cccId == null) {
if (nnnxxx.length() >= 6) { if (nnnxxx.length() >= 6) {
cccId = staticData.getAFOSTableMap("K" cccId = TextDBStaticData.getAFOSTableMap("K"
+ nnnxxx.substring(3, 6)); + nnnxxx.substring(3, 6));
} else if (nnnxxx.length() > 3) { } else if (nnnxxx.length() > 3) {
cccId = staticData.getAFOSTableMap("K" cccId = TextDBStaticData.getAFOSTableMap("K"
+ nnnxxx.substring(3)); + nnnxxx.substring(3));
} }
if (cccId == null) { // KWBC RCM,VER if (cccId == null) { // KWBC RCM,VER
@ -421,7 +422,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
if ((newId.length() < 7) || (newId.length() > 9)) { if ((newId.length() < 7) || (newId.length() > 9)) {
// If the length is bad, try mapping to the ispan table with the // If the length is bad, try mapping to the ispan table with the
// ispan id. // ispan id.
newId = staticData.getProductId(ispanId); newId = TextDBStaticData.getProductId(ispanId);
if (newId == null) { if (newId == null) {
// logger.error("Unable to create AFOS id - ispan table"); // logger.error("Unable to create AFOS id - ispan table");
return false; return false;
@ -445,7 +446,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
} }
} }
if (badflag) { if (badflag) {
newId = staticData.getProductId(ispanId); newId = TextDBStaticData.getProductId(ispanId);
if (newId == null) { if (newId == null) {
// logger.error("Invalid product - ispan table."); // logger.error("Invalid product - ispan table.");
return false; return false;
@ -458,7 +459,7 @@ public class StdTextSeparator extends WMOMessageSeparator {
} }
} }
} else { } else {
newId = staticData.getProductId(ispanId); newId = TextDBStaticData.getProductId(ispanId);
if (newId == null) { if (newId == null) {
// logger.error("Invalid product - ispan table."); // logger.error("Invalid product - ispan table.");
return false; return false;

View file

@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory;
import com.raytheon.edex.esb.Headers; import com.raytheon.edex.esb.Headers;
import com.raytheon.edex.plugin.text.impl.TextSeparatorFactory; import com.raytheon.edex.plugin.text.impl.TextSeparatorFactory;
import com.raytheon.edex.textdb.dbapi.impl.TextDBStaticData;
import com.raytheon.edex.textdb.dbapi.impl.WMOReportData; import com.raytheon.edex.textdb.dbapi.impl.WMOReportData;
import com.raytheon.uf.edex.wmo.message.AFOSProductId; import com.raytheon.uf.edex.wmo.message.AFOSProductId;
import com.raytheon.uf.edex.wmo.message.WMOHeader; import com.raytheon.uf.edex.wmo.message.WMOHeader;
@ -43,6 +44,7 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
* Sep 3, 2008 jkorman Initial creation * Sep 3, 2008 jkorman Initial creation
* Jul 10, 2009 2191 rjpeter Reimplemented. * Jul 10, 2009 2191 rjpeter Reimplemented.
* Mar 13, 2014 2652 skorolev Fixed calculation of message end. * Mar 13, 2014 2652 skorolev Fixed calculation of message end.
* Apr 01, 2014 2915 dgilling Support re-factored TextDBStaticData.
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
@ -88,7 +90,8 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
protected void createProductId() { protected void createProductId() {
WMOHeader wmoHeader = getWmoHeader(); WMOHeader wmoHeader = getWmoHeader();
String hdr = wmoHeader.getWmoHeader(); String hdr = wmoHeader.getWmoHeader();
String afosId = staticData.matchUACollective(createDataDes(wmoHeader)); String afosId = TextDBStaticData
.matchUACollective(createDataDes(wmoHeader));
if (afosId != null) { if (afosId != null) {
productId = new AFOSProductId(afosId); productId = new AFOSProductId(afosId);
@ -162,7 +165,8 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
} }
// Get the XXX from the station number, using station_table.dat // Get the XXX from the station number, using station_table.dat
else { else {
XXX_id = staticData.mapWMOToICAO(stationNum.toString()); XXX_id = TextDBStaticData.mapWMOToICAO(stationNum
.toString());
if (XXX_id == null) { if (XXX_id == null) {
logger.debug("NCF_FAIL to map station number to XXX: " logger.debug("NCF_FAIL to map station number to XXX: "
+ stationNum); + stationNum);
@ -339,11 +343,11 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
uaNNN = "SGL"; uaNNN = "SGL";
} }
String icao = staticData.mapWMOToICAO(wmoId); String icao = TextDBStaticData.mapWMOToICAO(wmoId);
if (icao != null) { if (icao != null) {
// get the associated CCC // get the associated CCC
String cccId = staticData.mapICAOToCCC(icao); String cccId = TextDBStaticData.mapICAOToCCC(icao);
AFOSProductId prodId = data.getAfosProdId(); AFOSProductId prodId = data.getAfosProdId();
if (prodId != null) { if (prodId != null) {
@ -411,18 +415,18 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
} }
// Check for USUS80 or 90 formatted messages and decode // Check for USUS80 or 90 formatted messages and decode
else if (dataDes.endsWith("80") || dataDes.endsWith("90")) { else if (dataDes.endsWith("80") || dataDes.endsWith("90")) {
if (checkCharNum(buffer.charAt(0))) if (checkCharNum(buffer.charAt(0))) {
buffer.deleteCharAt(0); buffer.deleteCharAt(0);
else { } else {
stationNum.append(assignTextSegment(buffer.toString(), CSPC)); stationNum.append(assignTextSegment(buffer.toString(), CSPC));
} }
getTextSegment(buffer, parsedMsg, CSEP); getTextSegment(buffer, parsedMsg, CSEP);
} else { } else {
// Otherwise it's standard format so decode // Otherwise it's standard format so decode
if (!checkCharNum(buffer.charAt(0))) if (!checkCharNum(buffer.charAt(0))) {
buffer.deleteCharAt(0); buffer.deleteCharAt(0);
else { } else {
// Move to the third field of the message to get the station // Move to the third field of the message to get the station
// number. // number.
@ -449,9 +453,9 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
// Remove excess control characters // Remove excess control characters
if (buffer.length() == 0) { if (buffer.length() == 0) {
if (parsedMsg.length() < MIN_COLL_DATA_LEN) if (parsedMsg.length() < MIN_COLL_DATA_LEN) {
stationNum.setLength(0); stationNum.setLength(0);
else { } else {
trim_message(parsedMsg); trim_message(parsedMsg);
} }
} else if (buffer.charAt(0) == '=') { } else if (buffer.charAt(0) == '=') {
@ -489,7 +493,7 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
// Otherwise, use the national category table to get the CCC from the // Otherwise, use the national category table to get the CCC from the
// XXX // XXX
else { else {
CCC_id = staticData.mapICAOToCCC(XXX_id); CCC_id = TextDBStaticData.mapICAOToCCC(XXX_id);
if (CCC_id == null) { if (CCC_id == null) {
// We failed to get a CCC from the national_category_table... // We failed to get a CCC from the national_category_table...
@ -497,10 +501,10 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
// prepending K or P (the latter for AK, HI products) // prepending K or P (the latter for AK, HI products)
if ((XXX_id.length() == 3) && (origin.charAt(0) == 'K')) { if ((XXX_id.length() == 3) && (origin.charAt(0) == 'K')) {
newId = "K" + XXX_id; newId = "K" + XXX_id;
CCC_id = staticData.mapICAOToCCC(newId); CCC_id = TextDBStaticData.mapICAOToCCC(newId);
if (CCC_id == null) { if (CCC_id == null) {
newId = "P" + XXX_id; newId = "P" + XXX_id;
CCC_id = staticData.mapICAOToCCC(newId); CCC_id = TextDBStaticData.mapICAOToCCC(newId);
if (CCC_id == null) { if (CCC_id == null) {
// logger.error("NCF_FAIL to map XXX to CCC: " // logger.error("NCF_FAIL to map XXX to CCC: "
// + XXX_id); // + XXX_id);
@ -513,7 +517,7 @@ public class UACollectiveSeparator extends WMOMessageSeparator {
// character of the origin. // character of the origin.
else if (XXX_id.length() == 3) { else if (XXX_id.length() == 3) {
newId = origin.charAt(0) + XXX_id; newId = origin.charAt(0) + XXX_id;
CCC_id = staticData.mapICAOToCCC(newId); CCC_id = TextDBStaticData.mapICAOToCCC(newId);
if (CCC_id == null) { if (CCC_id == null) {
// logger.error("NCF_FAIL to map XXX to CCC: " + // logger.error("NCF_FAIL to map XXX to CCC: " +
// XXX_id); // XXX_id);

View file

@ -30,7 +30,6 @@ import org.apache.commons.logging.LogFactory;
import com.raytheon.edex.esb.Headers; import com.raytheon.edex.esb.Headers;
import com.raytheon.edex.plugin.AbstractRecordSeparator; import com.raytheon.edex.plugin.AbstractRecordSeparator;
import com.raytheon.edex.textdb.dbapi.impl.TextDBStaticData;
import com.raytheon.edex.textdb.dbapi.impl.WMOReportData; import com.raytheon.edex.textdb.dbapi.impl.WMOReportData;
import com.raytheon.uf.edex.wmo.message.AFOSProductId; import com.raytheon.uf.edex.wmo.message.AFOSProductId;
import com.raytheon.uf.edex.wmo.message.WMOHeader; import com.raytheon.uf.edex.wmo.message.WMOHeader;
@ -96,8 +95,6 @@ public abstract class WMOMessageSeparator extends AbstractRecordSeparator {
protected final String traceId; protected final String traceId;
protected final TextDBStaticData staticData;
protected final String siteId; protected final String siteId;
protected final TextDecoderMode mode; protected final TextDecoderMode mode;
@ -133,8 +130,6 @@ public abstract class WMOMessageSeparator extends AbstractRecordSeparator {
this.siteId = siteId; this.siteId = siteId;
this.wmoHeader = wmoHeader; this.wmoHeader = wmoHeader;
this.mode = mode; this.mode = mode;
staticData = TextDBStaticData.instance(siteId);
// localCCC = staticData.getProductId("LOCALCCC ").substring(0, 3);
} }
/** /**
@ -282,7 +277,6 @@ public abstract class WMOMessageSeparator extends AbstractRecordSeparator {
return numSkipped; return numSkipped;
} }
/* /*
* private AFOSProductId createProductId() { AFOSProductId productId = null; * private AFOSProductId createProductId() { AFOSProductId productId = null;
* *
@ -382,10 +376,11 @@ public abstract class WMOMessageSeparator extends AbstractRecordSeparator {
// //
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
static boolean checkCharNum(char x) { static boolean checkCharNum(char x) {
if ((x > 64) && (x < 91)) if ((x > 64) && (x < 91)) {
return true; return true;
else if ((x > 47) && (x < 58)) } else if ((x > 47) && (x < 58)) {
return true; return true;
}
return false; return false;
} }

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>

View file

@ -1,7 +1,11 @@
#Thu Mar 26 10:27:35 CDT 2009
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7

View file

@ -18,7 +18,7 @@ Export-Package: com.raytheon.edex.textdb.alarms,
com.raytheon.edex.textdb.dao, com.raytheon.edex.textdb.dao,
com.raytheon.edex.textdb.dbapi.impl, com.raytheon.edex.textdb.dbapi.impl,
com.raytheon.edex.textdb.fax com.raytheon.edex.textdb.fax
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: com.raytheon.uf.common.message, Import-Package: com.raytheon.uf.common.message,
com.raytheon.uf.common.serialization.comm, com.raytheon.uf.common.serialization.comm,
org.apache.commons.logging org.apache.commons.logging

View file

@ -21,31 +21,42 @@ package com.raytheon.edex.textdb.dbapi.impl;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.util.Collection;
import java.io.InputStreamReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.site.SiteMap; import com.raytheon.uf.common.site.SiteMap;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.util.CollectionUtil;
import com.raytheon.uf.common.util.FileUtil;
import com.raytheon.uf.common.util.StringUtil;
/** /**
* TODO Add Description * A singleton class that maintains static data used by the TextDB (e.g., the
* mappings needed to perform lookups for AFOS and WMO IDs). Data is lazily
* loaded by data file.
* *
* <pre> * <pre>
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 2, 2008 1538 jkorman Initial creation * Sep 02, 2008 1538 jkorman Initial creation
* Jul 10, 2009 2191 rjpeter Added additional methods. * Jul 10, 2009 2191 rjpeter Added additional methods.
* Apr 01, 2014 2915 dgilling Major re-factor, all methods are now
* static.
* </pre> * </pre>
* *
* @author jkorman * @author jkorman
@ -54,6 +65,9 @@ import com.raytheon.uf.common.site.SiteMap;
public class TextDBStaticData { public class TextDBStaticData {
private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(TextDBStaticData.class);
private static final int COLLECTIVE_TABLE_KEY_LEN = 6; private static final int COLLECTIVE_TABLE_KEY_LEN = 6;
private static final int UPAIR_KEY_LEN = 6; private static final int UPAIR_KEY_LEN = 6;
@ -62,66 +76,85 @@ public class TextDBStaticData {
private static final int BIT_TABLE_KEY_LEN = 3; private static final int BIT_TABLE_KEY_LEN = 3;
private static final int ISPAN_KEY_LEN = 10;
private static final int STD_SEPARATOR_LEN = 1;
private static final int ISPAN_SEPARATOR_LEN = 2;
private static boolean exclusionFileInplay = System private static boolean exclusionFileInplay = System
.getenv("STD_TEXT_EXCLUSION") != null; .getenv("STD_TEXT_EXCLUSION") != null;
private static Map<String, TextDBStaticData> instanceMap = new HashMap<String, TextDBStaticData>(); private static final String TEXTDB = "textdb";
private boolean tablesLoaded = false; private static final String COLLECTIVE_TABLE_PATH = FileUtil.join(TEXTDB,
"collective_table.dat");
private Map<String, String> stdCollectiveMap = new HashMap<String, String>(); private static final String UPAIR_TABLE_PATH = FileUtil.join(TEXTDB,
"upair_table.dat");
private Map<String, String> uaCollectiveMap = new HashMap<String, String>(); private static final String STATION_TABLE_PATH = FileUtil.join(TEXTDB,
"station_table.dat");
private Map<String, String> stationTable = new HashMap<String, String>(); private static final String EXCLUSION_PRODUCT_LIST_PATH = FileUtil.join(
TEXTDB, "exclusionProductList.dat");
private Map<String, String> nationalTable = new HashMap<String, String>(); private static final String CHECK_PRODUCT_FILE_PATH = FileUtil.join(TEXTDB,
"checkProductFile.dat");
private Map<String, String> ispanTable = new HashMap<String, String>(); private static final String ISPAN_TABLE_PATH = FileUtil.join(TEXTDB,
"ispan_table.dat");
private Map<String, String> bitTable = new HashMap<String, String>(); private static final String BIT_TABLE_PATH = FileUtil.join(TEXTDB,
"bit_table.dat");
private Set<String> exclusionList = new HashSet<String>(); private static final AtomicBoolean stdCollectiveLoaded = new AtomicBoolean(
false);
private Set<String> duplicateCheckList = new HashSet<String>(); private static final AtomicBoolean uaCollectiveLoaded = new AtomicBoolean(
false);
private String siteId = null; private static final AtomicBoolean stationTableLoaded = new AtomicBoolean(
false);
/** private static final AtomicBoolean ispanTableLoaded = new AtomicBoolean(
* false);
*/
private TextDBStaticData(String siteId) { private static final AtomicBoolean bitTableLoaded = new AtomicBoolean(false);
this.siteId = siteId;
populateTables(); private static final AtomicBoolean exclusionListLoaded = new AtomicBoolean(
false);
private static final AtomicBoolean dupCheckListLoaded = new AtomicBoolean(
false);
private static final Map<String, String> stdCollectiveMap = new HashMap<>();
private static final Map<String, String> uaCollectiveMap = new HashMap<>();
private static final Map<String, String> stationTable = new HashMap<>();
private static final Map<String, String> ispanTable = new HashMap<>();
private static final Map<String, String> bitTable = new HashMap<>();
private static final Collection<String> exclusionList = new HashSet<>();
private static final Collection<String> duplicateCheckList = new HashSet<>();
private TextDBStaticData() {
// prevent default constructor from being created.
throw new AssertionError();
} }
public boolean areTablesLoaded() { public static void setDirty() {
return tablesLoaded; stdCollectiveLoaded.set(false);
} uaCollectiveLoaded.set(false);
stationTableLoaded.set(false);
/** ispanTableLoaded.set(false);
* bitTableLoaded.set(false);
* @return exclusionListLoaded.set(false);
*/ dupCheckListLoaded.set(false);
public synchronized static TextDBStaticData instance(String siteId) {
TextDBStaticData instance = instanceMap.get(siteId);
if (instance == null) {
instance = new TextDBStaticData(siteId);
instanceMap.put(siteId, instance);
}
return instance;
}
public synchronized static void setDirty() {
for (String key : instanceMap.keySet()) {
if (null != instanceMap.get(key)) {
instanceMap.get(key).makeDirty();
}
}
}
public synchronized void makeDirty() {
tablesLoaded = false;
} }
/** /**
@ -129,12 +162,15 @@ public class TextDBStaticData {
* @param dataDes * @param dataDes
* @return * @return
*/ */
public synchronized String matchStdCollective(String dataDes) { public static String matchStdCollective(String dataDes) {
if (!tablesLoaded) { if (!stdCollectiveLoaded.get()) {
reload(); populateMap(stdCollectiveMap, stdCollectiveLoaded,
COLLECTIVE_TABLE_PATH, COLLECTIVE_TABLE_KEY_LEN,
STD_SEPARATOR_LEN);
} }
String retValue = null; String retValue = null;
if (stdCollectiveMap != null) { synchronized (stdCollectiveMap) {
retValue = stdCollectiveMap.get(dataDes); retValue = stdCollectiveMap.get(dataDes);
} }
return retValue; return retValue;
@ -145,13 +181,14 @@ public class TextDBStaticData {
* @param dataDes * @param dataDes
* @return * @return
*/ */
public synchronized String matchUACollective(String dataDes) { public static String matchUACollective(String dataDes) {
if (!tablesLoaded) { if (!uaCollectiveLoaded.get()) {
reload(); populateMap(uaCollectiveMap, uaCollectiveLoaded, UPAIR_TABLE_PATH,
UPAIR_KEY_LEN, STD_SEPARATOR_LEN);
} }
String retValue = null; String retValue = null;
if (uaCollectiveMap != null) { synchronized (uaCollectiveMap) {
retValue = uaCollectiveMap.get(dataDes); retValue = uaCollectiveMap.get(dataDes);
} }
return retValue; return retValue;
@ -163,12 +200,14 @@ public class TextDBStaticData {
* @param WMOId * @param WMOId
* @return * @return
*/ */
public synchronized String mapWMOToICAO(String WMOId) { public static String mapWMOToICAO(String WMOId) {
if (!tablesLoaded) { if (!stationTableLoaded.get()) {
reload(); populateMap(stationTable, stationTableLoaded, STATION_TABLE_PATH,
STATION_TABLE_KEY_LEN, STD_SEPARATOR_LEN);
} }
String retValue = null; String retValue = null;
if (stationTable != null) { synchronized (stationTable) {
retValue = stationTable.get(WMOId); retValue = stationTable.get(WMOId);
} }
return retValue; return retValue;
@ -180,7 +219,7 @@ public class TextDBStaticData {
* @param WMOId * @param WMOId
* @return * @return
*/ */
public synchronized String mapICAOToCCC(String icao) { public static String mapICAOToCCC(String icao) {
return SiteMap.getInstance().mapICAOToCCC(icao); return SiteMap.getInstance().mapICAOToCCC(icao);
} }
@ -191,7 +230,7 @@ public class TextDBStaticData {
* @param WMOId * @param WMOId
* @return * @return
*/ */
public synchronized String mapWMOToCCC(String icao) { public static String mapWMOToCCC(String icao) {
return mapICAOToCCC(mapWMOToICAO(icao)); return mapICAOToCCC(mapWMOToICAO(icao));
} }
@ -200,11 +239,17 @@ public class TextDBStaticData {
* @param ispanId * @param ispanId
* @return * @return
*/ */
public synchronized boolean isMappedISpanId(String ispanId) { public static boolean isMappedISpanId(String ispanId) {
if (!tablesLoaded) { if (!ispanTableLoaded.get()) {
reload(); populateMap(ispanTable, ispanTableLoaded, ISPAN_TABLE_PATH,
ISPAN_KEY_LEN, ISPAN_SEPARATOR_LEN);
} }
return ispanTable.containsKey(ispanId);
boolean containsKey = false;
synchronized (ispanTable) {
containsKey = ispanTable.containsKey(ispanId);
}
return containsKey;
} }
/** /**
@ -212,56 +257,67 @@ public class TextDBStaticData {
* @param afosId * @param afosId
* @return * @return
*/ */
public synchronized boolean isExcluded(String afosId) { public static boolean isExcluded(String afosId) {
if (!tablesLoaded) { if (!exclusionListLoaded.get()) {
reload(); if (exclusionFileInplay) {
populateCollection(exclusionList, exclusionListLoaded,
EXCLUSION_PRODUCT_LIST_PATH);
} else {
synchronized (exclusionList) {
exclusionList.clear();
exclusionListLoaded.set(true);
}
}
} }
if (exclusionList != null && exclusionList.size() > 0) {
// If a product ID in the exclusion file list that matches the
// incoming product's ID is found, end the process; otherwise,
// continue searching through the end of the list.
// with CCC_id as wild card synchronized (exclusionList) {
String expandProductId = "000" if (!CollectionUtil.isNullOrEmpty(exclusionList)) {
+ afosId.substring(3, // If a product ID in the exclusion file list that matches the
(afosId.length() > 9 ? 9 : afosId.length())); // incoming product's ID is found, end the process; otherwise,
if (exclusionList.contains(expandProductId)) { // continue searching through the end of the list.
return true;
// with CCC_id as wild card
String expandProductId = "000"
+ afosId.substring(3,
(afosId.length() > 9 ? 9 : afosId.length()));
if (exclusionList.contains(expandProductId)) {
return true;
}
// with NNN_id as wild card
expandProductId = afosId.substring(0, 3) + "000"
+ afosId.substring(6);
if (exclusionList.contains(expandProductId)) {
return true;
}
// with XXX_id as wild card
expandProductId = afosId.substring(0, 6) + "000";
if (exclusionList.contains(expandProductId)) {
return true;
}
// with both NNN_id and XXX_id as wild card
expandProductId = afosId.substring(0, 3) + "000000";
if (exclusionList.contains(expandProductId)) {
return true;
}
// with both CCC_id and XXX_id as wild card
expandProductId = "000" + afosId.substring(3, 6) + "000";
if (exclusionList.contains(expandProductId)) {
return true;
}
// with both CCC_id and NNN_id as wild card
expandProductId = "000000" + afosId.substring(6);
if (exclusionList.contains(expandProductId)) {
return true;
}
// search full product id
return exclusionList.contains(afosId);
} }
// with NNN_id as wild card
expandProductId = afosId.substring(0, 3) + "000"
+ afosId.substring(6);
if (exclusionList.contains(expandProductId)) {
return true;
}
// with XXX_id as wild card
expandProductId = afosId.substring(0, 6) + "000";
if (exclusionList.contains(expandProductId)) {
return true;
}
// with both NNN_id and XXX_id as wild card
expandProductId = afosId.substring(0, 3) + "000000";
if (exclusionList.contains(expandProductId)) {
return true;
}
// with both CCC_id and XXX_id as wild card
expandProductId = "000" + afosId.substring(3, 6) + "000";
if (exclusionList.contains(expandProductId)) {
return true;
}
// with both CCC_id and NNN_id as wild card
expandProductId = "000000" + afosId.substring(6);
if (exclusionList.contains(expandProductId)) {
return true;
}
// search full product id
return exclusionList.contains(afosId);
} }
return false; return false;
@ -272,12 +328,18 @@ public class TextDBStaticData {
* @param afosId * @param afosId
* @return * @return
*/ */
public synchronized boolean checkForDuplicate(String afosId) { public static boolean checkForDuplicate(String afosId) {
boolean retVal = false; if (!dupCheckListLoaded.get()) {
if (duplicateCheckList != null && duplicateCheckList.size() > 0) { populateCollection(duplicateCheckList, dupCheckListLoaded,
retVal = duplicateCheckList.contains(afosId); CHECK_PRODUCT_FILE_PATH);
} }
boolean retVal = false;
synchronized (duplicateCheckList) {
if (!CollectionUtil.isNullOrEmpty(duplicateCheckList)) {
retVal = duplicateCheckList.contains(afosId);
}
}
return retVal; return retVal;
} }
@ -286,11 +348,17 @@ public class TextDBStaticData {
* @param ispanId * @param ispanId
* @return * @return
*/ */
public synchronized String getProductId(String ispanId) { public static String getProductId(String ispanId) {
if (!tablesLoaded) { if (!ispanTableLoaded.get()) {
reload(); populateMap(ispanTable, ispanTableLoaded, ISPAN_TABLE_PATH,
ISPAN_KEY_LEN, ISPAN_SEPARATOR_LEN);
} }
return ispanTable.get(ispanId);
String retVal = null;
synchronized (ispanTable) {
retVal = ispanTable.get(ispanId);
}
return retVal;
} }
/** /**
@ -298,11 +366,19 @@ public class TextDBStaticData {
* @param nnnId * @param nnnId
* @return * @return
*/ */
public synchronized String getSiteIdFromNNN(String nnnId) { public static String getSiteIdFromNNN(String nnnId, String siteId) {
if (!tablesLoaded) { if (!bitTableLoaded.get()) {
reload(); populateMap(bitTable, bitTableLoaded, BIT_TABLE_PATH,
BIT_TABLE_KEY_LEN, STD_SEPARATOR_LEN);
} }
return bitTable.get(nnnId);
String value = null;
synchronized (bitTable) {
value = bitTable.get(nnnId);
}
String retVal = ("AAA".equals(value)) ? SiteMap.getInstance()
.getCCCFromXXXCode(siteId) : value;
return retVal;
} }
/** /**
@ -310,7 +386,7 @@ public class TextDBStaticData {
* @param wmoCccc * @param wmoCccc
* @return * @return
*/ */
public synchronized String getAfosCCC(String wmoCccc) { public static String getAfosCCC(String wmoCccc) {
return SiteMap.getInstance().getCCCFromXXXCode(wmoCccc); return SiteMap.getInstance().getCCCFromXXXCode(wmoCccc);
} }
@ -319,85 +395,48 @@ public class TextDBStaticData {
* @param v * @param v
* @return * @return
*/ */
public synchronized String getAFOSTableMap(String v) { public static String getAFOSTableMap(String v) {
return SiteMap.getInstance().getAFOSTableMap(v); return SiteMap.getInstance().getAFOSTableMap(v);
} }
/** private static void populateMap(final Map<String, String> dataMap,
* Cause the internal tables to be reloaded. <code> final AtomicBoolean loadedFlag, final String filePath,
* TextDBStaticData.instance(site).reload(); final int keyLen, final int separatorLen) {
* </code> synchronized (dataMap) {
*/ if (loadedFlag.get()) {
public void reload() { return;
synchronized (this) { }
// Drop the old maps.
stdCollectiveMap = null; try {
uaCollectiveMap = null; Map<String, String> newData = loadFileToMap(filePath, keyLen,
stationTable = null; separatorLen);
nationalTable = null; dataMap.clear();
ispanTable = null; dataMap.putAll(newData);
bitTable = null; loadedFlag.set(true);
exclusionList = null; } catch (IOException e) {
duplicateCheckList = null; statusHandler.error(
// and repopulate. "Could not load TextDBStaticData from file ["
populateTables(); + filePath + "]", e);
}
} }
} }
/** private static void populateCollection(final Collection<String> dataList,
* Populate the internal data maps. final AtomicBoolean loadedFlag, final String filePath) {
*/ synchronized (dataList) {
private void populateTables() { if (loadedFlag.get()) {
tablesLoaded = true; return;
}
// ****************************** try {
if (stdCollectiveMap != null) { Set<String> newData = loadFileToSet(filePath);
stdCollectiveMap = new HashMap<String, String>(); dataList.clear();
} dataList.addAll(newData);
tablesLoaded &= loadFile("textdb/collective_table.dat", loadedFlag.set(true);
stdCollectiveMap, COLLECTIVE_TABLE_KEY_LEN); } catch (IOException e) {
// ****************************** statusHandler.error(
if (uaCollectiveMap != null) { "Could not load TextDBStaticData from file ["
uaCollectiveMap = new HashMap<String, String>(); + filePath + "]", e);
}
tablesLoaded &= loadFile("textdb/upair_table.dat", uaCollectiveMap,
UPAIR_KEY_LEN);
// ******************************
if (stationTable != null) {
stationTable = new HashMap<String, String>();
}
tablesLoaded &= loadFile("textdb/station_table.dat", stationTable,
STATION_TABLE_KEY_LEN);
// ******************************
if (exclusionList != null) {
exclusionList = new HashSet<String>();
}
if (exclusionFileInplay) {
tablesLoaded &= loadFile("textdb/exclusionProductList.dat",
exclusionList);
}
// ******************************
if (duplicateCheckList != null) {
duplicateCheckList = new HashSet<String>();
}
tablesLoaded &= loadFile("textdb/checkProductFile.dat",
duplicateCheckList);
// ******************************
if (ispanTable != null) {
ispanTable = new HashMap<String, String>();
}
tablesLoaded &= loadISpanFile("textdb/ispan_table.dat", ispanTable);
// ******************************
if (bitTable != null) {
bitTable = new HashMap<String, String>();
}
tablesLoaded &= loadFile("textdb/bit_table.dat", bitTable,
BIT_TABLE_KEY_LEN);
String node = SiteMap.getInstance().getCCCFromXXXCode(siteId);
for (String s : bitTable.keySet()) {
if ("AAA".equals(bitTable.get(s))) {
bitTable.put(s, node);
} }
} }
} }
@ -405,163 +444,126 @@ public class TextDBStaticData {
/** /**
* Read in the desired static file, parse its contains and place results in * Read in the desired static file, parse its contains and place results in
* the map. This assumes that each line of the file is in the following * the map. This assumes that each line of the file is in the following
* format: <li>(KEY)(DEL_CHAR)(VALUE)</li> <li>(KEY) is a string of keyLen * format: (KEY)(DELIMETER)(VALUE)
* characters that may include spaces</li> <li>(DEL_CHAR) a single character * <ul>
* delimiter normally a space or equal sign</li> <li>(VALUE) the reset of * <li>(KEY) is a string of <code>keyLen</code> characters that may include
* the line that is mapped to (KEY)</li> * spaces.</li>
* <li>(DELIMETER) is a string of <code>separatorLen</code> chars (usually,
* a space or equal sign or multiple spaces).</li>
* <li>(VALUE) the reset of the line that is mapped to (KEY).</li>
* </ul>
* *
* @param filename * @param filename
* - file to parse * File to parse
* @param map
* - parse results
* @param keyLen * @param keyLen
* - Length of the file's keys * Length of the file's keys
* @return - true when file read and parsed otherwise false * @param separatorLen
* Length of the separator between keys and values.
* @return A <code>Map</code> pairing the keys to their values.
* @throws IOException
* If any errors occur reading the specified input file.
* @throws FileNotFoundException
* If the specified file cannot be located in the localization
* hierarchy or if the file cannot be opened for reading.
*/ */
private boolean loadFile(String filename, Map<String, String> map, private static Map<String, String> loadFileToMap(final String filename,
final int keyLen) { final int keyLen, final int separatorLen)
boolean loaded = false; throws FileNotFoundException, IOException {
File file = locateFile(filename);
if (file == null) {
throw new FileNotFoundException("Could not locate file ["
+ filename + "] in localization hierarchy.");
}
InputStream strm = null; Map<String, String> retVal = new HashMap<>();
BufferedReader bf = null; try (BufferedReader inFile = new BufferedReader(new FileReader(file))) {
IPathManager pathMgr = PathManagerFactory.getPathManager(); String line = null;
LocalizationContext lc = pathMgr.getContext( while ((line = inFile.readLine()) != null) {
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); if ((line.length() < (keyLen + separatorLen + 1))
File file = pathMgr.getFile(lc, filename); || (line.startsWith("#"))) {
continue;
HashMap<String, String> dataMap = new HashMap<String, String>();
try {
try {
strm = new FileInputStream(file);
if (strm != null) {
bf = new BufferedReader(new InputStreamReader(strm));
String line = null;
while ((line = bf.readLine()) != null) {
String dataKey = line.substring(0, keyLen);
String tblData = line.substring(keyLen + 1);
String tData = dataMap.get(tblData);
if (tData == null) {
dataMap.put(tblData, tblData);
tData = tblData;
}
map.put(dataKey, tData);
}
loaded = true;
} }
} catch (IOException ioe) {
ioe.printStackTrace(); /*
} * A note on why we're performing this selective trimming: The
} finally { * format of the current NDM files on the web are formatted
if (bf != null) { * slightly differently than those in the current A2 baseline.
try { *
bf.close(); * The A2 baseline files have a single separator char between
} catch (IOException ioe) { * key and value, and no excess whitespace between the separator
ioe.printStackTrace(); * char and the value. The new updated files on the web,
} * however, vary between a single separator char and using 2
} * spaces as a separator.
if (dataMap != null) { *
dataMap.clear(); * To allow both formats to work we expect a fixed-length key,
* and left-trim the value string in case we get an extra
* leading space char from the newer format files.
*/
String dataKey = line.substring(0, keyLen);
String tblData = StringUtil.ltrim(line.substring(keyLen
+ separatorLen));
retVal.put(dataKey, tblData);
} }
} }
return loaded; return retVal;
} }
/** /**
* Read in the desired static file, parse its contains and place results in
* a <code>Set</code>.
* *
* @param filename * @param filename
* @param list * The path to the input file in the localization hierarchy.
* @return * @return A <code>Set</code> containing all the valid values in the input
* file.
* @throws FileNotFoundException
* If the specified file cannot be located in the localization
* hierarchy or if the file cannot be opened for reading.
* @throws IOException
* If any errors occur reading the specified input file.
*/ */
private boolean loadFile(String filename, Set<String> list) { private static Set<String> loadFileToSet(final String filename)
boolean loaded = false; throws FileNotFoundException, IOException {
File file = locateFile(filename);
if (file == null) {
throw new FileNotFoundException("Could not locate file ["
+ filename + "] in localization hierarchy.");
}
InputStream strm = null; Set<String> retVal = new HashSet<>();
BufferedReader bf = null; try (BufferedReader inFile = new BufferedReader(new FileReader(file))) {
IPathManager pathMgr = PathManagerFactory.getPathManager(); String line = null;
LocalizationContext lc = pathMgr.getContext( while ((line = inFile.readLine()) != null) {
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); line = line.trim();
File file = pathMgr.getFile(lc, filename); if (!line.isEmpty() && !line.startsWith("#")
&& !"000000000".equals(line)) {
try { retVal.add(line);
try {
strm = new FileInputStream(file);
if (strm != null) {
bf = new BufferedReader(new InputStreamReader(strm));
String line = null;
while ((line = bf.readLine()) != null) {
line = line.trim();
if (line.length() > 0 && !line.startsWith("#")
&& !"000000000".equals(line)) {
list.add(line);
}
}
loaded = true;
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
} finally {
if (bf != null) {
try {
bf.close();
} catch (IOException ioe) {
ioe.printStackTrace();
} }
} }
} }
return loaded; return retVal;
} }
/** private static File locateFile(final String filename) {
*
* @param filename
* @param map
* @return
*/
private boolean loadISpanFile(String filename, Map<String, String> map) {
boolean loaded = false;
InputStream strm = null;
BufferedReader bf = null;
IPathManager pathMgr = PathManagerFactory.getPathManager(); IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext lc = pathMgr.getContext( Map<LocalizationLevel, LocalizationFile> tieredFile = pathMgr
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); .getTieredLocalizationFile(LocalizationType.COMMON_STATIC,
File file = pathMgr.getFile(lc, filename); filename);
LocalizationContext[] contexts = pathMgr
.getLocalSearchHierarchy(LocalizationType.COMMON_STATIC);
try { File file = null;
try { for (LocalizationContext context : contexts) {
strm = new FileInputStream(file); LocalizationLevel level = context.getLocalizationLevel();
LocalizationFile lFile = tieredFile.get(level);
if (strm != null) { if (lFile != null) {
bf = new BufferedReader(new InputStreamReader(strm)); file = lFile.getFile();
break;
String line = null;
while ((line = bf.readLine()) != null) {
map.put(line.substring(0, 10), line.substring(12));
}
loaded = true;
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
} finally {
if (bf != null) {
try {
bf.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
} }
} }
return loaded; return file;
} }
} }

View file

@ -19,15 +19,8 @@
**/ **/
package com.raytheon.edex.textdb.ingest; package com.raytheon.edex.textdb.ingest;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import com.raytheon.edex.textdb.dbapi.impl.TextDBStaticData; import com.raytheon.edex.textdb.dbapi.impl.TextDBStaticData;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
@ -37,7 +30,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.util.FileUtil;
import com.raytheon.uf.edex.ndm.ingest.INationalDatasetSubscriber; import com.raytheon.uf.edex.ndm.ingest.INationalDatasetSubscriber;
/** /**
@ -52,6 +45,7 @@ import com.raytheon.uf.edex.ndm.ingest.INationalDatasetSubscriber;
* Jan 25, 2011 bfarmer Initial creation * Jan 25, 2011 bfarmer Initial creation
* Oct 18, 2011 10909 rferrel notify() now saves a file. * Oct 18, 2011 10909 rferrel notify() now saves a file.
* Mar 06, 2014 2876 mpduff New NDM plugin. * Mar 06, 2014 2876 mpduff New NDM plugin.
* Mar 20, 2014 2915 dgilling Code cleanup.
* *
* </pre> * </pre>
* *
@ -69,50 +63,16 @@ public class TextDBStaticDataSubscriber implements INationalDatasetSubscriber {
// in the BASE directory. // in the BASE directory.
IPathManager pathMgr = PathManagerFactory.getPathManager(); IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext lc = pathMgr.getContext( LocalizationContext lc = pathMgr.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED);
File outFile = pathMgr.getFile(lc, "textdb/" + fileName); File outFile = pathMgr.getFile(lc, FileUtil.join("textdb", fileName));
saveFile(file, outFile);
}
private void saveFile(File file, File outFile) { try {
if ((file != null) && file.exists()) { FileUtil.copyFile(file, outFile);
BufferedReader fis = null; TextDBStaticData.setDirty();
BufferedWriter fos = null; } catch (IOException e) {
try { statusHandler.error("Unable to copy textdb static data file ["
fis = new BufferedReader(new InputStreamReader( + file.getPath() + "] to destination [" + outFile.getPath()
new FileInputStream(file))); + "].", e);
fos = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outFile)));
String line = null;
try {
while ((line = fis.readLine()) != null) {
fos.write(line);
fos.newLine();
}
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM,
"Could not read file: " + file.getName(), e);
}
} catch (FileNotFoundException e) {
statusHandler.handle(Priority.PROBLEM, "Failed to find file: "
+ file.getName(), e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
// ignore
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
// ignore
}
}
}
} }
TextDBStaticData.setDirty();
} }
} }

View file

@ -41,6 +41,7 @@ import org.apache.commons.lang.StringUtils;
* Jul 13, 2012 740 djohnson Add join. * Jul 13, 2012 740 djohnson Add join.
* Nov 09, 2012 1322 djohnson Add NEWLINE, createMessage. * Nov 09, 2012 1322 djohnson Add NEWLINE, createMessage.
* Mar 02, 2013 1970 bgonzale Added fast string replacement method. * Mar 02, 2013 1970 bgonzale Added fast string replacement method.
* Apr 02, 2014 2915 dgilling Added left and right trim methods.
* *
* </pre> * </pre>
* *
@ -311,16 +312,54 @@ public final class StringUtil {
int count = 0; int count = 0;
Pattern pat = Pattern.compile("\\p{Alnum}"); Pattern pat = Pattern.compile("\\p{Alnum}");
Matcher mat = pat.matcher(str); Matcher mat = pat.matcher(str);
while (mat.find()) { while (mat.find()) {
count++; count++;
} }
if (count == str.length()) { if (count == str.length()) {
return true; return true;
} else { } else {
return false; return false;
} }
}
/**
* Returns a copy of the string, with only leading whitespace omitted.
* <p>
* Like String.trim(), whitespace is defined as any character with a code
* less than or equal to <code>'&#92;u0020'</code> (the space character).
*
* @param s
* The <code>String</code> to trim.
* @return A copy of this string with leading white space removed, or the
* passed in string if it has no leading white space.
*/
public static String ltrim(String s) {
int i = 0;
while ((i < s.length()) && (s.charAt(i) <= ' ')) {
i++;
}
return (i > 0) ? s.substring(i) : s;
}
/**
* Returns a copy of the string, with only trailing whitespace omitted.
* <p>
* Like String.trim(), whitespace is defined as any character with a code
* less than or equal to <code>'&#92;u0020'</code> (the space character).
*
* @param s
* The <code>String</code> to trim.
* @return A copy of this string with trailing white space removed, or the
* passed in string if it has no trailing white space.
*/
public static String rtrim(String s) {
int i = s.length();
while ((i > 0) && (s.charAt(i - 1) <= ' ')) {
i--;
}
return (i < s.length()) ? s.substring(0, i) : s;
} }
} }