Issue #1185 - Add metar2shef write to archive
Amend: Code review corrections Change-Id: I4b921c25d5b3ced59774cd90a2450ba60d3a42b3 Former-commit-id:2c58ced6f6
[formerlye3ec5ee975
] [formerly8279facaf3
] [formerly3434561427
[formerly8279facaf3
[formerly f6333fecdc9087c0757c8f098cf0f1c34a7b619a]]] Former-commit-id:3434561427
Former-commit-id: 7a3a258d00d17f421aba697c8bf973088b93a8e3 [formerly9387024461
] Former-commit-id:3fc46c136f
This commit is contained in:
parent
2de7124a93
commit
6efd5bb314
8 changed files with 522 additions and 239 deletions
|
@ -3,5 +3,6 @@
|
|||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="unit-test"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -20,7 +20,8 @@ Require-Bundle: com.raytheon.edex.common,
|
|||
com.raytheon.uf.common.localization,
|
||||
javax.persistence,
|
||||
org.apache.commons.cli;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.dataplugin.shef;bundle-version="1.12.1174"
|
||||
com.raytheon.uf.common.dataplugin.shef;bundle-version="1.12.1174",
|
||||
org.junit;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Import-Package: com.raytheon.edex.plugin.obs,
|
||||
com.raytheon.edex.plugin.obs.metar,
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
**/
|
||||
package com.raytheon.edex.transform.shef;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
|
@ -33,7 +37,6 @@ import com.raytheon.edex.esb.Headers;
|
|||
import com.raytheon.edex.transform.shef.obs.ObsToSHEFOptions;
|
||||
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
||||
import com.raytheon.uf.common.ohd.AppsDefaults;
|
||||
import com.raytheon.uf.edex.decodertools.core.DecoderTools;
|
||||
import com.raytheon.uf.edex.decodertools.time.TimeTools;
|
||||
import com.raytheon.uf.edex.wmo.message.WMOHeader;
|
||||
|
||||
|
@ -45,6 +48,9 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 30, 2008 1659 jkorman Initial creation
|
||||
* ======================================
|
||||
* AWIPS2 DR Work
|
||||
* 20120918 1185 jkorman Added save to archive capability.
|
||||
* </pre>
|
||||
*
|
||||
* @author jkorman
|
||||
|
@ -54,8 +60,24 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
|
|||
public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
||||
implements ShefTransformerInterface {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
protected static final String SOH = String.valueOf((char) 1);
|
||||
|
||||
protected static final String CRCRLF = "\r\r\n";
|
||||
|
||||
protected static final String ETX = String.valueOf((char) 3);
|
||||
|
||||
private final String WMO_HEADER_FMT;
|
||||
|
||||
private static final String ARCHIVE_FORMAT = "%s_%04d";
|
||||
|
||||
// Note that the nuber of digits must agree with ARCHIVE_FORMAT
|
||||
private static final int MAX_ARCHIVE_SEQUENCE = 10000;
|
||||
|
||||
private static final String WMO_MSG_SEQ_FMT = "%03d";
|
||||
|
||||
// WMO Sequence number range from 001..999
|
||||
private static final int MAX_WMO_MSG_SEQ = 1000;
|
||||
|
||||
public static final String METAR_2_SHEF_NNN = "MTR";
|
||||
|
||||
public static final String METAR_2_SHEF_OPT = "metar2shef_options";
|
||||
|
@ -76,6 +98,10 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
|
||||
public static final String SHEF_OBS_BASISTIME_FMT = "/DC%1$ty%1$tm%1$td%1$tH%1$tM";
|
||||
|
||||
public static final String OPT_ARC_ENABLE = "archive_enable";
|
||||
|
||||
public static final String OPT_SHEF_ARC_DIR = "archive_shefdata_dir";
|
||||
|
||||
// ***********************
|
||||
private static Integer instanceId = 0;
|
||||
|
||||
|
@ -83,6 +109,9 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
|
||||
// ***********************
|
||||
// Exposed properties
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private String serviceName = null;
|
||||
|
||||
private int messageCount = 0;
|
||||
|
@ -93,18 +122,26 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
|
||||
private String metar2ShefOptions = null;
|
||||
|
||||
ObsToSHEFOptions options = null;
|
||||
private boolean archiveEnabled = false;
|
||||
|
||||
private String shefArchiveDir = null;
|
||||
|
||||
private File shefArchiveFileDir = null;
|
||||
|
||||
protected ObsToSHEFOptions options = null;
|
||||
|
||||
private static AtomicInteger sequenceNumber = new AtomicInteger();
|
||||
|
||||
protected static AtomicInteger msgSequence = new AtomicInteger();
|
||||
// ************************************************************
|
||||
|
||||
protected static final String SOH = String.valueOf((char) 1);
|
||||
|
||||
protected static final String CRCRLF = "\r\r\n";
|
||||
|
||||
protected static final String ETX = String.valueOf((char) 3);
|
||||
|
||||
private final String WMO_HEADER_FMT;
|
||||
|
||||
/**
|
||||
* Create the common transformer.
|
||||
* @param cmdLine Command line options that may be used if these
|
||||
* options are not present in the Apps_defaults.
|
||||
* @param headerFmt The specific WMO header format string to be used
|
||||
* when constructing a WMO header for a particular subclass.
|
||||
*/
|
||||
public AbstractShefTransformer(String cmdLine, String headerFmt) {
|
||||
|
||||
commandLineOptions = cmdLine;
|
||||
|
@ -128,13 +165,17 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
throws TransformerException {
|
||||
String cmdLine = AppsDefaults.getInstance().getToken(METAR_2_SHEF_OPT,
|
||||
null);
|
||||
if ((options != null) && (cmdLine != null)) {
|
||||
if (!cmdLine.equals(metar2ShefOptions)) {
|
||||
metar2ShefOptions = cmdLine;
|
||||
options.updateCommandLine(cmdLine);
|
||||
if(options != null) {
|
||||
if(cmdLine != null) {
|
||||
if (!cmdLine.equals(metar2ShefOptions)) {
|
||||
metar2ShefOptions = cmdLine;
|
||||
options.updateCommandLine(cmdLine);
|
||||
}
|
||||
}
|
||||
options.updateOptions();
|
||||
}
|
||||
configureArchiveDir();
|
||||
|
||||
return transformReport(report, headers);
|
||||
}
|
||||
|
||||
|
@ -145,7 +186,7 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
*/
|
||||
public static Iterator<?> iterate(PluginDataObject[] objects) {
|
||||
Iterator<PluginDataObject> it = null;
|
||||
if (objects != null) {
|
||||
if ((objects != null)&&(objects.length > 0)) {
|
||||
List<PluginDataObject> obj = Arrays.asList(objects);
|
||||
if (obj != null) {
|
||||
it = obj.iterator();
|
||||
|
@ -173,25 +214,24 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param report
|
||||
* @return
|
||||
* @throws TransformerException
|
||||
* Transform the input report to a SHEF encoded report.
|
||||
* @param report A report to transform.
|
||||
* @return The encoded SHEF report.
|
||||
* @throws TransformerException An error occurred during proccessing.
|
||||
*/
|
||||
protected abstract byte[] transformReport(T report, Headers headers)
|
||||
throws TransformerException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param buffer
|
||||
* Create a new buffer containing the opening stanza of a WMO bulletin.
|
||||
* @param sequenceId Abuffer
|
||||
* @param report
|
||||
* @return
|
||||
*/
|
||||
protected StringBuilder openWMOMessage(int sequenceId, int initialSize) {
|
||||
|
||||
sequenceId = (sequenceId % 1000) + 1;
|
||||
protected StringBuilder openWMOMessage(int initialSize) {
|
||||
StringBuilder buffer = new StringBuilder(initialSize);
|
||||
buffer.append(String.format("%s" + CRCRLF + "%03d", SOH, sequenceId));
|
||||
startMessageLine(buffer);
|
||||
buffer.append(String.format(WMO_MSG_SEQ_FMT, getMsgSequenceNumber()));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -327,6 +367,23 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
return jmxModeOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state of the archive enabled flag. This value follows
|
||||
* AppsDefaults:archive_enable.
|
||||
* @return The archive enabled state.
|
||||
*/
|
||||
private boolean isArchiveEnabled() {
|
||||
return archiveEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shef archive file directory if it exists.
|
||||
* @return
|
||||
*/
|
||||
private File getShefArchiveFileDir() {
|
||||
return shefArchiveFileDir;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -339,6 +396,60 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
metar2ShefOptions = commandLineOptions;
|
||||
}
|
||||
options = new ObsToSHEFOptions(metar2ShefOptions, true);
|
||||
configureArchiveDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an encoded SHEF observation to a specified archive directory.
|
||||
* @param shefObs The SHEF encoded data to archive.
|
||||
* @param fileName The base filename.
|
||||
*/
|
||||
protected void archiveSHEFObs(String shefObs, String fileName) {
|
||||
if(isArchiveEnabled()) {
|
||||
File arcFile = getShefArchiveFileDir();
|
||||
if(arcFile != null) {
|
||||
String fName = String.format(ARCHIVE_FORMAT, fileName, getSequenceNumber());
|
||||
File outFile = new File(arcFile, fName);
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(outFile);
|
||||
fos.write(shefObs.getBytes());
|
||||
fos.flush();
|
||||
} catch(IOException ioe) {
|
||||
logger.error("Could not archive data " + fName);
|
||||
} finally {
|
||||
if(fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch(IOException ioe) {
|
||||
logger.error("Could not close archive file " + fName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.error("Could not archive data for " + fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next sequence number.
|
||||
* @return The sequence number.
|
||||
*/
|
||||
private synchronized int getSequenceNumber() {
|
||||
int seq = sequenceNumber.addAndGet(1);
|
||||
sequenceNumber.compareAndSet(MAX_ARCHIVE_SEQUENCE, 1);
|
||||
return seq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next message sequence number.
|
||||
* @return The message sequence number.
|
||||
*/
|
||||
private synchronized int getMsgSequenceNumber() {
|
||||
int seq = msgSequence.addAndGet(1);
|
||||
msgSequence.compareAndSet(MAX_WMO_MSG_SEQ, 1);
|
||||
return seq;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -369,4 +480,59 @@ public abstract class AbstractShefTransformer<T extends PluginDataObject>
|
|||
return rtn.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, or recreate and validate the shef archive directory.
|
||||
*/
|
||||
private void configureArchiveDir() {
|
||||
archiveEnabled = AppsDefaults.getInstance().getBoolean(OPT_ARC_ENABLE,
|
||||
false);
|
||||
String arcDir = AppsDefaults.getInstance().getToken(OPT_SHEF_ARC_DIR);
|
||||
if (arcDir != null) {
|
||||
if (archiveEnabled) {
|
||||
boolean update = false;
|
||||
if (shefArchiveDir == null) {
|
||||
update = true;
|
||||
} else {
|
||||
update = !shefArchiveDir.equals(arcDir);
|
||||
}
|
||||
if (update) {
|
||||
File f = null;
|
||||
try {
|
||||
f = new File(arcDir);
|
||||
if (!f.exists()) {
|
||||
if (!f.mkdirs()) {
|
||||
f = null;
|
||||
logger.error(String
|
||||
.format("Could not create SHEF archive directory [%s] - Are permissions set correctly?",
|
||||
arcDir));
|
||||
}
|
||||
} else {
|
||||
// Ok, the arcDir exists, ensure that it is a
|
||||
// directory!
|
||||
if (!f.isDirectory()) {
|
||||
logger.error(String
|
||||
.format("Path [%s] is not a directory, cannot create directory",
|
||||
f.getAbsolutePath()));
|
||||
f = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
f = null;
|
||||
logger.error(
|
||||
String.format(
|
||||
"Could not create SHEF archive directory [%s] - Are permissions set correctly?",
|
||||
arcDir), e);
|
||||
}
|
||||
if (f != null) {
|
||||
shefArchiveFileDir = f;
|
||||
shefArchiveDir = arcDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.error(String.format(
|
||||
"Apps_defaults token [%s] is not defined!",
|
||||
OPT_SHEF_ARC_DIR));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,11 +19,9 @@
|
|||
**/
|
||||
package com.raytheon.edex.transform.shef;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -35,7 +33,6 @@ import com.raytheon.edex.transform.shef.obs.ObsToSHEFOptions;
|
|||
import com.raytheon.edex.transform.shef.obs.SHEF_Metar_Codes;
|
||||
import com.raytheon.edex.transform.shef.obs.SHEF_Obs_Codes;
|
||||
import com.raytheon.edex.transform.shef.obs.Utilities;
|
||||
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
||||
import com.raytheon.uf.common.dataplugin.obs.metar.MetarRecord;
|
||||
import com.raytheon.uf.edex.decodertools.core.DecoderTools;
|
||||
import com.raytheon.uf.edex.decodertools.time.TimeTools;
|
||||
|
@ -50,6 +47,9 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 29, 2008 1659 jkorman Initial creation
|
||||
* ======================================
|
||||
* AWIPS2 DR Work
|
||||
* 20120918 1185 jkorman Added save to archive capability.
|
||||
* </pre>
|
||||
*
|
||||
* @author jkorman
|
||||
|
@ -71,20 +71,30 @@ public class MetarToShefTransformer extends
|
|||
|
||||
private static final String SENS_TYPE_AUTO = " AUTO";
|
||||
|
||||
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
static {
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
|
||||
private static final int P1_MIN = 50;
|
||||
private static final int P2_MAX = 5;
|
||||
|
||||
/**
|
||||
* Construct an instance of this transformer.
|
||||
* @param cmdLine Command line options that may be used if these
|
||||
* options are not present in the Apps_defaults.
|
||||
*/
|
||||
public MetarToShefTransformer(String cmdLine) {
|
||||
super(cmdLine, WMO_HEADER_FMT);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param report
|
||||
* @return
|
||||
* Attempt to transform a single metar observation into SHEF encoded observations.
|
||||
* @param report A metar report to encode.
|
||||
* @param The system headers associated with the original metar message.
|
||||
* @return The encoded SHEF report as a byte array. May return an empty
|
||||
* array if the report should not have been encoded or some error occured.
|
||||
* @throws TransformerException
|
||||
*/
|
||||
@Override
|
||||
|
@ -94,84 +104,76 @@ public class MetarToShefTransformer extends
|
|||
// Transformed METAR PluginDataObject to SHEF
|
||||
byte[] result = null;
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
Calendar nowCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
||||
Calendar metarTime = TimeTools.getSystemCalendar((String) headers
|
||||
Calendar nowCalendar = TimeTools.getSystemCalendar();
|
||||
|
||||
Calendar metarTime = TimeTools.getSystemCalendar((String) headers
|
||||
.get(DecoderTools.INGEST_FILE_NAME));
|
||||
|
||||
|
||||
|
||||
logger.debug("report object type = " + report.getClass().getName());
|
||||
|
||||
incrementMessageCount();
|
||||
int place = 0;
|
||||
try {
|
||||
// Ensure we're dealing with metar data.
|
||||
if (report instanceof MetarRecord) {
|
||||
MetarRecord rec = (MetarRecord) report;
|
||||
|
||||
String ccc = null;
|
||||
String msg = rec.getMessageData();
|
||||
WMOHeader hdr = new WMOHeader(msg.getBytes());
|
||||
if((hdr != null) && (hdr.isValid())) {
|
||||
ccc = hdr.getCccc();
|
||||
if(ccc != null) {
|
||||
if(ccc.length() > 3) {
|
||||
ccc = ccc.substring(ccc.length() - 3);
|
||||
}
|
||||
String ccc = null;
|
||||
String msg = report.getMessageData();
|
||||
WMOHeader hdr = new WMOHeader(msg.getBytes());
|
||||
if ((hdr != null) && (hdr.isValid())) {
|
||||
ccc = hdr.getCccc();
|
||||
if (ccc != null) {
|
||||
if (ccc.length() > 3) {
|
||||
ccc = ccc.substring(ccc.length() - 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (encodeThisStation(rec)) {
|
||||
place = 1;
|
||||
String stnId = rec.getStationId();
|
||||
place = 2;
|
||||
StringBuilder sb = makeWMOHeader(openWMOMessage(0, 200),
|
||||
stnId, headers, hdr);
|
||||
place = 3;
|
||||
if (encodeThisStation(report)) {
|
||||
place = 1;
|
||||
String stnId = report.getStationId();
|
||||
place = 2;
|
||||
StringBuilder sb = makeWMOHeader(openWMOMessage(200), stnId,
|
||||
headers, hdr);
|
||||
String fileName = makeWMOHeader(new StringBuilder(20), stnId, headers, hdr).toString().trim().replace(' ', '_');
|
||||
place = 3;
|
||||
|
||||
startMessageLine(sb);
|
||||
if(ccc != null) {
|
||||
sb.append(ccc);
|
||||
}
|
||||
sb.append(METAR_2_SHEF_NNN);
|
||||
if(stnId.length() == 4) {
|
||||
sb.append(stnId.substring(1));
|
||||
} else if (stnId.length() == 3) {
|
||||
sb.append(stnId);
|
||||
}
|
||||
|
||||
startMessageLine(sb);
|
||||
metarTime=rec.getTimeObs();
|
||||
if (metarTime.compareTo(nowCalendar)> 0) {
|
||||
sb.append(": WARNING: observation time is greater than the system time for the same day");
|
||||
startMessageLine(sb);
|
||||
sb.append(": observation time= " + rec.getDataTime() +
|
||||
" System time= "+ dateFormat.format(nowCalendar.getTime()));
|
||||
startMessageLine(sb);
|
||||
} else {
|
||||
sb.append(": WARNING: observation time is less than the system time for the same day");
|
||||
startMessageLine(sb);
|
||||
sb.append("observation time= " + rec.getDataTime() +
|
||||
" System time= "+ dateFormat.format(nowCalendar.getTime()));
|
||||
startMessageLine(sb);
|
||||
}
|
||||
|
||||
sb.append(":SHEF derived data created by MetarToShefTransformer:");
|
||||
startMessageLine(sb);
|
||||
sb.append(":TRACEID = ");
|
||||
sb.append(rec.getWmoHeader());
|
||||
sb.append(":");
|
||||
place = 4;
|
||||
String shef = closeWMOMessage(encodeShef(sb, rec, headers))
|
||||
.toString();
|
||||
|
||||
if (options.isOptVerbose()) {
|
||||
logger.info("MetarToShef: = " + shef);
|
||||
}
|
||||
|
||||
setLastMessage(shef);
|
||||
result = shef.getBytes();
|
||||
startMessageLine(sb);
|
||||
if (ccc != null) {
|
||||
sb.append(ccc);
|
||||
}
|
||||
sb.append(METAR_2_SHEF_NNN);
|
||||
if (stnId.length() == 4) {
|
||||
sb.append(stnId.substring(1));
|
||||
} else if (stnId.length() == 3) {
|
||||
sb.append(stnId);
|
||||
}
|
||||
|
||||
startMessageLine(sb);
|
||||
metarTime = report.getTimeObs();
|
||||
if (metarTime.compareTo(nowCalendar) > 0) {
|
||||
sb.append(": WARNING: observation time is greater than the system time for the same day");
|
||||
startMessageLine(sb);
|
||||
sb.append(": Observation time = ");
|
||||
sb.append(report.getDataTime());
|
||||
sb.append(" System time= ");
|
||||
synchronized(dateFormat) {
|
||||
sb.append(dateFormat.format(nowCalendar.getTime()));
|
||||
}
|
||||
}
|
||||
sb.append(": SHEF derived data created by MetarToShefTransformer:");
|
||||
startMessageLine(sb);
|
||||
sb.append(": TRACEID = ");
|
||||
sb.append(report.getWmoHeader());
|
||||
sb.append(":");
|
||||
place = 4;
|
||||
String shef = closeWMOMessage(encodeShef(sb, report, headers))
|
||||
.toString();
|
||||
|
||||
if (options.isOptVerbose()) {
|
||||
logger.info(String.format("MetarToShef: = %s", shef));
|
||||
}
|
||||
archiveSHEFObs(shef, fileName);
|
||||
|
||||
setLastMessage(shef);
|
||||
result = shef.getBytes();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in transform:place " + place, e);
|
||||
|
@ -371,9 +373,14 @@ public class MetarToShefTransformer extends
|
|||
String s = report.getStationId();
|
||||
return (encodeOk & options.checkName(s));
|
||||
}
|
||||
|
||||
private static StringBuilder writeObs(StringBuilder sb, String obs) {
|
||||
|
||||
/**
|
||||
* Reformats observation text into a SHEF comment.
|
||||
* @param sb Buffer to receive the formatted data.
|
||||
* @param obs The observation to format.
|
||||
* @return The formatted data.
|
||||
*/
|
||||
public static StringBuilder writeObs(StringBuilder sb, String obs) {
|
||||
boolean startLine = true;
|
||||
int count = 0;
|
||||
String indent = "";
|
||||
|
@ -402,51 +409,6 @@ public class MetarToShefTransformer extends
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static final Boolean testIterate() {
|
||||
PluginDataObject[] pdos = null;
|
||||
Iterator<?> it = MetarToShefTransformer.iterate(pdos);
|
||||
return (it != null) && (!it.hasNext()) && (it.next() == null);
|
||||
}
|
||||
|
||||
public static final void main(String[] args) {
|
||||
if (testIterate()) {
|
||||
System.out.println("Test passed");
|
||||
} else {
|
||||
System.out.println("Test failed");
|
||||
}
|
||||
|
||||
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 = writeObs(newobs,sb.toString());
|
||||
|
||||
System.out.println(newobs);
|
||||
|
||||
Calendar c = TimeTools.getBaseCalendar(2011, 11, 30);
|
||||
c.set(Calendar.HOUR_OF_DAY, 16);
|
||||
c.set(Calendar.MINUTE, 21);
|
||||
|
||||
|
||||
System.out.println(String.format(WMO_HEADER_FMT, "KOMA", c));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,9 @@ import com.raytheon.uf.edex.wmo.message.WMOHeader;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 29, 2008 1659 jkorman Initial creation
|
||||
*
|
||||
* ======================================
|
||||
* AWIPS2 DR Work
|
||||
* 20120918 1185 jkorman Added save to archive capability.
|
||||
* </pre>
|
||||
*
|
||||
* @author jkorman
|
||||
|
@ -77,37 +79,33 @@ public class SMToShefTransformer extends AbstractShefTransformer<ObsCommon> {
|
|||
// 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);
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -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.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* ======================================
|
||||
* AWIPS2 DR Work
|
||||
* 20120918 1185 jkorman Extracted from mains
|
||||
* </pre>
|
||||
*
|
||||
* @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());
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* ======================================
|
||||
* AWIPS2 DR Work
|
||||
* 20120918 1185 jkorman Extracted from mains
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue