{
// Transformed Synoptic PluginDataObject to SHEF
byte[] result = null;
try {
- // Ensure we're dealing with synoptic data.
- if (report instanceof ObsCommon) {
+ // Currently returns false, so nothing is encoded at this time.
+ if (encodeThisStation(report)) {
- ObsCommon rec = (ObsCommon) report;
+ WMOHeader hdr = new WMOHeader(report.getObsText().getBytes());
- // Currently returns false, so nothing is encoded at this time.
- if (encodeThisStation(rec)) {
+ StringBuilder sb = makeWMOHeader(openWMOMessage(200),
+ "KWOH", headers, hdr);
+ String fileName = makeWMOHeader(new StringBuilder(20), "KWOH",
+ headers, hdr).toString().trim().replace(' ', '_');
- WMOHeader hdr = new WMOHeader(rec.getObsText().getBytes());
+ startMessageLine(sb).append(
+ ": SHEF derived data created by SMToShefTransformer");
+ startMessageLine(sb).append(": TRACEID = ");
+ sb.append(headers.get(DecoderTools.INGEST_FILE_NAME));
- StringBuilder sb = makeWMOHeader(openWMOMessage(0, 200),
- "KWOH", headers, hdr);
-
- startMessageLine(sb)
- .append(":SHEF derived data created by SMToShefTransformer");
- startMessageLine(sb)
- .append(":TRACEID = "
- + headers
- .get(DecoderTools.INGEST_FILE_NAME));
-
- String shef = closeWMOMessage(encodeShef(sb, rec, headers))
- .toString();
-
- if (options.isOptVerbose()) {
- logger.info("SynopticToShef: = " + shef);
- }
-
- setLastMessage(shef);
- result = shef.getBytes();
+ String shef = closeWMOMessage(encodeShef(sb, report, headers))
+ .toString();
+ if (options.isOptVerbose()) {
+ logger.info("SynopticToShef: = " + shef);
}
+
+ archiveSHEFObs(shef, fileName);
+
+ setLastMessage(shef);
+ result = shef.getBytes();
+
}
} catch (Exception e) {
logger.error(e);
diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java
index 8747c41a83..031ca96379 100644
--- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java
+++ b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/transform/shef/obs/ObsToSHEFOptions.java
@@ -26,7 +26,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
-import java.io.StringReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -42,11 +41,12 @@ import org.apache.commons.logging.LogFactory;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
-import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
+import com.raytheon.uf.common.localization.PathManagerFactory;
/**
- * TODO Add Description
+ * Reads options available from the metar2shef command line string, as well as
+ * the metar.cfg.
*
*
*
@@ -55,6 +55,9 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 24, 2010 jkorman Initial creation
+ * ======================================
+ * AWIPS2 DR Work
+ * 20120918 1185 jkorman Added save to archive capability.
*
*
*
@@ -64,7 +67,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel
public class ObsToSHEFOptions {
// 1 minute update delta.
- private static final long updateDelta = 60L * 1000L;
+ private static final long UPDATE_DELTA = 60L * 1000L;
private static final String METAR_CFG = "metar.cfg";
@@ -213,7 +216,7 @@ public class ObsToSHEFOptions {
final Class> clazz;
public CmdLineData(String key, String option, Integer numOptions,
- Class clazz) {
+ Class> clazz) {
this.key = key;
this.option = option;
this.numOptions = numOptions;
@@ -833,9 +836,12 @@ public class ObsToSHEFOptions {
parseCommandLine(commandLine);
}
+ /**
+ * Check if the metar.cfg needs to be reread.
+ */
public void updateOptions() {
long cTime = System.currentTimeMillis() - updateTime;
- if (cTime > updateDelta) {
+ if (cTime > UPDATE_DELTA) {
if (loaded && localized) {
readConfig(METAR_CFG, optConfigContext);
updateTime = System.currentTimeMillis();
@@ -919,7 +925,6 @@ public class ObsToSHEFOptions {
saoOut = val;
} else if (ERROR_FILE.equals(m.group(2)) && lineCount == 5) {
errorFile = val;
- errorFile = val;
} else if (SHEF_PASS.equals(m.group(2)) && lineCount == 6) {
shefPass = val;
}
@@ -983,63 +988,4 @@ public class ObsToSHEFOptions {
}
return sb.toString();
}
-
- public static final void main(String[] args) {
-
- String METAR_CFG_DATA = "/tmp/queue/metar/in\n"
- + "/tmp/queue/metar/out\n"
- + "/tmp/queue/metar/err\n"
- + "+SAOOUT\n"
- + "-ERRORFILE\n"
- + "-SHEFPASS\n"
- + "TAIRZZ TD UP SD UD US PL TX TN PPT PPQ PPH PPD PA TAIRZR TAIRZH TAIRZP TAIRZY PTIR\n"
- + ".begin_names\n" + " KOMA\n" + " KOFF\n" + " KLNK\n"
- + " KFET\n" + " KOFK\n" + " KPMV\n" + " KCBF\n"
- + " KSUX\n" + ".end_names\n" + ".begin_sm_alias\n"
- + " 72550 KOMA\n" + " 72551 KLNK\n" + " 72552 KGRI\n"
- + " 72556 KOFK\n" + " 72557 KSUX\n" + ".end_sm_alias\n"
- + ".begin_pc_reset\n" + " KOMA 40\n" + ".end_pc_reset\n";
-
- String cmdLine = " -a -pedtsep -v -b -strip -pct 4 -howold 405 -p1 -p6 -pall6 -round -w -q1 -g";
-
- ObsToSHEFOptions options = new ObsToSHEFOptions(cmdLine, false);
-
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new StringReader(METAR_CFG_DATA));
- options.readConfig(reader);
-
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
- }
-
- System.out.println(options);
- System.out.println(String.format("%s%s", SAO_OUT, options.saoOut ? "+"
- : "-"));
- System.out.println(String.format("%s%s", ERROR_FILE,
- options.errorFile ? "+" : "-"));
- System.out.println(String.format("%s%s", SHEF_PASS,
- options.shefPass ? "+" : "-"));
- System.out.println(options.optPE);
- System.out.println(options.optNames);
- System.out.println(options.optAlias);
- System.out.println(options.optPCReset);
-
- System.out.println("Getting pc reset for KOMA = ["
- + options.getPCReset("KOMA") + "]");
- System.out.println("Checking station KSAT = " + options.checkName("KSAT"));
-
- System.out.println(options.isOptZeroAuto1HourPrecip());
-
- System.out.println(options.isOptTypeSrcV());
-
- }
}
diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/unit-test/test/edex/transform/shef/TestM2SOptions.java b/edexOsgi/com.raytheon.edex.plugin.shef/unit-test/test/edex/transform/shef/TestM2SOptions.java
new file mode 100644
index 0000000000..75aa20bc49
--- /dev/null
+++ b/edexOsgi/com.raytheon.edex.plugin.shef/unit-test/test/edex/transform/shef/TestM2SOptions.java
@@ -0,0 +1,96 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package test.edex.transform.shef;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
+import com.raytheon.edex.transform.shef.obs.ObsToSHEFOptions;
+
+/**
+ * Tests extracted from ObsToSHEFOptions.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * ======================================
+ * AWIPS2 DR Work
+ * 20120918 1185 jkorman Extracted from mains
+ *
+ *
+ * @author jkorman
+ * @version 1.0
+ */
+
+public class TestM2SOptions {
+
+ @Test
+ public void testConstructOptions() {
+
+ String METAR_CFG_DATA = "/tmp/queue/metar/in\n"
+ + "/tmp/queue/metar/out\n"
+ + "/tmp/queue/metar/err\n"
+ + "+SAOOUT\n"
+ + "-ERRORFILE\n"
+ + "-SHEFPASS\n"
+ + "TAIRZZ TD UP SD UD US PL TX TN PPT PPQ PPH PPD PA TAIRZR TAIRZH TAIRZP TAIRZY PTIR\n"
+ + ".begin_names\n" + " KOMA\n" + " KOFF\n" + " KLNK\n"
+ + " KFET\n" + " KOFK\n" + " KPMV\n" + " KCBF\n"
+ + " KSUX\n" + ".end_names\n" + ".begin_sm_alias\n"
+ + " 72550 KOMA\n" + " 72551 KLNK\n" + " 72552 KGRI\n"
+ + " 72556 KOFK\n" + " 72557 KSUX\n" + ".end_sm_alias\n"
+ + ".begin_pc_reset\n" + " KOMA 40\n" + ".end_pc_reset\n";
+
+ String cmdLine = " -a -pedtsep -v -b -strip -pct 4 -howold 405 -p1 -p6 -pall6 -round -w -q1 -g";
+
+ ObsToSHEFOptions options = new ObsToSHEFOptions(cmdLine, false);
+
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new StringReader(METAR_CFG_DATA));
+ options.readConfig(reader);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+ }
+
+ assertEquals(40, options.getPCReset("KOMA"));
+ assertFalse(options.checkName("KSAT"));
+ assertTrue(options.isOptZeroAuto1HourPrecip());
+ assertFalse(options.isOptTypeSrcV());
+ assertTrue(options.isOptVerbose());
+ assertTrue(options.isOptZero6HourPrecip());
+ }
+}
diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/unit-test/test/edex/transform/shef/TestMetarToShefTransformer.java b/edexOsgi/com.raytheon.edex.plugin.shef/unit-test/test/edex/transform/shef/TestMetarToShefTransformer.java
new file mode 100644
index 0000000000..8a4b988f28
--- /dev/null
+++ b/edexOsgi/com.raytheon.edex.plugin.shef/unit-test/test/edex/transform/shef/TestMetarToShefTransformer.java
@@ -0,0 +1,113 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package test.edex.transform.shef;
+
+import java.util.Iterator;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import com.raytheon.edex.transform.shef.MetarToShefTransformer;
+import com.raytheon.uf.common.dataplugin.IDecoderGettable;
+import com.raytheon.uf.common.dataplugin.PluginDataObject;
+
+/**
+ * Tests extracted from MetarToShef.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * ======================================
+ * AWIPS2 DR Work
+ * 20120918 1185 jkorman Extracted from mains
+ *
+ *
+ *
+ * @author jkorman
+ * @version 1.0
+ */
+
+public class TestMetarToShefTransformer {
+
+ /**
+ * Test that the transformer creates an empty iterator when
+ * given no input.
+ */
+ @Test
+ public void testMetarToShefInteratorA() {
+ PluginDataObject[] pdos = null;
+ Iterator> it = MetarToShefTransformer.iterate(pdos);
+ assertNotNull(it);
+ assertFalse(it.hasNext());
+ assertNull(it.next());
+
+ pdos = new PluginDataObject [0];
+ it = MetarToShefTransformer.iterate(pdos);
+ assertNotNull(it);
+ assertFalse(it.hasNext());
+ assertNull(it.next());
+
+ }
+
+ /**
+ * Test that the transformer creates an non-empty iterator for
+ * given input.
+ */
+ @Test
+ public void testMetarToShefInteratorB() {
+ PluginDataObject p = new PluginDataObject() {
+
+ @Override
+ public IDecoderGettable getDecoderGettable() {
+ return null;
+ }
+ };
+
+ PluginDataObject[] pdos = { p, };
+ Iterator> it = MetarToShefTransformer.iterate(pdos);
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ assertNotNull(it.next());
+ }
+
+ @Test
+ public void testFormatAsComment() {
+
+ StringBuilder sb = new StringBuilder(
+ "KOMA 251152Z 35007KT 10SM BKN035 BKN250 03/01 A2970 RMK AO2 SLP062"
+ + "\n60000 T00330011 10078 20033 53021 931012 933025 98245 4/005=");
+
+ StringBuilder newobs = new StringBuilder();
+ newobs = MetarToShefTransformer.writeObs(newobs, sb.toString());
+
+ assertEquals(
+ "\r\r\n:KOMA 251152Z 35007KT 10SM BKN035 BKN250 03/01 A2970 RMK AO2 SLP062"
+ + "\r\r\n: 60000 T00330011 10078 20033 53021 931012 933025 98245 4/005=",
+ newobs.toString());
+
+ }
+
+
+
+
+}