From c0688f9e99d20c56416c9d886d4e9d73391f685f Mon Sep 17 00:00:00 2001 From: Slav Korolev Date: Tue, 25 Mar 2014 09:20:13 -0400 Subject: [PATCH] Issue #2930 - Fixed error in distance. Former-commit-id: c56753c19f8413e1094b524a9bc43bbcfc74e46f --- .../META-INF/MANIFEST.MF | 6 +- .../res/spring/cwa-ingest.xml | 12 ++- .../uf/edex/plugin/cwa/CWADecoder.java | 15 ++-- .../uf/edex/plugin/cwa/decoder/CWAParser.java | 89 +++++++++++++------ .../plugin/cwa/decoder/InternalReport.java | 18 ++-- .../uf/edex/plugin/cwa/util/TableLoader.java | 18 ++-- 6 files changed, 104 insertions(+), 54 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/META-INF/MANIFEST.MF index 4b4dbc01fa..8d8d13c30f 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Cwa Plug-in Bundle-SymbolicName: com.raytheon.uf.edex.plugin.cwa -Bundle-Version: 1.12.1174.qualifier +Bundle-Version: 1.14.0.qualifier Bundle-Vendor: RAYTHEON Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: com.raytheon.uf.common.dataplugin.cwa;bundle-version="1.0.0", @@ -17,8 +17,8 @@ Require-Bundle: com.raytheon.uf.common.dataplugin.cwa;bundle-version="1.0.0", com.raytheon.uf.common.serialization Import-Package: com.raytheon.edex.esb, com.raytheon.uf.common.dataplugin, + com.raytheon.uf.common.dataplugin.exception, com.raytheon.uf.common.datastorage.records, com.raytheon.uf.common.status, com.raytheon.uf.common.time, - com.raytheon.uf.edex.core, - org.apache.commons.logging + com.raytheon.uf.edex.core diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/res/spring/cwa-ingest.xml b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/res/spring/cwa-ingest.xml index 0d43bc232b..a051672616 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/res/spring/cwa-ingest.xml +++ b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/res/spring/cwa-ingest.xml @@ -34,10 +34,14 @@ - - java.lang.Throwable - - + + com.raytheon.uf.common.dataplugin.exception.MalformedDataException + + + + java.lang.Throwable + + diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/CWADecoder.java b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/CWADecoder.java index 4a38261f53..397cd3922e 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/CWADecoder.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/CWADecoder.java @@ -19,21 +19,22 @@ **/ package com.raytheon.uf.edex.plugin.cwa; +import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import com.raytheon.edex.esb.Headers; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.cwa.CWARecord; +import com.raytheon.uf.common.dataplugin.exception.MalformedDataException; import com.raytheon.uf.common.pointdata.PointDataDescription; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.edex.plugin.cwa.decoder.CWAParser; import com.raytheon.uf.edex.plugin.cwa.util.TableLoader; /** - * + * CWA Decoder. * *
  * 
@@ -42,6 +43,7 @@ import com.raytheon.uf.edex.plugin.cwa.util.TableLoader;
  * ------------ ---------- ----------- --------------------------
  * Feb 01, 2010            jsanchez     Initial creation
  * Apr 19, 2012  #457      dgilling     Minor code cleanup.
+ * Mar 25, 2014  2930      skorolev     Fixed error in distance.
  * 
  * 
* @@ -49,7 +51,7 @@ import com.raytheon.uf.edex.plugin.cwa.util.TableLoader; * @version 1.0 */ public class CWADecoder { - private Log logger = LogFactory.getLog(getClass()); + private IUFStatusHandler logger = UFStatus.getHandler(CWADecoder.class); private final String pluginName; @@ -93,7 +95,8 @@ public class CWADecoder { * @param headers * @return */ - public PluginDataObject[] decode(byte[] data, Headers headers) { + public PluginDataObject[] decode(byte[] data, Headers headers) + throws MalformedDataException, IOException { String traceId = null; PluginDataObject[] decodedData = null; diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/CWAParser.java b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/CWAParser.java index 893f6c494b..a712a15727 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/CWAParser.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/CWAParser.java @@ -32,17 +32,18 @@ import javax.measure.converter.UnitConverter; import javax.measure.unit.NonSI; import javax.measure.unit.SI; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.geotools.referencing.GeodeticCalculator; import com.raytheon.edex.esb.Headers; import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.cwa.CWADimension; import com.raytheon.uf.common.dataplugin.cwa.CWARecord; +import com.raytheon.uf.common.dataplugin.exception.MalformedDataException; import com.raytheon.uf.common.pointdata.PointDataContainer; import com.raytheon.uf.common.pointdata.PointDataDescription; import com.raytheon.uf.common.pointdata.PointDataView; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.edex.decodertools.time.TimeTools; import com.raytheon.uf.edex.plugin.cwa.CWARecordDao; @@ -52,7 +53,7 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader; import com.vividsolutions.jts.geom.Coordinate; /** - * TODO Add Description + * The CWA text Parser. * *
  * 
@@ -64,6 +65,7 @@ import com.vividsolutions.jts.geom.Coordinate;
  * Apr 18, 2012 473        dgilling    Modify parser to set  DataTime based on
  *                                     ingest  file name.
  * Aug 30, 2013 2298       rjpeter     Make getPluginName abstract
+ * Mar 25, 2014 2930       skorolev    Fixed error in distance.
  * 
  * 
* @@ -72,7 +74,7 @@ import com.vividsolutions.jts.geom.Coordinate; */ public class CWAParser { /** The logger */ - private final Log logger = LogFactory.getLog(getClass()); + private IUFStatusHandler logger = UFStatus.getHandler(CWAParser.class); private final PointDataDescription pointDataDescription; @@ -84,8 +86,6 @@ public class CWAParser { private final GeodeticCalculator gc = new GeodeticCalculator(); - private final String pluginName; - private String eventId; private String text; @@ -94,8 +94,6 @@ public class CWAParser { private DataTime startTime; - private DataTime endTime; - private CWADimension dimension; private final List coordinates = new ArrayList(); @@ -117,6 +115,9 @@ public class CWAParser { private static UnitConverter nauticalmileToMeter = NonSI.NAUTICAL_MILE .getConverterTo(SI.METER); + // Maximum possible distance between reference points in nautical miles. + private static final double MAX_VOR_DIST = 999.0; + private Headers headers; static { @@ -139,16 +140,15 @@ public class CWAParser { } /** - * - * @param message - * @param wmoHeader + * @param dao * @param pdd + * @param name + * @param pirepTable */ public CWAParser(CWARecordDao dao, PointDataDescription pdd, String name, TableLoader pirepTable) { pointDataDescription = pdd; cwaDao = dao; - pluginName = name; containerMap = new HashMap(); this.pirepTable = pirepTable; } @@ -244,11 +244,12 @@ public class CWAParser { } /** - * - * @param start - * @return + * @param message + * @return reports + * @throws MalformedDataException */ - private List findReports(byte[] message) { + private List findReports(byte[] message) + throws MalformedDataException { List reports = new ArrayList(); @@ -306,8 +307,11 @@ public class CWAParser { * Raw message data. * @param traceId * Trace id for this data. + * @param headers + * @throws MalformedDataException */ - public void setData(byte[] message, String traceId, Headers headers) { + public void setData(byte[] message, String traceId, Headers headers) + throws MalformedDataException { currentReport = -1; this.traceId = traceId; this.headers = headers; @@ -322,6 +326,9 @@ public class CWAParser { } } + /** + * @param issuanceInfo + */ private void parseIssuanceInfo(String issuanceInfo) { String[] parts = issuanceInfo.split(" "); if ((parts != null) && (parts[0] != null)) { @@ -336,15 +343,21 @@ public class CWAParser { } } + /** + * @param validToInfo + */ private void parseValidToInfo(String validToInfo) { Pattern p = Pattern.compile(InternalReport.TIME); Matcher m = p.matcher(validToInfo); if (m.find()) { String time = m.group(); - endTime = getDataTime(time); + getDataTime(time); } } + /** + * @param vicinityInfo + */ private void parseVicinityInfo(String vicinityInfo) { Pattern vicinityPtrn = Pattern.compile(InternalReport.VICINITY); Matcher m = vicinityPtrn.matcher(vicinityInfo); @@ -358,7 +371,12 @@ public class CWAParser { } } - private void parseCoordinateInfo(String coordinateInfo) { + /** + * @param coordinateInfo + * @throws MalformedDataException + */ + private void parseCoordinateInfo(String coordinateInfo) + throws MalformedDataException { String tokens[] = coordinateInfo.replace("-", " - ").split(" "); boolean getMoreCoords = true; @@ -401,8 +419,21 @@ public class CWAParser { if (direction > 180) { direction -= 360; } - this.gc.setDirection(direction, - nauticalmileToMeter.convert(distance)); + // According to WSOM: + // http://www.nws.noaa.gov/wsom/manual/archives/ND259606.HTML#6.1.2%C2%A0%C2%A0%C2%A0%C2%A0%20CWSU%20Meteorologist%20Responsibilities + // ..."When using a distance in CWSU products all references are in nautical miles (NM). " + // ..."The " (n)nn". is distance and "DD(D)" is a + // 16-point compass direction (e.g., VC IAH or 40NNE + // LBB)." + if (distance > MAX_VOR_DIST) { + throw new MalformedDataException("CWA product " + + wmoHeader.getWmoHeader() + + " has a non-valid distance " + distance + + " NM to " + tok + "."); + } + distance = (float) nauticalmileToMeter + .convert(distance); + this.gc.setDirection(direction, distance); coordinates .add(new Coordinate( this.gc.getDestinationGeographicPoint() @@ -424,6 +455,9 @@ public class CWAParser { } } + /** + * @param geometryInfo + */ private void parseGeometryInfo(String geometryInfo) { boolean found = false; Pattern lineGeomPtrn = Pattern.compile(InternalReport.LINE_GEOM); @@ -459,9 +493,12 @@ public class CWAParser { text = ""; dimension = CWADimension.CANCELED; startTime = null; - endTime = null; } + /** + * @param timeStr + * @return DataTime from header + */ private DataTime getDataTime(String timeStr) { Calendar cal = TimeTools.findDataTime(timeStr, headers); if (cal != null) { @@ -471,16 +508,14 @@ public class CWAParser { } } + /** + * @return CWA Record + */ private CWARecord getRecord() { CWARecord record = new CWARecord(); record.setEventId(eventId); record.setDimension(dimension); record.setMessageData(text); - // TimeRange tr = new TimeRange( - // startTime.getRefTimeAsCalendar(), - // endTime.getRefTimeAsCalendar()); - // DataTime dataTime = new DataTime( - // startTime.getRefTimeAsCalendar(),tr); DataTime dataTime = new DataTime(startTime.getRefTimeAsCalendar()); record.setDataTime(dataTime); Coordinate[] coord = null; diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/InternalReport.java b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/InternalReport.java index 13248f52ca..d7d37e8c5e 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/InternalReport.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/decoder/InternalReport.java @@ -28,8 +28,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; /** * @@ -37,9 +37,10 @@ import org.apache.commons.logging.LogFactory; *
  * 
  * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Feb 1, 2010            jsanchez     Initial creation
+ * Date    Ticket#         Engineer    Description
+ * ------- ----------      ----------- --------------------------
+ * Feb 01, 2010            jsanchez     Initial creation
+ * Mar 26, 2014            skorolev    Updated logger.
  * 
  * 
* @@ -47,7 +48,8 @@ import org.apache.commons.logging.LogFactory; * @version 1.0 */ public class InternalReport { - private static Log logger = LogFactory.getLog(InternalReport.class); + private static IUFStatusHandler logger = UFStatus + .getHandler(InternalReport.class); private static final String ISSUANCE = "^([A-Z]{3})([0-9]) +U?CWA +([0-9]{6}) *"; @@ -174,9 +176,7 @@ public class InternalReport { } else { m = p3.matcher(s); if (m.matches()) { - reports - .add(new InternalReport(InternalType.VICINITY, - s)); + reports.add(new InternalReport(InternalType.VICINITY, s)); } else if (issuanceFound && validtoFound && !coordinateFound) { reports.add(new InternalReport(InternalType.COORDS, s)); diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/util/TableLoader.java b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/util/TableLoader.java index 8924bc5e6e..3503817784 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/util/TableLoader.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.cwa/src/com/raytheon/uf/edex/plugin/cwa/util/TableLoader.java @@ -28,10 +28,9 @@ import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.vividsolutions.jts.geom.Coordinate; /** @@ -42,7 +41,8 @@ import com.vividsolutions.jts.geom.Coordinate; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Feb 2, 2010 jsanchez Initial creation + * Feb 02, 2010 jsanchez Initial creation + * Mar 26, 2014 skorolev Updated logger. * * * @@ -54,7 +54,7 @@ public class TableLoader { private static HashMap pirepTable = new HashMap(); /** The logger */ - private Log logger = LogFactory.getLog(getClass()); + private IUFStatusHandler logger = UFStatus.getHandler(TableLoader.class); private static final String KEY = "\\w{3,3}"; @@ -117,10 +117,18 @@ public class TableLoader { } } + /** + * @param key + * @return + */ public Coordinate get(String key) { return pirepTable.get(key); } + /** + * @param key + * @return + */ public boolean contains(String key) { return pirepTable.containsKey(key); }