From 27efe780b1902e7b62ad8c36df78b922de29f386 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Wed, 18 Sep 2013 09:47:46 -0500 Subject: [PATCH] Issue #2249 Add check for director when checking for file created by the TextEditorDialog. Change-Id: Iede767fca5a720e1972c772f752bcf830f8c092b Former-commit-id: b3b6ed29e62cba3165eee86f0acfa41507b57890 [formerly 604ff6a0dd4731663ad82199b6528fc90332a604 [formerly bfa59e5de2ad0d6bb0625b275c43aede596cb2c2]] Former-commit-id: 604ff6a0dd4731663ad82199b6528fc90332a604 Former-commit-id: f5fa113deda4aeb516a056dc3c4b358ee886b769 --- .../texteditor/dialogs/TextEditorDialog.java | 4 ++ .../WarningDecoder.py | 2 +- .../uf/edex/decodertools/time/TimeTools.java | 38 ++++++++++++++++--- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/cave/com.raytheon.viz.texteditor/src/com/raytheon/viz/texteditor/dialogs/TextEditorDialog.java b/cave/com.raytheon.viz.texteditor/src/com/raytheon/viz/texteditor/dialogs/TextEditorDialog.java index fa97fc7225..2d3bc8a005 100644 --- a/cave/com.raytheon.viz.texteditor/src/com/raytheon/viz/texteditor/dialogs/TextEditorDialog.java +++ b/cave/com.raytheon.viz.texteditor/src/com/raytheon/viz/texteditor/dialogs/TextEditorDialog.java @@ -4968,6 +4968,10 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener, oup.setWmoType(fixNOR(prod.getBbbid())); oup.setUserDateTimeStamp(prod.getHdrtime()); StringBuilder fileName = new StringBuilder(); + + // The .wan extension followed by the 10 digit epoch seconds + // of simulated time is used in EDEX's WarningDecoder to + // determine the base time. fileName.append(awipsID).append(".wan") .append(TimeUtil.getUnixTime(TimeUtil.newDate())); oup.setFilename(fileName.toString()); diff --git a/edexOsgi/com.raytheon.edex.plugin.warning/WarningDecoder.py b/edexOsgi/com.raytheon.edex.plugin.warning/WarningDecoder.py index a7d4c556ef..d51f38ec3a 100644 --- a/edexOsgi/com.raytheon.edex.plugin.warning/WarningDecoder.py +++ b/edexOsgi/com.raytheon.edex.plugin.warning/WarningDecoder.py @@ -128,7 +128,7 @@ class StdWarningDecoder(): except : LogStream.logProblem('Unable to get timestamp from filename: "%s"' % (self._incomingFilename)) else: - # Use the epoch seconds from file generated by the text editor dialog, + # Use the epoch seconds in the file generated by TextEditorDialog.java. self._time = long(warningTimestamp) os.umask(0) #ensure proper permissions diff --git a/edexOsgi/com.raytheon.uf.edex.decodertools/src/com/raytheon/uf/edex/decodertools/time/TimeTools.java b/edexOsgi/com.raytheon.uf.edex.decodertools/src/com/raytheon/uf/edex/decodertools/time/TimeTools.java index abb0f52b41..765257d16c 100644 --- a/edexOsgi/com.raytheon.uf.edex.decodertools/src/com/raytheon/uf/edex/decodertools/time/TimeTools.java +++ b/edexOsgi/com.raytheon.uf.edex.decodertools/src/com/raytheon/uf/edex/decodertools/time/TimeTools.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.edex.decodertools.time; +import java.io.File; import java.text.ParseException; import java.util.Calendar; import java.util.TimeZone; @@ -68,10 +69,21 @@ public class TimeTools { .compile("(.*\\.)(\\d{8}|\\d{10})$"); /** - * Time stamp for a file name created by the Text Editor Dialog. + * Time stamp for a file name created by the Text Editor Dialog. This + * assumes the 10 digit following .wan is the warning's issue time in epoch + * seconds. */ - private static final Pattern FILE_WARNING_TIMESTAMP = Pattern - .compile(".*\\.wan(\\d{10})$"); + private static final String TEXT_EDITOR_WARNING = ".*\\.wan(\\d{10})$"; + + /** + * Environment variable with the root directory. + */ + private static final String DATA_ARCHIVE_ROOT = "data.archive.root"; + + /** + * Pattern for getting time stamp from Text Editor Dialog created files. + */ + private static Pattern FILE_WARNING_TIMESTAMP = null; public static final Pattern WMO_TIMESTAMP = Pattern .compile("([0-3][0-9])(\\d{2})(\\d{2})[Zz]?"); @@ -113,7 +125,7 @@ public class TimeTools { } - /** Allows the check on archive to be overriden for testing. */ + /** Allows the check on archive to be overridden for testing. */ static ICheckAllowArchive checkAllowArchive = new CheckOSEnv(); /** @@ -246,12 +258,26 @@ public class TimeTools { } /** - * Get the time stamp of a warning file name. + * Get the time stamp of a warning file name based on the name generated by + * the TextEditorDialog. * * @param fileName - * @return timestamp if if matches FILE_WARNING_TIMESTAMP otherwise null + * @return timestamp warning's issue time in epoch seconds when fileName is + * a Text Editor Dialog file otherwise null */ public static final String getWarningTimestamp(String fileName) { + if (FILE_WARNING_TIMESTAMP == null) { + // Create pattern to test if fileName is in a director relative to + // DATA_ARCHIVE_ROOT and ends with the expected extension. + StringBuilder pattern = new StringBuilder("^"); + pattern.append(System.getProperty(DATA_ARCHIVE_ROOT)); + if (!pattern.substring(pattern.length() - 1).equals(File.separator)) { + pattern.append(File.separator); + } + pattern.append(TEXT_EDITOR_WARNING); + FILE_WARNING_TIMESTAMP = Pattern.compile(pattern.toString()); + } + String timestamp = null; Matcher matcher = FILE_WARNING_TIMESTAMP.matcher(fileName); if (matcher.find()) {