From 474dda75de8d94d38b2d56bae23305b0172fd60e Mon Sep 17 00:00:00 2001 From: David Gillingham Date: Thu, 13 Feb 2014 15:36:28 -0600 Subject: [PATCH] Issue #2783: Rewrite run_report_alarm script into EDEX service. Change-Id: I26a5e1c98f1454d57522ede49d3e85f2ebc7d8be Former-commit-id: 32719432ff824b2df610ce8ea277ac67c4ef7ad4 [formerly 32719432ff824b2df610ce8ea277ac67c4ef7ad4 [formerly d0ae60f4abaa0bd2c8f966de2e4ed4c5989737fd]] Former-commit-id: de12904c7a7678024a9cd7cae4e2bd2929a0c06f Former-commit-id: 1520317c2485e192b4cf2b649c82bcd6599d3e31 --- .../build.edex/esb/conf/logback-ingest.xml | 18 + .../META-INF/MANIFEST.MF | 1 - .../alarms/AlertalarmStdTextProductUtil.java | 339 -------- .../plugin/shef/alarms/CmdlineOption.java | 55 -- .../plugin/shef/alarms/CmdlineOptionId.java | 106 --- .../plugin/shef/alarms/CmdlineOptions.java | 70 -- .../edex/plugin/shef/alarms/RecordMgr.java | 245 ------ .../plugin/shef/alarms/ReportOptions.java | 267 ------- .../common_static/base/hydro/Apps_defaults | 37 + .../META-INF/MANIFEST.MF | 8 +- .../res/spring/alarmWhfs-spring.xml | 26 +- .../ohd/reportalarm}/AlertalarmRecord.java | 2 +- .../uf/edex/ohd/reportalarm}/Constants.java | 48 +- .../edex/ohd/reportalarm}/FilterOption.java | 25 +- .../uf/edex/ohd/reportalarm/RecordMgr.java | 244 ++++++ .../uf/edex/ohd/reportalarm}/ReportMode.java | 2 +- .../edex/ohd/reportalarm/ReportOptions.java | 269 +++++++ .../edex/ohd/reportalarm}/ReportWriter.java | 732 ++++++++++-------- .../ohd/reportalarm/RunReportAlarmSrv.java | 159 ++++ .../hydroapps/whfs/bin/run_alarm_whfs | 4 +- .../hydroapps/whfs/bin/run_report_alarm | 158 +--- 21 files changed, 1216 insertions(+), 1599 deletions(-) delete mode 100644 edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java delete mode 100644 edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOption.java delete mode 100644 edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptionId.java delete mode 100644 edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptions.java delete mode 100644 edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/RecordMgr.java delete mode 100644 edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportOptions.java rename edexOsgi/{com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms => com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm}/AlertalarmRecord.java (99%) rename edexOsgi/{com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms => com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm}/Constants.java (64%) rename edexOsgi/{com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms => com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm}/FilterOption.java (69%) create mode 100644 edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RecordMgr.java rename edexOsgi/{com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms => com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm}/ReportMode.java (96%) create mode 100644 edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportOptions.java rename edexOsgi/{com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms => com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm}/ReportWriter.java (74%) create mode 100644 edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RunReportAlarmSrv.java diff --git a/edexOsgi/build.edex/esb/conf/logback-ingest.xml b/edexOsgi/build.edex/esb/conf/logback-ingest.xml index d040b385c1..69f9fb5a80 100644 --- a/edexOsgi/build.edex/esb/conf/logback-ingest.xml +++ b/edexOsgi/build.edex/esb/conf/logback-ingest.xml @@ -164,6 +164,18 @@ %-5p %d [%t] %c{0}: %m%n + + + + + ${edex.home}/logs/edex-${edex.run.mode}-ohd-%d{yyyyMMdd}.log + 30 + + + + %-5p %d [%t] %c{0}: %m%n + + RadarLog:radarThreadPool.*;SatelliteLog:satelliteThreadPool.*;ShefLog:shefThreadPool.*;TextLog:textThreadPool.*;SmartInitLog:smartInit.*;PurgeLog:Purge.*;ArchiveLog:Archive.* @@ -300,6 +312,12 @@ + + + + + + diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.edex.plugin.shef/META-INF/MANIFEST.MF index 5ea2b8abb7..f5ac2505c1 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.edex.plugin.shef/META-INF/MANIFEST.MF @@ -6,7 +6,6 @@ Bundle-Version: 1.12.1174.qualifier Eclipse-RegisterBuddy: com.raytheon.edex.common, com.raytheon.uf.common.serialization Bundle-Vendor: RAYTHEON Export-Package: com.raytheon.edex.plugin.shef, - com.raytheon.edex.plugin.shef.alarms, com.raytheon.edex.plugin.shef.data, com.raytheon.edex.plugin.shef.data.precip, com.raytheon.edex.plugin.shef.database, diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java deleted file mode 100644 index f30156189e..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmStdTextProductUtil.java +++ /dev/null @@ -1,339 +0,0 @@ -/** - * 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 com.raytheon.edex.plugin.shef.alarms; - -import java.io.File; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.raytheon.edex.textdb.dbapi.impl.TextDB; -import com.raytheon.uf.common.dataplugin.text.request.WriteProductRequest; -import com.raytheon.uf.common.ohd.AppsDefaults; -import com.raytheon.uf.edex.core.EDEXUtil; - -/** - * Provides SHEF with the ability to generate alert/alarms report products and - * write them to the text database. - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * June 15, 2011    9377     jnjanga     Initial creation
- *  July 12, 2013   15711     wkwock      Fix verbose, observe mode, etc
- * 
- * 
- * 
- * - * @author jnjanga - * @version 1.0 - */ - -public class AlertalarmStdTextProductUtil { - - private static Log log = LogFactory - .getLog(AlertalarmStdTextProductUtil.class); - - private static final Options cliOptions = createCmdLineOptions(); - - private static ReportWriter reportWriter = null; - - private static ReportOptions reportOptions = null; - - private static File currReport = null; - - private static String reportDir = null; - - /** - * this application main entry point - * - * @param args - */ - public static void main(String[] args) { - - loadEnvironment(); - - setApplicationSpringContext(Constants.IHFS_CONFIG); - - setReportOptions(args); - - setCurrentReportfile(); - - reportAlarm(); - - System.exit(reportWriter.getAlarmCount()); - } - - /* - * create the org.apache.commons.cli.Options object - */ - private static Options createCmdLineOptions() { - CmdlineOptions options = new CmdlineOptions(); - options.addMandatoryOption(CmdlineOptionId.DB_NAME); - options.addMandatoryOption(CmdlineOptionId.PRODUCT_ID); - options.addOption(CmdlineOptionId.REPORT_MODE); - options.addOption(CmdlineOptionId.MINUTES); - options.addOption(CmdlineOptionId.FILE_SUFFIX); - options.addOption(CmdlineOptionId.FLAGS); - options.addOption(CmdlineOptionId.PE); - options.addOption(CmdlineOptionId.VERBOSE,false); - return options; - } - - /* - * initialize the ReportOptions object based on command line arguments - */ - private static void setReportOptions(String[] args) { - CommandLine line = null; - ReportOptions rptOptions = new ReportOptions(); - - // Check CmdLine arguments - if (args.length < 3) { - System.out.println("Invalid or missing arguments."); - printUsage(); - System.exit(0); - } - - // Process CmdLine Arguments - GnuParser parser = new GnuParser(); - try { - line = parser.parse(cliOptions, args); - } catch (ParseException exp) { - System.err.println("Command line Parsing failed. Reason: " - + exp.getMessage()); - printUsage(); - System.exit(0); - } - - // duplicate options - if (hasDuplicateOptions(line)) { - System.err.println("Error : Duplicate command line options."); - printUsage(); - System.exit(0); - } - - // All user specified options, including mandatory ones - // are recognized , and there are no duplicate options. - // Query the CmdLine and build the report options object - for (CmdlineOptionId optId : CmdlineOptionId.values()) { - String optName = optId.toString(); - System.out.println("optName = " + optName); - if (optName.equalsIgnoreCase("v")) { - if (line.hasOption(optName)) { - System.out.println(" optValue = true"); - } else { - System.out.println(" optValue = false"); - } - } else { - System.out.println(" optValue = " + line.getOptionValue(optName)); - } - - if (line.hasOption(optName)) { - - CmdlineOption option = new CmdlineOption(optId, - line.getOptionValue(optName)); - - try { - rptOptions.addOption(option); - } catch (IllegalArgumentException e) { - System.err.println(e.getMessage()); - System.exit(0); - } - } - } - - // The report options are all valid - Set ignoreMin = new HashSet(); - ignoreMin.add(ReportMode.ALL); - ignoreMin.add(ReportMode.UNREPORTED); - ignoreMin.add(ReportMode.NEAREST); - ignoreMin.add(ReportMode.LATEST_MAXFCST); - if (rptOptions.isMinutesGiven() - && ignoreMin.contains(rptOptions.getMode())) - System.out - .println("Usage : -m value ignored for this -r"); - - reportOptions = rptOptions; - - } - - /* - * check whether user has entered duplicate options on the command line - */ - private static boolean hasDuplicateOptions(CommandLine line) { - Option[] userOptions = line.getOptions(); - Set unique = new HashSet(); - for (Option option : userOptions) - if (!unique.add(option.getOpt())) - return true; - return false; - } - - /* - * Display a usage message - */ - private static void printUsage() { - System.out.print("Usage: report_alarm -d -p "); - System.out.print("[-r] [-m] [-s] "); - System.out.println("[-f] [-e] [-v]"); - } - - /* - * process alertalarmval data. if there data meets alert/alarm conditions, - * report them in a text file and send it to the text database. - */ - private static void reportAlarm() { - Date now = new Date(System.currentTimeMillis()); - - // Get the whole data for the report - AlertalarmRecord aaRecord = RecordMgr.getAlarmData(reportOptions); - - // write the report - reportWriter = new ReportWriter(currReport, reportOptions, now); - reportWriter.writeHeader(); - reportWriter.writeBody(aaRecord); - if (reportOptions.getVerbose()) { - reportWriter.writeVerboseTrailer(); - } else { - reportWriter.writeReportTrailer(); - } - - // save it to the text database if indeed - // there are alarm events to report. - int alarmCount = reportWriter.getAlarmCount(); - if (alarmCount > 0) { - log.info(alarmCount + " alarms reported, report written to " - + reportWriter.getFilename()); - //saveReportTotextDb(); - } else { - log.info("No alarms reported, info sent to " - + reportWriter.getFilename()); - log.info("File NOT sent to text database."); - } - - } - - /* - * saves the report contents to the text database. - */ - private static void saveReportTotextDb() { - - setApplicationSpringContext(Constants.FXA_CONFIG); - - WriteProductRequest request = new WriteProductRequest(); - request.setProductId(reportOptions.getProductId()); - request.setOperationalMode(true); - request.setNotifyAlarmAlert(true); - String rptData = reportWriter.getReportData(); - request.setReportData(rptData); - - log.info("Sending " + reportWriter.getFilename() + " to textdb as id " - + request.getProductId()); - - TextDB textdb = new TextDB(); - long result = textdb.writeProduct(request.getProductId(), - request.getReportData(), request.getOperationalMode(), null); - - if (result != Long.MIN_VALUE) { - log.info("Product " + request.getProductId() - + " successfully sent to textdb"); - } else { - log.error("Error sending product " + request.getProductId() - + " to textdb. status=" + result); - } - - } - - /* - * verify whether necessary application tokens have been defined. - */ - private static void loadEnvironment() { - - System.setProperty("edex.home", System.getenv("EDEX_HOME")); - System.setProperty("db.addr", System.getenv("PGHOST")); - System.setProperty("ih.db.name", System.getenv("DB_NAME")); - System.setProperty("fxa.db.name", System.getenv("FXA_DB_NAME")); - System.setProperty("db.port", System.getenv("PGPORT")); - - AppsDefaults appDefaults = AppsDefaults.getInstance(); - - String aalogDir = appDefaults.getToken(Constants.WHFS_UTIL_LOG_DIR); - - if (aalogDir == null) { - System.out - .println("whfs_util_log_dir directory undefined. Aborting."); - } - - reportDir = appDefaults.getToken(Constants.WHFS_PRODUCT_DIR); - - if (reportDir == null) { - System.out - .println("whfs_product_dir directory undefined . Aborting."); - System.exit(0); - } - } - - /* - * initializes a File object that points to the current alert/alarm report - */ - private static void setCurrentReportfile() { - String pid = reportOptions.getProductId(); - String suffix = reportOptions.getFileSuffix(); - - if (suffix.length() > 0) - currReport = new File(reportDir + File.separator + pid + "." + suffix); - else - currReport = new File(reportDir + File.separator + pid); - - try { - currReport.createNewFile(); - } catch (Exception e) { - log.fatal("Could not create report file " - + String.valueOf(currReport)); - log.info("Exiting."); - System.exit(0); - } - } - - private static void setApplicationSpringContext(String... configLocations) { - if (configLocations.length > 0) { - ClassPathXmlApplicationContext ctxt = new ClassPathXmlApplicationContext( - configLocations); - EDEXUtil edexUtil = new EDEXUtil(); - edexUtil.setApplicationContext(ctxt); - } else { - log.fatal("Application spring config location not specified"); - log.info("Exiting."); - System.exit(0); - } - } - -} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOption.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOption.java deleted file mode 100644 index 76351cb6d0..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOption.java +++ /dev/null @@ -1,55 +0,0 @@ -/** 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 com.raytheon.edex.plugin.shef.alarms; - -/** - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * June 15, 2011    9377     jnjanga     Initial creation
- * 
- * 
- * 
- * - * @author jnjanga - * @version 1.0 - */ - -public class CmdlineOption { - - private CmdlineOptionId Id; - - private String argument; - - public CmdlineOption(CmdlineOptionId Id, String argument) { - this.Id = Id; - this.argument = argument; - } - - public CmdlineOptionId getId() { - return Id; - } - - public String getArg() { - return argument; - } -} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptionId.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptionId.java deleted file mode 100644 index 0f153a5d46..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptionId.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * 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 com.raytheon.edex.plugin.shef.alarms; - -/** - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * June 15, 2011    9377     jnjanga     Initial creation
- *  July 12, 2013   15711     wkwock      Fix verbose, observe mode, etc
- * 
- * 
- * - * @author jnjanga - * @version 1.0 - */ - -public enum CmdlineOptionId { - - DB_NAME("Database Name") { - - public String toString() { - return "d"; - } - - }, - - PRODUCT_ID("Product Id") { - - public String toString() { - return "p"; - } - - }, - - REPORT_MODE("Report mode") { - public String toString() { - return "r"; - } - - }, - - MINUTES("minutes") { - - public String toString() { - return "m"; - } - }, - - FILE_SUFFIX("File Suffix") { - public String toString() { - return "s"; - } - - }, - - FLAGS("Include Flags") { - public String toString() { - return "f"; - } - - }, - - PE("Physical Element") { - public String toString() { - return "e"; - } - - }, - - VERBOSE("Verbose") { - public String toString() { - return "v"; - } - }; - - CmdlineOptionId(String desc) { - this.desc = desc; - } - - public String description() { - return this.desc; - } - - private String desc; -} diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptions.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptions.java deleted file mode 100644 index 6a6a83d999..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/CmdlineOptions.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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 com.raytheon.edex.plugin.shef.alarms; - -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; - -/** - * Convenience wrapper around org.apache.commons.cli.Options - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * June 15, 2011    9377     jnjanga     Initial creation
- * 
- * 
- * 
- * - * @author jnjanga - * @version 1.0 - */ - -public class CmdlineOptions extends Options { - - private static final long serialVersionUID = 1L; - - CmdlineOptions() { - super(); - } - - public void addOption(CmdlineOptionId optId) { - Option opt = new Option(optId.toString(), true, optId.description()); - addOption(opt); - } - - public void addOption(CmdlineOptionId optId, boolean hasArg) { - Option opt = new Option(optId.toString(), hasArg, optId.description()); - addOption(opt); - } - - public void addMandatoryOption(CmdlineOptionId optId) { - Option opt = new Option(optId.toString(), true, optId.description()); - opt.setRequired(true); - addOption(opt); - } - - public boolean hasOption(CmdlineOptionId optId) { - return hasOption(optId.toString()); - } - -} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/RecordMgr.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/RecordMgr.java deleted file mode 100644 index 15650ae2a2..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/RecordMgr.java +++ /dev/null @@ -1,245 +0,0 @@ -/** - * 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 com.raytheon.edex.plugin.shef.alarms; - -import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALARM_CATEGSTR; -import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALERT_CATEGSTR; -import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.DIFF_CHECKSTR; -import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.LOWER_CHECKSTR; -import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ROC_CHECKSTR; -import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.UPPER_CHECKSTR; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.raytheon.uf.edex.database.dao.CoreDao; -import com.raytheon.uf.edex.database.dao.DaoConfig; - -/** - * Reads Alertalarmval table and creates an organized record. - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * June 15, 2011    9377     jnjanga     Initial creation
- * Sep  05, 2013    16549    wkwock      Fix the query
- * 
- * 
- * 
- * - * @author jnjanga - * @version 1.0 - */ - -class RecordMgr { - - static final int MODE = 101; - - static final int TYPE_SRC = 102; - - static final int AA_CAT = 103; - - static final int AA_CHCK = 104; - - static final int PEFILTER = 105; - - private static Log log = LogFactory - .getLog(RecordMgr.class); - - private static ReportOptions options = null; - - public static AlertalarmRecord getAlarmData(ReportOptions opt) { - options = opt; - StringBuilder query = new StringBuilder( - "select aav.lid, " - + "aav.pe, aav.dur, " - + "aav.ts, aav.extremum, " - + "aav.probability, aav.validtime, aav.basistime, " - + "aav.aa_categ, aav.aa_check, " - + "aav.value, aav.suppl_value, " - + "aav.shef_qual_code, aav.quality_code, aav.revision, " - + "aav.product_id, aav.producttime, aav.postingtime, aav.action_time, " - + "location.name from location, alertalarmval aav where location.lid = aav.lid"); - - // Build 'where' clause according to report mode - // if getting only unreported data, let the query filter out the - // reported data - query.append(whereSubClauseFor(MODE)) - .append(whereSubClauseFor(TYPE_SRC)) - .append(whereSubClauseFor(AA_CAT)) - .append(whereSubClauseFor(AA_CHCK)) - .append(whereSubClauseFor(PEFILTER)) - .append(" AND (aav.ts NOT LIKE 'F%' OR aav.validtime >= current_timestamp) ") - .append(" ORDER BY aav.lid ASC, aav.pe, aav.ts, aav.aa_check, aav.validtime DESC "); - - log.info("Query for getting alertalarmval data :" + query.toString()); - - Object[] aaData = null; - CoreDao dao = null; - AlertalarmRecord aaRecord = null; - - // Get the data - try { - dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); - aaData = dao.executeSQLQuery(query.toString()); - if (aaData != null && aaData.length > 0) { - aaRecord = AlertalarmRecord.newInstance(); - for (int i = 0; i < aaData.length; i++) { - Object[] aaRow = (Object[]) aaData[i]; - aaRecord.put(aaRow); - } - } - - } catch (Exception e) { - log.error("Query = [" + query + "]"); - log.error(" - PostgresSQL error retrieving from alertalarmval ", e); - System.exit(0); - } - - return aaRecord; - } - - private static String whereSubClauseFor(int userSelection) { - switch (userSelection) { - case MODE: - return modeSubClause(); - case TYPE_SRC: - return typeSrcSubClause(); - case AA_CAT: - return aaCatSubClause(); - case AA_CHCK: - return aaCheckSubClause(); - case PEFILTER: - return peFilterSubClause(); - default: - return null; - } - - } - - /** - * Adjust the query to any PE Filter - * - * @return - */ - private static String peFilterSubClause() { - String pe = options.getPEfilter(); - return pe == null ? "" : " AND pe = " + pe; - } - - private static String modeSubClause() { - if (options.getMode() == ReportMode.UNREPORTED) - return " AND action_time IS NULL "; - else - return " "; - } - - private static String typeSrcSubClause() { - String flags = options.getFilter(); - if(flags==null) - return " AND aav.ts like '%'"; - - if (flags.contains("O") && !flags.contains("F")) - return " AND (aav.ts like 'R%' or aav.ts like 'P%')"; - else if (!flags.contains("O") && flags.contains("F")) - return " AND (aav.ts like 'F%' or aav.ts like 'C%')"; - else - return " AND aav.ts like '%'"; - } - - /** - * append the where clause based on the alert/alarm category field - * - * @return - */ - private static String aaCatSubClause() { - String flags = options.getFilter(); - if(flags == null) - return " "; - - if (flags.contains("T") && !flags.contains("M")) - return " AND aav.aa_categ = " + ALERT_CATEGSTR; - else if (!flags.contains("T") && flags.contains("M")) - return " AND aav.aa_categ = " + ALARM_CATEGSTR; - else - return " "; - } - - /** - * append the where clause based on the alert/alarm check field - * - * @return - */ - private static String aaCheckSubClause() { - String subClause = " AND aa_check in ("; - String flags = options.getFilter(); - if(flags == null) - return " "; - - boolean rocFlag = flags.contains("R"); - boolean lowFlag = flags.contains("L"); - boolean upFlag = flags.contains("U"); - boolean diffFlag = flags.contains("D"); - - if (!rocFlag && !lowFlag && !upFlag && !diffFlag) - return " "; - else { - boolean init = true; - - char[] checks = { 'R', 'L', 'U', 'D' }; - for (char c : checks) { - switch (c) { - case 'U': - if (upFlag) - subClause - .concat(aaCheckSubClause(init, UPPER_CHECKSTR)); - break; - case 'L': - if (lowFlag) - subClause - .concat(aaCheckSubClause(init, LOWER_CHECKSTR)); - break; - case 'R': - if (rocFlag) - subClause.concat(aaCheckSubClause(init, ROC_CHECKSTR)); - break; - case 'D': - if (diffFlag) - subClause.concat(aaCheckSubClause(init, DIFF_CHECKSTR)); - break; - default: - break; - } - } - } - return subClause.concat(" ) "); - } - - private static String aaCheckSubClause(boolean initialEntry, String checkStr) { - if (initialEntry) { - initialEntry = !initialEntry; - return checkStr; - } else - return "," + checkStr; - } - -} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportOptions.java b/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportOptions.java deleted file mode 100644 index 5d9c454872..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportOptions.java +++ /dev/null @@ -1,267 +0,0 @@ -/** - * 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 com.raytheon.edex.plugin.shef.alarms; - -import java.util.ArrayList; - -import com.raytheon.uf.common.dataplugin.shef.util.ShefConstants; - -/** - * Place holder for user defined report options - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * June 15, 2011    9377     jnjanga     Initial creation
- * July 12, 2013   15711     wkwock      Fix verbose, observe mode, etc
- *  
- * 
- * - * @author jnjanga - * @version 1.0 - */ - -class ReportOptions { - - private String dbname=null; - - private String productId=null; - - private ReportMode mode=null; - - private String filter=null; - - private String PEfilter=null; - - private String fileSuffix=null; - - private float min_val_diff=0; - - private int minutes=0; - - private boolean minGiven=false; - - private boolean verboseFlag=false; - - ReportOptions() { - } - - public String getDbname() { - return dbname; - } - - public String getProductId() { - return productId; - } - - public void setProductId(String productId) { - int pidlength = productId.length(); - if (pidlength != 9 && pidlength != 10) { - final String msg = "Invalid length for Product_Id : " + pidlength; - throw new IllegalArgumentException(msg); - } - this.productId = productId; - } - - - public void setDbname(String dbname) { - if(!dbname.equals( System.getProperty("ih.db.name"))) { - final String msg = "Invalid database name : " + dbname; - throw new IllegalArgumentException(msg); - } - this.dbname = ShefConstants.IHFS; - } - - public int getMinutes() { - return minutes; - } - - public void setMinutes(String minutes) throws IllegalArgumentException { - boolean invalid = false; - int argl = minutes.length(); - int tmp = Integer.valueOf(minutes); - if (argl == 0 || argl > 6) { - invalid = true; - } else { - invalid = isWithinWindow(tmp); - } - - if (invalid) { - final String msg = getWindowOptionUsage(tmp); - throw new IllegalArgumentException(msg); - } - - this.minutes = tmp; - minGiven = true; - } - - public boolean isMinutesGiven() { - return minGiven; - } - - public ReportMode getMode() { - return mode; - } - - public void setMode(String mode) throws IllegalArgumentException { - try { - this.mode = ReportMode.valueOf(mode); - } catch (Exception e) { - final String msg = "Invalid report mode : " + mode + Constants.EOL - + "Report mode must be either : " - + printValid(ReportMode.values()); - throw new IllegalArgumentException(msg); - } - } - - public String getFilter() { - return filter; - } - - public void setFilter(String filter) throws IllegalArgumentException { - boolean invalid = false; - int fltrlen = filter.length(); - if (fltrlen == 0 || fltrlen > 8) - invalid = true; - else - invalid = !tokensValid(filter); - - if (invalid) { - final String msg = printFilterOptionUsage(filter); - throw new IllegalArgumentException(msg); - } - - this.filter = filter; - } - - public String getPEfilter() { - return PEfilter; - } - - public void setPEfilter(String pEfilter) throws IllegalArgumentException { - if (pEfilter.length() != 2) { - final String msg = "PE filter option must be two characters"; - throw new IllegalArgumentException(msg); - } - PEfilter = pEfilter; - } - - public String getFileSuffix() { - return fileSuffix; - } - - public void setFileSuffix(String fileSuffix) { - this.fileSuffix = fileSuffix; - } - - public float getMin_val_diff() { - return min_val_diff; - } - - public void setMin_val_diff(float min_val_diff) { - this.min_val_diff = min_val_diff; - } - - public boolean getVerbose () { - return verboseFlag ; - } - - public void setVerbose (boolean verboseFlg) { - verboseFlag = verboseFlg; - } - - public void addOption(CmdlineOption option) throws IllegalArgumentException { - String arg = (String) option.getArg(); - switch (option.getId()) { - case DB_NAME: - setDbname(arg); - break; - case PRODUCT_ID: - setProductId(arg); - break; - case REPORT_MODE: - setMode(arg); - break; - case FLAGS: - setFilter(arg); - break; - case PE: - setPEfilter(arg); - break; - case MINUTES: - setMinutes(arg); - break; - case FILE_SUFFIX: - setFileSuffix(arg); - break; - case VERBOSE: - setVerbose(true); - break; - default: - break; - } - } - - public String toString() { - StringBuilder str = new StringBuilder(); - - str.append("Product_Id = " + productId + Constants.EOL); - str.append("Report_Mode = " + mode.toString() + Constants.EOL); - str.append("Filter = " + filter + Constants.EOL); - str.append("PE Filter = " + PEfilter + Constants.EOL); - str.append("File suffix = " + fileSuffix + Constants.EOL); - str.append("minutes = " + minutes + Constants.EOL); - return str.toString(); - } - - private static String printValid(E[] array) { - StringBuilder str = new StringBuilder(); - for (E element : array) - str.append(element.toString() + ", "); - str.delete(str.length() - 2, str.length()); - return str.toString(); - } - - private boolean isWithinWindow(int min) { - return (min <= 0 || min > 999999); - } - - private String getWindowOptionUsage(int min) { - return "Invalid number of minutes : " + min - + " . Must be between 1 - 999999 "; - } - - private String printFilterOptionUsage(String filter) { - return "Invalid length or token for filter option : " + filter + Constants.EOL - + "Filter option must be either : " - + printValid(FilterOption.values()); - } - - private boolean tokensValid(String filter) { - ArrayList validArgs = FilterOption.asList(); - for (char c : filter.toCharArray()) - if (!validArgs.contains(c)) - return false; - return true; - } - -} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.ohd/utility/common_static/base/hydro/Apps_defaults b/edexOsgi/com.raytheon.uf.common.ohd/utility/common_static/base/hydro/Apps_defaults index 94dcef9616..d26831c84d 100644 --- a/edexOsgi/com.raytheon.uf.common.ohd/utility/common_static/base/hydro/Apps_defaults +++ b/edexOsgi/com.raytheon.uf.common.ohd/utility/common_static/base/hydro/Apps_defaults @@ -125,6 +125,7 @@ # #10/01/09 - Added 5 tokens for arcnav application. //only for arcnav for raxum application #10/03/12 - Added token section for script execution +#02/18/14 - Added section for run_report_alarm service configuration. # ============================================================================== @@ -179,6 +180,42 @@ MpeRUCFreezingLevel : ON MpeLightningSrv : ON #==================================================================================== +#===================== run_report_alarm Configuration =============================== +# These settings modify behavior of the EDEX RunReportAlarmSrv service, which +# replaced the original run_report_alarm script ported from A1 hydro. +# +## Mandatory Arguments: +## alarm_product_id : The product id that will be used to write the alarm +## report product into the textdb. +## +## Optional Arguments: +## alarm_file_suffix : A Java date/time format string that will be used as +## the alarm report's file extension when the product is +## written to disk. Product file path is +## ${whfs_product_dir}/PRODUCT_ID.FILE_SUFFIX. +## +## alarm_report_mode : Report mode. Valid values are one of the following: +## ALL, FRESH, RECENT, UNREPORTED, NEAREST, NEAR_NOW, +## LATEST_MAXFCST, or NEW_OR_INCREASED. +## +## alarm_filter : Additional filtering options for the product. +## Valid values can one or many of the following: +## 'O', 'F', 'T', 'M', 'R', 'L', 'U', 'D'. +## +## alarm_pe_filter : Physical element filter. +## +## alarm_minutes : For certain report modes, creates a window going back +## or forward the specified number of minutes. +## Valid values are 1 - 999999. +## +## alarm_verbose : Whether or not to create a "verbose mode" report. +## Valid values are TRUE or FALSE. +## + +alarm_product_id : CCCACRXXX +alarm_file_suffix : MMdd.HHmm +alarm_report_mode : NEAREST + # ============================================================================== # Executable directory tokens. diff --git a/edexOsgi/com.raytheon.uf.edex.ohd/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.ohd/META-INF/MANIFEST.MF index 1127f38294..b67a8d0cc9 100644 --- a/edexOsgi/com.raytheon.uf.edex.ohd/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.ohd/META-INF/MANIFEST.MF @@ -8,7 +8,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Import-Package: com.raytheon.edex.util, com.raytheon.uf.common.dataplugin.binlightning, com.raytheon.uf.common.dataplugin.grid, - com.raytheon.uf.common.dataplugin.shef.util, com.raytheon.uf.common.localization, com.raytheon.uf.common.ohd, com.raytheon.uf.common.serialization.comm, @@ -21,6 +20,7 @@ Import-Package: com.raytheon.edex.util, org.apache.commons.logging, org.quartz Export-Package: com.raytheon.uf.edex.ohd, + com.raytheon.uf.edex.ohd.reportalarm, com.raytheon.uf.edex.ohd.whfs Require-Bundle: com.raytheon.edex.common, com.raytheon.uf.common.mpe;bundle-version="1.11.15", @@ -29,4 +29,8 @@ Require-Bundle: com.raytheon.edex.common, com.raytheon.uf.common.status;bundle-version="1.12.1174", com.raytheon.uf.common.monitor, com.raytheon.uf.common.parameter;bundle-version="1.0.0", - com.raytheon.uf.common.units;bundle-version="1.0.0" + com.raytheon.uf.common.units;bundle-version="1.0.0", + com.raytheon.uf.common.dataplugin.shef, + com.raytheon.uf.common.dataplugin.text, + com.raytheon.edex.textdb, + com.raytheon.uf.edex.decodertools diff --git a/edexOsgi/com.raytheon.uf.edex.ohd/res/spring/alarmWhfs-spring.xml b/edexOsgi/com.raytheon.uf.edex.ohd/res/spring/alarmWhfs-spring.xml index daaf49e842..dff0d79727 100644 --- a/edexOsgi/com.raytheon.uf.edex.ohd/res/spring/alarmWhfs-spring.xml +++ b/edexOsgi/com.raytheon.uf.edex.ohd/res/spring/alarmWhfs-spring.xml @@ -8,6 +8,8 @@ run_alarm_whfs + + - - - - java.lang.Throwable - - - + + + + + java.lang.Throwable + + + + + + + + java.lang.Throwable + + + + diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmRecord.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/AlertalarmRecord.java similarity index 99% rename from edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmRecord.java rename to edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/AlertalarmRecord.java index 5c68e8ecb6..4a33db9381 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/AlertalarmRecord.java +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/AlertalarmRecord.java @@ -17,7 +17,7 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.edex.plugin.shef.alarms; +package com.raytheon.uf.edex.ohd.reportalarm; import java.text.DateFormat; diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/Constants.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/Constants.java similarity index 64% rename from edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/Constants.java rename to edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/Constants.java index c09f29263a..f26a90531c 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/Constants.java +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/Constants.java @@ -17,36 +17,52 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.edex.plugin.shef.alarms; +package com.raytheon.uf.edex.ohd.reportalarm; import java.text.SimpleDateFormat; import com.raytheon.uf.common.dataplugin.shef.util.ShefConstants; - +/** + * Constants needed by the run_report_alarm process. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 13, 2014  #2378     dgilling     Removed unused constants.
+ * 
+ * 
+ * + * @author xxxxxxxx + * @version 1.0 + */ class Constants { - + public static final SimpleDateFormat REPORT_TIME_PATTERN = new SimpleDateFormat( - "HH:mm:ss z, yyyy.MM.dd "); + "HH:mm:ss z, yyyy.MM.dd "); public static final int MISSING_VALUE_INT = ShefConstants.SHEF_MISSING_INT; - + public static final double MISSING_VALUE_DOUBLE = -9999999.87654321; public static final String NEWLINE = System.getProperty("line.separator"); - + public final static String EOL = NEWLINE; public static final String SPACE = " "; - - public static final String REPORT_ALARM_LOG = "report_alarm.log"; - + public static final String WHFS_PRODUCT_DIR = "whfs_product_dir"; - - public static final String WHFS_UTIL_LOG_DIR = "whfs_util_log_dir"; - - public static final String IHFS_CONFIG = "/res/spring/ohd-common.xml"; - - public static final String FXA_CONFIG = "/res/spring/alertalarm.xml"; - + + /** + * A private constructor so that Java does not attempt to create one for us. + * As this class should not be instantiated, do not attempt to ever call + * this constructor; it will simply throw an AssertionError. + * + */ + private Constants() { + throw new AssertionError(); + } } \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/FilterOption.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/FilterOption.java similarity index 69% rename from edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/FilterOption.java rename to edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/FilterOption.java index e1d5677fcb..65f4140786 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/FilterOption.java +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/FilterOption.java @@ -17,9 +17,10 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.edex.plugin.shef.alarms; +package com.raytheon.uf.edex.ohd.reportalarm; import java.util.ArrayList; +import java.util.List; /** * @@ -28,7 +29,8 @@ import java.util.ArrayList; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * June 15, 2011 9377 jnjanga Initial creation + * Jun 15, 2011 9377 jnjanga Initial creation + * Feb 13, 2014 #2783 dgilling Added fromArg() method. * * * @@ -48,6 +50,7 @@ public enum FilterOption { this.arg = arg; } + @Override public String toString() { return Character.toString(arg); } @@ -56,10 +59,22 @@ public enum FilterOption { return arg; } - public static ArrayList asList() { - ArrayList vals = new ArrayList(); - for (FilterOption opt : values()) + public static List asList() { + List vals = new ArrayList(); + for (FilterOption opt : values()) { vals.add(opt.getArg()); + } return vals; } + + public static FilterOption fromArg(char arg) { + for (FilterOption filter : values()) { + if (arg == filter.arg) { + return filter; + } + } + + throw new IllegalArgumentException(arg + + " is not a valid FilterOption."); + } } \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RecordMgr.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RecordMgr.java new file mode 100644 index 0000000000..1fce5e6f92 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RecordMgr.java @@ -0,0 +1,244 @@ +/** + * 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 com.raytheon.uf.edex.ohd.reportalarm; + +import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALARM_CATEGSTR; +import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALERT_CATEGSTR; +import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.DIFF_CHECKSTR; +import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.LOWER_CHECKSTR; +import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ROC_CHECKSTR; +import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.UPPER_CHECKSTR; + +import java.util.EnumSet; + +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.edex.database.dao.CoreDao; +import com.raytheon.uf.edex.database.dao.DaoConfig; + +/** + * Reads Alertalarmval table and creates an organized record. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jun 15, 2011  9377      jnjanga      Initial creation
+ * Sep 05, 2013  16549     wkwock       Fix the query
+ * Feb 13, 2014  #2783     dgilling     Refactored to support running as part
+ *                                      of an EDEX service.
+ * 
+ * 
+ * 
+ * + * @author jnjanga + * @version 1.0 + */ + +class RecordMgr { + + static final int MODE = 101; + + static final int TYPE_SRC = 102; + + static final int AA_CAT = 103; + + static final int AA_CHCK = 104; + + static final int PEFILTER = 105; + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(RecordMgr.class); + + /** + * A private constructor so that Java does not attempt to create one for us. + * As this class should not be instantiated, do not attempt to ever call + * this constructor; it will simply throw an AssertionError. + * + */ + private RecordMgr() { + throw new AssertionError(); + } + + public static AlertalarmRecord getAlarmData(ReportOptions opt) { + StringBuilder query = new StringBuilder("select aav.lid, ") + .append("aav.pe, aav.dur, ") + .append("aav.ts, aav.extremum, ") + .append("aav.probability, aav.validtime, aav.basistime, ") + .append("aav.aa_categ, aav.aa_check, ") + .append("aav.value, aav.suppl_value, ") + .append("aav.shef_qual_code, aav.quality_code, aav.revision, ") + .append("aav.product_id, aav.producttime, aav.postingtime, aav.action_time, ") + .append("location.name from location, alertalarmval aav where location.lid = aav.lid"); + + // Build 'where' clause according to report mode + // if getting only unreported data, let the query filter out the + // reported data + query.append(whereSubClauseFor(MODE, opt)) + .append(whereSubClauseFor(TYPE_SRC, opt)) + .append(whereSubClauseFor(AA_CAT, opt)) + .append(whereSubClauseFor(AA_CHCK, opt)) + .append(whereSubClauseFor(PEFILTER, opt)) + .append(" AND (aav.ts NOT LIKE 'F%' OR aav.validtime >= current_timestamp) ") + .append(" ORDER BY aav.lid ASC, aav.pe, aav.ts, aav.aa_check, aav.validtime DESC "); + + statusHandler.info("Query for getting alertalarmval data :" + + query.toString()); + + // Get the data + AlertalarmRecord aaRecord = null; + CoreDao dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); + Object[] aaData = dao.executeSQLQuery(query.toString()); + if (aaData != null && aaData.length > 0) { + aaRecord = AlertalarmRecord.newInstance(); + for (int i = 0; i < aaData.length; i++) { + Object[] aaRow = (Object[]) aaData[i]; + aaRecord.put(aaRow); + } + } + + return aaRecord; + } + + private static String whereSubClauseFor(int userSelection, + ReportOptions options) { + switch (userSelection) { + case MODE: + return modeSubClause(options.getMode()); + case TYPE_SRC: + return typeSrcSubClause(options.getFilter()); + case AA_CAT: + return aaCatSubClause(options.getFilter()); + case AA_CHCK: + return aaCheckSubClause(options.getFilter()); + case PEFILTER: + return peFilterSubClause(options.getPEfilter()); + default: + return null; + } + + } + + /** + * Adjust the query to any PE Filter + * + * @return + */ + private static String peFilterSubClause(String pe) { + return pe == null ? "" : " AND pe = " + pe; + } + + private static String modeSubClause(ReportMode mode) { + if (mode == ReportMode.UNREPORTED) { + return " AND action_time IS NULL "; + } else { + return " "; + } + } + + private static String typeSrcSubClause(EnumSet flags) { + if (flags == null) { + return " AND aav.ts like '%'"; + } + + if (flags.contains(FilterOption.OBSERVED) + && !flags.contains(FilterOption.FORECAST)) { + return " AND (aav.ts like 'R%' or aav.ts like 'P%')"; + } else if (!flags.contains(FilterOption.OBSERVED) + && flags.contains(FilterOption.FORECAST)) { + return " AND (aav.ts like 'F%' or aav.ts like 'C%')"; + } else { + return " AND aav.ts like '%'"; + } + } + + /** + * append the where clause based on the alert/alarm category field + * + * @return + */ + private static String aaCatSubClause(EnumSet flags) { + if (flags == null) { + return " "; + } + + if (flags.contains(FilterOption.ALERTS) + && !flags.contains(FilterOption.ALARMS)) { + return " AND aav.aa_categ = " + ALERT_CATEGSTR; + } else if (!flags.contains(FilterOption.ALERTS) + && flags.contains(FilterOption.ALARMS)) { + return " AND aav.aa_categ = " + ALARM_CATEGSTR; + } else { + return " "; + } + } + + /** + * append the where clause based on the alert/alarm check field + * + * @return + */ + private static String aaCheckSubClause(EnumSet flags) { + String subClause = " AND aa_check in ("; + if (flags == null) { + return " "; + } + + boolean rocFlag = flags.contains(FilterOption.RATE_OF_CHANGE); + boolean lowFlag = flags.contains(FilterOption.LOWER_LIMIT); + boolean upFlag = flags.contains(FilterOption.UPPER_LIMIT); + boolean diffFlag = flags.contains(FilterOption.DIFF_LIMIT); + + if (!rocFlag && !lowFlag && !upFlag && !diffFlag) { + return " "; + } else { + boolean init = true; + + if (rocFlag) { + subClause.concat(aaCheckSubClause(init, ROC_CHECKSTR)); + } + + if (lowFlag) { + subClause.concat(aaCheckSubClause(init, LOWER_CHECKSTR)); + } + + if (upFlag) { + subClause.concat(aaCheckSubClause(init, UPPER_CHECKSTR)); + } + + if (diffFlag) { + subClause.concat(aaCheckSubClause(init, DIFF_CHECKSTR)); + } + } + + return subClause.concat(" ) "); + } + + private static String aaCheckSubClause(boolean initialEntry, String checkStr) { + if (initialEntry) { + initialEntry = !initialEntry; + return checkStr; + } else { + return "," + checkStr; + } + } + +} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportMode.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportMode.java similarity index 96% rename from edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportMode.java rename to edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportMode.java index e51d5a6cf0..5a7f14c260 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportMode.java +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportMode.java @@ -17,7 +17,7 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.edex.plugin.shef.alarms; +package com.raytheon.uf.edex.ohd.reportalarm; /** * diff --git a/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportOptions.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportOptions.java new file mode 100644 index 0000000000..5c968e5a6b --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportOptions.java @@ -0,0 +1,269 @@ +/** + * 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 com.raytheon.uf.edex.ohd.reportalarm; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.EnumSet; + +import com.raytheon.uf.common.ohd.AppsDefaults; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.common.util.StringUtil; + +/** + * Place holder for user defined report options + * + *
+ * 
+ * SOFTWARE HISTORY
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jun 15, 2011  9377      jnjanga      Initial creation
+ * Jul 12, 2013  15711     wkwock       Fix verbose, observe mode, etc
+ * Feb 12, 2014  #2783     dgilling     Major refactor, cleanup.
+ * 
+ * 
+ * + * @author jnjanga + * @version 1.0 + */ + +class ReportOptions { + + private static final String DB_NAME = "ihfs"; + + private static final String PRODUCT_ID_KEY = "alarm_product_id"; + + private static final String REPORT_MODE_KEY = "alarm_report_mode"; + + private static final String INCLUDE_FLAGS_KEY = "alarm_filter"; + + private static final String PHYSICAL_ELEMENT_KEY = "alarm_pe_filter"; + + private static final String FILE_SUFFIX_KEY = "alarm_file_suffix"; + + private static final String MINUTES_KEY = "alarm_minutes"; + + private static final String VERBOSE_MODE_KEY = "alarm_verbose"; + + private static final EnumSet IGNORE_MINS = EnumSet.of( + ReportMode.ALL, ReportMode.UNREPORTED, ReportMode.NEAREST, + ReportMode.LATEST_MAXFCST); + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(ReportOptions.class); + + private String productId; + + private ReportMode mode = null; + + private EnumSet filter = EnumSet.noneOf(FilterOption.class); + + private String PEfilter = null; + + private DateFormat fileSuffix = null; + + private Integer minutes = null; + + private boolean verboseFlag; + + /** + * @param appsDefaults + * @throws IllegalArgumentException + */ + public ReportOptions(final AppsDefaults appsDefaults) + throws IllegalArgumentException { + setProductId(appsDefaults.getToken(PRODUCT_ID_KEY)); + + if (appsDefaults.getTokens().contains(REPORT_MODE_KEY)) { + setMode(appsDefaults.getToken(REPORT_MODE_KEY)); + } + + if (appsDefaults.getTokens().contains(INCLUDE_FLAGS_KEY)) { + setFilter(appsDefaults.getToken(INCLUDE_FLAGS_KEY)); + } + + if (appsDefaults.getTokens().contains(PHYSICAL_ELEMENT_KEY)) { + setPEfilter(appsDefaults.getToken(PHYSICAL_ELEMENT_KEY)); + } + + if (appsDefaults.getTokens().contains(FILE_SUFFIX_KEY)) { + setFileSuffix(appsDefaults.getToken(FILE_SUFFIX_KEY)); + } + + if (appsDefaults.getTokens().contains(MINUTES_KEY)) { + setMinutes(appsDefaults.getInt(MINUTES_KEY, -1)); + } + + setVerbose(appsDefaults.getBoolean(VERBOSE_MODE_KEY, false)); + + if (isMinutesGiven() && IGNORE_MINS.contains(this.mode)) { + statusHandler.warn("Minutes value ignored for this report mode."); + } + } + + public String getProductId() { + return productId; + } + + private void setProductId(String productId) throws IllegalArgumentException { + int pidlength = (productId != null) ? productId.length() : 0; + if (pidlength != 9 && pidlength != 10) { + throw new IllegalArgumentException( + "Invalid length for Product_Id : " + pidlength); + } + this.productId = productId; + } + + public int getMinutes() { + return (minutes != null) ? minutes : 0; + } + + private void setMinutes(Integer minutes) throws IllegalArgumentException { + if (minutes != null && !isWithinWindow(minutes)) { + throw new IllegalArgumentException(getWindowOptionUsage(minutes)); + } + + this.minutes = minutes; + } + + public boolean isMinutesGiven() { + return (minutes != null); + } + + public ReportMode getMode() { + return mode; + } + + private void setMode(String mode) throws IllegalArgumentException { + try { + this.mode = ReportMode.valueOf(mode); + } catch (Exception e) { + final String msg = "Invalid report mode : " + mode + Constants.EOL + + "Report mode must be either : " + + printValid(ReportMode.values()); + throw new IllegalArgumentException(msg); + } + } + + public EnumSet getFilter() { + return filter; + } + + private void setFilter(String filter) throws IllegalArgumentException { + int fltrlen = filter.length(); + if (fltrlen == 0 || fltrlen > 8) { + throw new IllegalArgumentException( + "Invalid number of filter options specified. Filter string must be between 1 and 8 characters long."); + } + + this.filter = EnumSet.noneOf(FilterOption.class); + for (char flag : filter.toCharArray()) { + try { + this.filter.add(FilterOption.fromArg(flag)); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(printFilterOptionUsage(flag)); + } + } + } + + public String getPEfilter() { + return PEfilter; + } + + private void setPEfilter(String pEfilter) throws IllegalArgumentException { + if (pEfilter.length() != 2) { + throw new IllegalArgumentException( + "PE filter option must be two characters"); + } + this.PEfilter = pEfilter; + } + + public String getFileSuffix() { + String retVal = (fileSuffix != null) ? fileSuffix.format(TimeUtil + .newDate()) : ""; + return retVal; + } + + private void setFileSuffix(String fileSuffix) { + if (!StringUtil.isEmptyString(fileSuffix)) { + this.fileSuffix = new SimpleDateFormat(fileSuffix); + } + } + + public boolean getVerbose() { + return verboseFlag; + } + + private void setVerbose(boolean verboseFlg) { + this.verboseFlag = verboseFlg; + } + + public String getDbname() { + return DB_NAME; + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + str.append("Product_Id = ").append(productId).append(Constants.EOL); + str.append("Report_Mode = ").append(mode.toString()) + .append(Constants.EOL); + str.append("Filter = ").append(filter).append(Constants.EOL); + str.append("PE Filter = ").append(PEfilter).append(Constants.EOL); + str.append("File suffix = ").append(fileSuffix).append(Constants.EOL); + str.append("minutes = ").append(minutes).append(Constants.EOL); + return str.toString(); + } + + private static String printValid(E[] array) { + StringBuilder str = new StringBuilder(); + for (E element : array) { + str.append(element.toString() + ", "); + } + str.delete(str.length() - 2, str.length()); + return str.toString(); + } + + private boolean isWithinWindow(int min) { + return (min >= 0 && min <= 999999); + } + + private String getWindowOptionUsage(int min) { + return "Invalid number of minutes : " + min + + " . Must be between 1 - 999999 "; + } + + private String printFilterOptionUsage(char flag) { + return "Invalid token for filter option : " + flag + Constants.EOL + + "Filter option must be either : " + + printValid(FilterOption.values()); + } + + public String getFileName() { + String retVal = productId; + if (fileSuffix != null) { + retVal = retVal + '.' + getFileSuffix(); + } + return retVal; + } +} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportWriter.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportWriter.java similarity index 74% rename from edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportWriter.java rename to edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportWriter.java index 58b3d924c8..41539fa341 100644 --- a/edexOsgi/com.raytheon.edex.plugin.shef/src/com/raytheon/edex/plugin/shef/alarms/ReportWriter.java +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/ReportWriter.java @@ -17,27 +17,24 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.edex.plugin.shef.alarms; +package com.raytheon.uf.edex.ohd.reportalarm; import java.io.BufferedWriter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.lang.reflect.Method; -import java.text.ParseException; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.EnumSet; import java.util.List; import java.util.Set; import java.util.TreeSet; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import com.raytheon.uf.common.dataplugin.shef.tables.Alertalarmval; import com.raytheon.uf.common.dataplugin.shef.tables.Counties; import com.raytheon.uf.common.dataplugin.shef.tables.CountiesId; @@ -51,6 +48,10 @@ import com.raytheon.uf.common.dataplugin.shef.tables.State; import com.raytheon.uf.common.dataplugin.shef.tables.Timezone; import com.raytheon.uf.common.dataplugin.shef.tables.Wfo; import com.raytheon.uf.common.dataplugin.shef.util.ShefConstants; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.common.util.CollectionUtil; import com.raytheon.uf.edex.database.dao.CoreDao; import com.raytheon.uf.edex.database.dao.DaoConfig; @@ -61,9 +62,11 @@ import com.raytheon.uf.edex.database.dao.DaoConfig; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * June 15, 2011 9377 jnjanga Initial creation - * July 12, 2013 15711 wkwock Fix verbose, observe mode, etc - * Sep 05, 2013 16539 wkwock Fix RECENT, NEAR_NOW,FRESH,and NEW_OR_INCREASED modes + * Jun 15, 2011 9377 jnjanga Initial creation + * Jul 12, 2013 15711 wkwock Fix verbose, observe mode, etc + * Sep 05, 2013 16539 wkwock Fix RECENT, NEAR_NOW,FRESH,and NEW_OR_INCREASED modes + * Feb 13, 2014 #2783 dgilling Refactored to support running as part + * of an EDEX service. * * * @@ -72,10 +75,8 @@ import com.raytheon.uf.edex.database.dao.DaoConfig; */ class ReportWriter { - private static Log log = LogFactory - .getLog(ReportWriter.class); - - private File report; + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(ReportWriter.class); private StringBuilder reportData; @@ -92,56 +93,59 @@ class ReportWriter { /** * Constructor * - * @param report * @param opt * @param now */ - ReportWriter(File report, ReportOptions opt, Date now) { - this.report = report; + ReportWriter(ReportOptions opt, Date now) { this.reportData = new StringBuilder(); this.opt = opt; this.now = now; Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, opt.getMinutes()); endTime = cal.getTime(); - cal.add(Calendar.MINUTE, opt.getMinutes()*(-2)); + cal.add(Calendar.MINUTE, opt.getMinutes() * (-2)); startTime = cal.getTime(); - } - + public void generateReport(final AlertalarmRecord record) throws Exception { + writeHeader(); + writeBody(record); + if (opt.getVerbose()) { + writeVerboseTrailer(); + } else { + writeReportTrailer(); + } + } /** * Processes and writes the data by groups found in this record. * * @param record * - the Alertalarm record for this run + * @throws Exception */ - public void writeBody(AlertalarmRecord record) { - - if(record!=null) { - Set groups = record.getGroups(); + private void writeBody(AlertalarmRecord record) throws Exception { - log.debug(" ---Groups---"); - log.debug(groups.toString()); - log.debug(" ---Record begin---"); - log.debug(record.toString()); - log.debug(" ---Record end---"); - - for (String group : groups) { - List grpData = record.getGroupData(group); - writeGroup(grpData); - } + if (record != null) { + Set groups = record.getGroups(); + + statusHandler.debug(" ---Groups---"); + statusHandler.debug(groups.toString()); + statusHandler.debug(" ---Record begin---"); + statusHandler.debug(record.toString()); + statusHandler.debug(" ---Record end---"); + + for (String group : groups) { + List grpData = record.getGroupData(group); + writeGroup(grpData); + } } } /** - * Writes the report's header information - * - * @throws ParseException + * Writes the report's header information. */ - public void writeHeader() { - + private void writeHeader() { write("***REPORT OF ALERT/ALARM DATA FROM THE HYDROLOGIC DATABASE***"); writeNewline(); @@ -165,34 +169,44 @@ class ReportWriter { // note which class of data is being considered via the filter write("DATA FILTER: "); - if (opt.getFilter() == null) { + + EnumSet flags = opt.getFilter(); + if (CollectionUtil.isNullOrEmpty(flags)) { writeln("All alerts/alarms considered (i.e. no filter)."); } else { write("Only considering "); - if (opt.getFilter().contains("O") && !opt.getFilter().contains("F")) + if (flags.contains(FilterOption.OBSERVED) + && !flags.contains(FilterOption.FORECAST)) { write(FilterOption.OBSERVED.name().toLowerCase()); - else if (!opt.getFilter().contains("O") - && opt.getFilter().contains("F")) + } else if (!flags.contains(FilterOption.OBSERVED) + && flags.contains(FilterOption.FORECAST)) { write(FilterOption.FORECAST.name().toLowerCase()); + } - if (opt.getFilter().contains("R")) + if (flags.contains(FilterOption.RATE_OF_CHANGE)) { write(" " + FilterOption.RATE_OF_CHANGE.name().toLowerCase()); + } - if (opt.getFilter().contains("U")) + if (flags.contains(FilterOption.UPPER_LIMIT)) { write(" " + FilterOption.UPPER_LIMIT.name().toLowerCase()); - if (opt.getFilter().contains("L")) + } + if (flags.contains(FilterOption.LOWER_LIMIT)) { write(" " + FilterOption.LOWER_LIMIT.name().toLowerCase()); - if (opt.getFilter().contains("D")) + } + if (flags.contains(FilterOption.DIFF_LIMIT)) { write(" " + FilterOption.DIFF_LIMIT.name().toLowerCase()); + } - if (opt.getFilter().contains("T") && !opt.getFilter().contains("M")) + if (flags.contains(FilterOption.ALERTS) + && !flags.contains(FilterOption.ALARMS)) { write(" " + FilterOption.ALERTS.name().toLowerCase()); - else if (!opt.getFilter().contains("T") - && opt.getFilter().contains("M")) + } else if (!flags.contains(FilterOption.ALERTS) + && flags.contains(FilterOption.ALARMS)) { write(" " + FilterOption.ALARMS.name().toLowerCase()); - else + } else { write(" " + FilterOption.ALERTS.name().toLowerCase() + " and " + FilterOption.ALARMS.name().toLowerCase()); + } writeNewline(); } @@ -200,7 +214,7 @@ class ReportWriter { write("PE FILTER : "); if (opt.getPEfilter() == null) { writeln(" All Physical Elements are considered (i.e. no filter)."); - + } else { write(" Only considering "); writeln(opt.getPEfilter() + " physical element data"); @@ -209,35 +223,36 @@ class ReportWriter { if (opt.getMode() == ReportMode.RECENT || opt.getMode() == ReportMode.NEAR_NOW || opt.getMode() == ReportMode.FRESH - || opt.getMode() == ReportMode.NEW_OR_INCREASED) + || opt.getMode() == ReportMode.NEW_OR_INCREASED) { write("NUM MINUTES: " + opt.getMinutes()); + } writeNewline(); writeln("--------------------------------------------------------------------"); } - public void writeReportTrailer() { - /* if no alarms found, then write message */ - - if (alarmCount == 0) { - writeln("\nNO ALERT/ALARM DATA TO REPORT FOR GIVEN REQUEST.\n"); - } else { - String reportMode=opt.getMode().toString(); - if (reportMode.equals("")) { - writeln("\n"+alarmCount+" ALERT/ALARMS REPORTED."); - }else { - writeln("\n"+alarmCount+" ALERT/ALARMS REPORTED. ("+reportMode+" MODE)"); - } - } - - writeln ("\nEND OF REPORT"); - writeToDisk(); + private void writeReportTrailer() { + /* if no alarms found, then write message */ + + if (alarmCount == 0) { + writeln("\nNO ALERT/ALARM DATA TO REPORT FOR GIVEN REQUEST.\n"); + } else { + String reportMode = opt.getMode().toString(); + if (reportMode.equals("")) { + writeln("\n" + alarmCount + " ALERT/ALARMS REPORTED."); + } else { + writeln("\n" + alarmCount + " ALERT/ALARMS REPORTED. (" + + reportMode + " MODE)"); + } + } + + writeln("\nEND OF REPORT"); } /** * Writes the report's trailer information. */ - public void writeVerboseTrailer() { + private void writeVerboseTrailer() { if (alarmCount == 0) { writeNewline(); @@ -245,12 +260,13 @@ class ReportWriter { writeNewline(); writeNewline(); } else { - String reportMode=opt.getMode().toString(); - if (reportMode.equals("")) { - writeln("\n"+alarmCount+" ALERT/ALARMS REPORTED."); - }else { - writeln("\n"+alarmCount+" ALERT/ALARMS REPORTED. ("+reportMode+" MODE)"); - } + String reportMode = opt.getMode().toString(); + if (reportMode.equals("")) { + writeln("\n" + alarmCount + " ALERT/ALARMS REPORTED."); + } else { + writeln("\n" + alarmCount + " ALERT/ALARMS REPORTED. (" + + reportMode + " MODE)"); + } writeln("\n-------------------------------------------------------------------"); writeln("Limits: shown above are the alert threshold/alarm threshold."); writeln("Info grouped by location, physical element, type-source and check type."); @@ -319,16 +335,16 @@ class ReportWriter { writeNewline(); writeln("END OF REPORT"); - - writeToDisk(); } - /* + /** * Write the group data to the report * - * @param grpData - A list of Alertalarmval row data + * @param grpData + * - A list of Alertalarmval row data + * @throws Exception */ - private void writeGroup(List grpData) { + private void writeGroup(List grpData) throws Exception { if (hasDataToReport(grpData)) { /* write the alert-alarm group header */ writeGroupHeader(grpData); @@ -337,7 +353,7 @@ class ReportWriter { } } - /* + /** * Write info on the alert/alarm for the current group * * If report mode is: @@ -372,8 +388,9 @@ class ReportWriter { * updates alarmCount in the process * * @param groupData + * @throws Exception */ - private void writeGroupReport(List grpData) { + private void writeGroupReport(List grpData) throws Exception { Alertalarmval maxfcst = findMaxfcst(grpData); Alertalarmval latestReport = findLatestAction(grpData); @@ -389,8 +406,9 @@ class ReportWriter { */ char grpTs0 = grpData.get(0).getId().getTs().charAt(0); - if (grpTs0 != 'R' && grpTs0 != 'P') + if (grpTs0 != 'R' && grpTs0 != 'P') { Collections.reverse(grpData); + } /* * now loop on the data for this group and write the data records @@ -456,7 +474,7 @@ class ReportWriter { alarmCount++; } } - break; + break; case LATEST_MAXFCST: @@ -484,37 +502,38 @@ class ReportWriter { if ((grpTs0 == 'R' || grpTs0 == 'P')) { Date validtime = aav.getId().getValidtime(); Calendar cal = Calendar.getInstance(); - if (latestReport != null) - cal.setTime(latestReport.getId().getValidtime()); + if (latestReport != null) { + cal.setTime(latestReport.getId().getValidtime()); + } cal.add(Calendar.MINUTE, opt.getMinutes()); - if (latestReport==null || validtime.after(cal.getTime())) { + if (latestReport == null || validtime.after(cal.getTime())) { writeAAval(aav); updateDatabase(aav); alarmCount++; } } } - if (grpTs0 == 'F' || grpTs0 == 'C') { - if (maxfcst != null - && isNotNull(maxfcst.getActionTime().getTime())) { - if (maxfcst.getActionTime().before(startTime)) { - writeAAval(maxfcst); - updateDatabase(maxfcst); - alarmCount++; - } + if (grpTs0 == 'F' || grpTs0 == 'C') { + if (maxfcst != null + && isNotNull(maxfcst.getActionTime().getTime())) { + if (maxfcst.getActionTime().before(startTime)) { + writeAAval(maxfcst); + updateDatabase(maxfcst); + alarmCount++; } } + } break; case NEW_OR_INCREASED: - Calendar cal = Calendar.getInstance(); + Calendar cal = Calendar.getInstance(); for (Alertalarmval aav : grpData) { if (latestReport != null) { latestValue = latestReport.getValue(); cal.setTime(latestReport.getPostingtime()); } else { - cal.setTimeInMillis(0); + cal.setTimeInMillis(0); } if (isNull(aav.getActionTime().getTime())) { @@ -527,7 +546,7 @@ class ReportWriter { */ cal.add(Calendar.MINUTE, opt.getMinutes()); - if (posttime.after(cal.getTime()) + if (posttime.after(cal.getTime()) || (aav.getValue() > latestValue)) { writeAAval(aav); updateDatabase(aav); @@ -544,26 +563,28 @@ class ReportWriter { } - /* + /** * Checks whether this group(lid-pe-ts-aa_check) has any row data that * exceeds specified alert/alarm limits. The checks depends on the modes. * * @param grpData * * @return - True if at least one row data satisfies the alert/alarm - * situation. - false if none. + * situation. - false if none. */ private boolean hasDataToReport(List grpData) { - if (grpData == null || grpData.isEmpty()) + if (grpData == null || grpData.isEmpty()) { return false; + } // These following modes are guaranteed to // use at least one value from the retrieved data. if (opt.getMode() == ReportMode.ALL || opt.getMode() == ReportMode.UNREPORTED || opt.getMode() == ReportMode.NEAREST - || opt.getMode() == ReportMode.LATEST_MAXFCST) + || opt.getMode() == ReportMode.LATEST_MAXFCST) { return true; + } Alertalarmval latestReport = findLatestAction(grpData); Alertalarmval maxfcstVal = findMaxfcst(grpData); @@ -577,13 +598,16 @@ class ReportWriter { Date postingTime = aav.getPostingtime(); switch (opt.getMode()) { case NEAR_NOW: - if ((ts0 == 'F' || ts0 == 'C') && validTime.before(endTime)) + if ((ts0 == 'F' || ts0 == 'C') && validTime.before(endTime)) { return true; - if ((ts0 == 'R' || ts0 == 'P') && validTime.after(startTime)) + } + if ((ts0 == 'R' || ts0 == 'P') && validTime.after(startTime)) { return true; + } case RECENT: - if (postingTime.after(startTime)) + if (postingTime.after(startTime)) { return true; + } case FRESH: /* * get the latest action time reported, if there is one. for @@ -591,36 +615,39 @@ class ReportWriter { * forecast value */ - if ((ts0 == 'R' || ts0 == 'P') ) { - if (latestReport == null) - return true; - - Date validtime = aav.getId().getValidtime(); - Calendar cal = Calendar.getInstance(); - cal.setTime(latestReport.getId().getValidtime()); - cal.add(Calendar.MINUTE, opt.getMinutes()); - if (validtime.after(cal.getTime())) + if ((ts0 == 'R' || ts0 == 'P')) { + if (latestReport == null) { return true; + } + + Date validtime = aav.getId().getValidtime(); + Calendar cal = Calendar.getInstance(); + cal.setTime(latestReport.getId().getValidtime()); + cal.add(Calendar.MINUTE, opt.getMinutes()); + if (validtime.after(cal.getTime())) { + return true; + } } if (ts0 == 'F' || ts0 == 'C') { if (maxfcstVal != null && isNotNull(maxfcstVal.getActionTime().getTime())) { Date latestActiondate = maxfcstVal.getActionTime(); - if (latestActiondate.before(startTime)) + if (latestActiondate.before(startTime)) { return true; + } } } break; case NEW_OR_INCREASED: /* get the last reported record and its time and value. */ - Calendar cal = Calendar.getInstance(); + Calendar cal = Calendar.getInstance(); if (latestReport != null) { latestValue = latestReport.getValue(); cal.setTime(latestReport.getPostingtime()); } else { - cal.setTimeInMillis(0); + cal.setTimeInMillis(0); } if (isNull(aav.getActionTime().getTime())) { @@ -649,12 +676,13 @@ class ReportWriter { return false; } - /* + /** * write out to the report file this alertalarmval row data * * @param aav + * @throws Exception */ - private void writeAAval(Alertalarmval aav) { + private void writeAAval(Alertalarmval aav) throws Exception { String[] devb = buildString(aav); String durInfo = devb[0]; String exInfo = devb[1]; @@ -670,42 +698,45 @@ class ReportWriter { args.add(basisInfo); if (aav.getId().getAaCheck().equals(ShefConstants.UPPER_CHECKSTR)) { fmtSpecifier = " %s > %s %s %7.1f %s"; - } else if (aav.getId().getAaCheck().equals(ShefConstants.LOWER_CHECKSTR)) { + } else if (aav.getId().getAaCheck() + .equals(ShefConstants.LOWER_CHECKSTR)) { fmtSpecifier = " %s < %s %s %7.1f %s"; } else { fmtSpecifier = " %s > %s %s %7.1f (value = %7.1f) %s"; args.add(3, aav.getSupplValue()); } - - log.debug("fmt="+fmtSpecifier); - log.debug("args="+args.toString()); - + + statusHandler.debug("fmt=" + fmtSpecifier); + statusHandler.debug("args=" + args.toString()); + line = String.format(fmtSpecifier, args.toArray()); write(line); - if (durInfo.length() > 0 || exInfo.length() > 0) + if (durInfo.length() > 0 || exInfo.length() > 0) { writeln(durInfo + exInfo); - else + } else { writeNewline(); + } } - /* + /** * build a presentable string for duration, extremum code and convert valid * time to time_t format. * * @param aav + * @throws Exception */ - private String[] buildString(Alertalarmval aav) { + private String[] buildString(Alertalarmval aav) throws Exception { String[] devbStr = new String[4]; /* build a presentable string for the duration code value */ short dur = aav.getId().getDur(); if (dur != 0) { Object[] durData = getShefDurInfo(dur); - if (durData == null) + if (durData == null) { devbStr[0] = "Duration=" + dur; - else { - Object[] aDurData = (Object[]) durData[0] -; devbStr[0] = (String) aDurData[2] + Constants.SPACE; + } else { + Object[] aDurData = (Object[]) durData[0]; + devbStr[0] = (String) aDurData[2] + Constants.SPACE; } } else { @@ -716,10 +747,11 @@ class ReportWriter { String ex = aav.getId().getExtremum(); if (!ex.equals("Z")) { Object[] exData = getShefExInfo(ex); - if (exData == null) + if (exData == null) { devbStr[1] = "Extremum=" + ex; - else + } else { devbStr[1] = (String) exData[1] + Constants.SPACE; + } } else { devbStr[1] = Constants.SPACE; } @@ -728,8 +760,7 @@ class ReportWriter { * convert the valid time for use in the update statement and for * presenting the time in the output */ - devbStr[2] = ShefConstants.POSTGRES_DATE_FORMAT.format(aav.getId() - .getValidtime()); + devbStr[2] = TimeUtil.formatToSqlTimestamp(aav.getId().getValidtime()); /* * if forecast or contingency data, then show the basis time in a @@ -739,8 +770,8 @@ class ReportWriter { char ts0 = aav.getId().getTs().charAt(0); if (ts0 == 'F' || ts0 == 'C') { - String basisStr = ShefConstants.POSTGRES_DATE_FORMAT.format(aav - .getId().getBasistime()); + String basisStr = TimeUtil.formatToSqlTimestamp(aav.getId() + .getBasistime()); devbStr[3] = "fcast " + basisStr; } else { devbStr[3] = Constants.SPACE; @@ -749,14 +780,15 @@ class ReportWriter { return devbStr; } - /* + /** * Writes the group header information * * @param headerTokens * * @param grpData + * @throws Exception */ - private void writeGroupHeader(List grpData) { + private void writeGroupHeader(List grpData) throws Exception { // get the location info for this group String lid = grpData.get(0).getId().getLid(); Location loc = getLocationInfo(lid); @@ -770,84 +802,95 @@ class ReportWriter { // make a description of the type portion of the type-source field String typeInfo = null; String ts = grpData.get(0).getId().getTs(); - String ts1StChr = ts.substring(0,1).toUpperCase(); - if (ts1StChr.equals("C")) + String ts1StChr = ts.substring(0, 1).toUpperCase(); + if (ts1StChr.equals("C")) { typeInfo = "Contingengy"; - else if (ts1StChr.equals("F")) + } else if (ts1StChr.equals("F")) { typeInfo = "Forecast"; - else if (ts1StChr.equals("P")) + } else if (ts1StChr.equals("P")) { typeInfo = "Processed"; - else + } else { typeInfo = "Observed"; + } // write header lines to the file for this group writeNewline(); - write(loc.getName() + Constants.SPACE + "(" + loc.getLid() + ")" + Constants.SPACE - + loc.getCounties().getId().getCounty() + " County," + Constants.SPACE - + state.getName()); + write(loc.getName() + Constants.SPACE + "(" + loc.getLid() + ")" + + Constants.SPACE + loc.getCounties().getId().getCounty() + + " County," + Constants.SPACE + state.getName()); writeNewline(); writeNewline(); - write(peInfo + Constants.SPACE + typeInfo + Constants.SPACE + "(" + pe + Constants.SPACE + ts + ")"); + write(peInfo + Constants.SPACE + typeInfo + Constants.SPACE + "(" + pe + + Constants.SPACE + ts + ")"); writeNewline(); Datalimits limits = getDatalimits(grpData); if (limits != null) { StringBuilder lim = new StringBuilder("Limits: Upper limit Value="); - if (limits.getAlertUpperLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlertUpperLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlertUpperLimit())); - else + } else { lim.append("undef"); + } lim.append("/"); - if (limits.getAlarmUpperLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlarmUpperLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlarmUpperLimit())); - else + } else { lim.append("undef"); + } lim.append(" Lower limit Value="); - if (limits.getAlertLowerLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlertLowerLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlertLowerLimit())); - else + } else { lim.append("undef"); + } lim.append("/"); - if (limits.getAlarmLowerLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlarmLowerLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlarmLowerLimit())); - else + } else { lim.append("undef"); + } lim.append(" Diff limit Value="); - if (limits.getAlertDiffLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlertDiffLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlertDiffLimit())); - else + } else { lim.append("undef"); + } lim.append("/"); - if (limits.getAlarmDiffLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlarmDiffLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlarmDiffLimit())); - else + } else { lim.append("undef"); + } lim.append(" ROC="); - if (limits.getAlertRocLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlertRocLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlertRocLimit())); - else + } else { lim.append("undef"); + } lim.append("/"); - if (limits.getAlarmRocLimit() != Constants.MISSING_VALUE_DOUBLE) + if (limits.getAlarmRocLimit() != Constants.MISSING_VALUE_DOUBLE) { lim.append(String.format("%.1f", limits.getAlarmRocLimit())); - else + } else { lim.append("undef"); + } - if (opt.getVerbose()){ - writeln(lim.toString()); + if (opt.getVerbose()) { + writeln(lim.toString()); } } else { - log.info("No data limits found in Database while writing alert/alarm group report!"); + statusHandler + .info("No data limits found in Database while writing alert/alarm group report!"); writeln("Alert/Alarm limits not available."); } } - /* + /** * Find the most recent record which was reported already. The record with * the most recent action time is is returned. * @@ -859,8 +902,9 @@ class ReportWriter { TreeSet actions = new TreeSet( new ActiontimeComparator()); for (Alertalarmval aav : grpData) { - if (isNotNull(aav.getActionTime().getTime())) + if (isNotNull(aav.getActionTime().getTime())) { actions.add(aav); + } } return actions.isEmpty() ? null : actions.first(); } @@ -883,7 +927,7 @@ class ReportWriter { } } - /* + /** * Find the record in the forecast combination group with the maximum value. * This function should not return with a null pointer; i.e. if there are * data, there should always be a maximum value. This function is used for @@ -894,8 +938,9 @@ class ReportWriter { * @return */ private Alertalarmval findMaxfcst(List grpData) { - if (grpData == null || grpData.isEmpty()) + if (grpData == null || grpData.isEmpty()) { return null; + } Alertalarmval maxfsct = grpData.get(0); TreeSet fcstvalues = new TreeSet( @@ -903,30 +948,31 @@ class ReportWriter { /* only process the data if it is forecast type data */ char ts0 = maxfsct.getId().getTs().charAt(0); if (ts0 == 'F' || ts0 == 'C') { - for (Alertalarmval aav : grpData) - if (isNotNull(aav.getValue())) + for (Alertalarmval aav : grpData) { + if (isNotNull(aav.getValue())) { fcstvalues.add(aav); + } + } maxfsct = fcstvalues.first(); } return fcstvalues.isEmpty() ? null : fcstvalues.first(); } - /* + /** * Update the action time to now. Note that because certain report modes * include data that has already been reported, it is possible that the * action_time is not null; in this case, the action_time field will show * the last time the record was reported. + * + * @throws Exception */ - private void updateDatabase(Alertalarmval aav) { - - String nowAnsi = ShefConstants.POSTGRES_DATE_FORMAT.format(now); - String validAnsi = ShefConstants.POSTGRES_DATE_FORMAT.format(aav.getId().getValidtime()); - String basisAnsi = ShefConstants.POSTGRES_DATE_FORMAT.format(aav.getId().getBasistime()); - /*Timestamp nowAnsi = new Timestamp(now.getTime()); - Timestamp validAnsi = new Timestamp(aav.getId().getValidtime() - .getTime()); - Timestamp basisAnsi = new Timestamp(aav.getId().getBasistime() - .getTime());*/ + private void updateDatabase(Alertalarmval aav) throws Exception { + String nowAnsi = TimeUtil.formatToSqlTimestamp(now); + String validAnsi = TimeUtil.formatToSqlTimestamp(aav.getId() + .getValidtime()); + String basisAnsi = TimeUtil.formatToSqlTimestamp(aav.getId() + .getBasistime()); + StringBuilder query = new StringBuilder(); query.append(" UPDATE alertalarmval SET action_time ='"); query.append(nowAnsi + "' "); @@ -935,30 +981,33 @@ class ReportWriter { query.append("AND dur=" + aav.getId().getDur() + Constants.SPACE); query.append("AND ts='" + aav.getId().getTs() + "' "); query.append("AND extremum='" + aav.getId().getExtremum() + "' "); - query.append("AND probability=" + aav.getId().getProbability() + Constants.SPACE); + query.append("AND probability=" + aav.getId().getProbability() + + Constants.SPACE); query.append("AND validtime='" + validAnsi + "' "); query.append("AND basistime='" + basisAnsi + "' "); query.append("AND aa_categ='" + aav.getId().getAaCateg() + "' "); query.append("AND aa_check='" + aav.getId().getAaCheck() + "' "); - try{ - CoreDao dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); - dao.executeSQLUpdate(query.toString()); - - } catch(Exception e) { - log.error("Error updating alertalarmval table"); - log.error("Query = [" + query + "]",e); - System.exit(0); + try { + CoreDao dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); + dao.executeSQLUpdate(query.toString()); + + } catch (Exception e) { + statusHandler.error("Error updating alertalarmval table"); + statusHandler.error("Query = [" + query + "]"); + throw e; } } - /* + /** * Query the database and obtain the data limits for this group. * * @param grpData * * @return + * @throws Exception */ - private Datalimits getDatalimits(List grpData) { + private Datalimits getDatalimits(List grpData) + throws Exception { Object[] limData = null; Object[] limRow = null; CoreDao dao = null; @@ -971,7 +1020,7 @@ class ReportWriter { Short dur = grpData.get(0).getId().getDur(); Date validtime = grpData.get(0).getId().getValidtime(); - String query = "SELECT * FROM locdatalimits WHERE lid='" + lid + String query = "SELECT * FROM locdatalimits WHERE lid='" + lid + "' AND pe='" + pe + "' AND dur=" + dur; try { @@ -1017,17 +1066,17 @@ class ReportWriter { } } catch (Exception e) { - log.error("- PostgresSQL error executing Query = [" + query + "]", - e); - System.exit(0); + statusHandler.error("- PostgresSQL error executing Query = [" + + query + "]"); + throw e; } return limits; } - /* - * copy only the thresholds themselves into the returned record. - * check for nulls always + /** + * copy only the thresholds themselves into the returned record. check for + * nulls always */ private void copyThresholds(Datalimits limits, Object[] limitsRow, boolean locRangeFound) { @@ -1045,13 +1094,14 @@ class ReportWriter { Double alarmll; Double alertdl; Double alarmdl; - - //traverse the limitsRow and substitute all nulls with - //the default nullDouble value - for(int i=0;i cls = Class + .forName("com.raytheon.uf.common.dataplugin.shef.tables.Datalimits"); + Method methodlist[] = cls.getDeclaredMethods(); + for (Method method : methodlist) { + if ((method.getName().startsWith("set") && !method.getName() + .contains("Id")) + && (method.getName().contains("Max") + || method.getName().contains("Min") || method + .getName().contains("Limit"))) { + method.invoke(limits, Constants.MISSING_VALUE_DOUBLE); + } + } + } catch (Exception e) { + statusHandler.error("Failed to flush Datalimits object."); + throw e; + } + } + public static double getNullDouble() { return -Double.MAX_VALUE; } @@ -1158,7 +1222,7 @@ class ReportWriter { return Long.MIN_VALUE; } - public static boolean isNull(double value) { + public static boolean isNull(double value) { boolean result = false; if (value == getNullDouble()) { @@ -1170,7 +1234,7 @@ class ReportWriter { public static boolean isNull(long value) { boolean result = false; - if (value == getNullLong() || value==0) { + if (value == getNullLong() || value == 0) { result = true; } @@ -1185,7 +1249,7 @@ class ReportWriter { return !isNull(value); } - /* + /** * Check that the observation date is within the window limits found in the * db * @@ -1217,28 +1281,32 @@ class ReportWriter { return reportData.toString(); } - /* + /** * Query the location table and obtain a location rset for this location Id * - * @param lid - the location Id + * @param lid + * - the location Id * * @return - a location row + * @throws Exception */ - private Location getLocationInfo(String lid) { + private Location getLocationInfo(String lid) throws Exception { Object[] locData = null; CoreDao dao = null; Object[] locInfo = null; - final String query = "SELECT * FROM location WHERE lid='" + lid+"'"; + final String query = "SELECT * FROM location WHERE lid='" + lid + "'"; try { dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); locData = dao.executeSQLQuery(query); - if (locData != null && locData.length > 0) + if (locData != null && locData.length > 0) { locInfo = (Object[]) locData[0]; + } } catch (Exception e) { - log.info("Query = [" + query + "]"); - log.error(" - PostgresSQL error retrieving location info for " - + lid, e); - System.exit(0); + statusHandler + .error(" - PostgresSQL error retrieving location info for " + + lid); + statusHandler.error("Query = [" + query + "]"); + throw e; } Location loc = new Location(); @@ -1282,14 +1350,16 @@ class ReportWriter { return loc; } - /* + /** * Query the shefex table and obtain shefex rset for the given duration * - * @param ex - the extremum + * @param ex + * - the extremum * * @return - a shefex row + * @throws Exception */ - private Object[] getShefExInfo(String ex) { + private Object[] getShefExInfo(String ex) throws Exception { Object[] exData = null; CoreDao dao = null; final String query = "SELECT * FROM shefex WHERE extremum='" + ex + "'"; @@ -1297,24 +1367,26 @@ class ReportWriter { dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); exData = dao.executeSQLQuery(query); } catch (Exception e) { - log.info("Query = [" + query + "]"); - log.error( - " - PostgresSQL error retrieving Shefex info for extremum" - + ex, e); - System.exit(0); + statusHandler + .error(" - PostgresSQL error retrieving Shefex info for extremum" + + ex); + statusHandler.error("Query = [" + query + "]"); + throw e; } return exData; } - /* + /** * Query the shefdur table and obtain shefdur rset for the given duration * - * @param ex - the duration + * @param ex + * - the duration * * @return - a shefdur row + * @throws Exception */ - private Object[] getShefDurInfo(short dur) { + private Object[] getShefDurInfo(short dur) throws Exception { Object[] durData = null; CoreDao dao = null; final String query = "SELECT * FROM shefdur WHERE dur=" + dur; @@ -1322,25 +1394,27 @@ class ReportWriter { dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); durData = dao.executeSQLQuery(query); } catch (Exception e) { - log.info("Query = [" + query + "]"); - log.error( - " - PostgresSQL error retrieving ShefDur info for duration" - + dur, e); - System.exit(0); + statusHandler + .error(" - PostgresSQL error retrieving ShefDur info for duration" + + dur); + statusHandler.error("Query = [" + query + "]"); + throw e; } return durData; } - /* + /** * Query the shefpe table and obtain shefpe rset for the given physical * element * - * @param pe - the physical element + * @param pe + * - the physical element * * @return - a shefpe row + * @throws Exception */ - private String getShefPeInfo(String pe) { + private String getShefPeInfo(String pe) throws Exception { Object[] peData = null; CoreDao dao = null; Object[] peInfo = null; @@ -1348,45 +1422,51 @@ class ReportWriter { try { dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); peData = dao.executeSQLQuery(query); - if (peData != null && peData.length > 0) + if (peData != null && peData.length > 0) { peInfo = (Object[]) peData[0]; + } } catch (Exception e) { - log.info("Query = [" + query + "]"); - log.error( - " - PostgresSQL error retrieving physical element info for " - + pe, e); - System.exit(0); + statusHandler + .error(" - PostgresSQL error retrieving physical element info for " + + pe); + statusHandler.error("Query = [" + query + "]"); + throw e; } - if (peInfo == null) + if (peInfo == null) { return "UndefinedName"; + } return (String) peInfo[1]; } - /* + /** * Query the * * @param state * * @return + * @throws Exception */ - private State getStateInfo(String state) { + private State getStateInfo(String state) throws Exception { Object[] stateData = null; CoreDao dao = null; Object[] stateInfo = null; - final String query = "SELECT * FROM state WHERE state='"+ state + "'"; + final String query = "SELECT * FROM state WHERE state='" + state + "'"; try { dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname())); stateData = dao.executeSQLQuery(query); - if (stateData != null && stateData.length > 0) + if (stateData != null && stateData.length > 0) { stateInfo = (Object[]) stateData[0]; + } } catch (Exception e) { - log.info("Query = [" + query + "]"); - log.error(" - PostgresSQL error retrieving state info info for " - + state, e); - System.exit(0); + statusHandler + .error(" - PostgresSQL error retrieving state info info for " + + state); + statusHandler.error("Query = [" + query + "]"); + throw e; } + State s = new State(); s.setState((String) stateInfo[0]); s.setName((String) stateInfo[1]); @@ -1399,72 +1479,52 @@ class ReportWriter { public int getAlarmCount() { return alarmCount; } - + /** - * @return - the report complete filename - */ - public String getFilename() { - return report.getAbsolutePath(); - } - - /* * does not perform disk access - * @param str - + * + * @param str + * - */ private void write(String str) { - reportData.append(str); + reportData.append(str); } - /* - * writes a line and positions the file - * cursor after the new line separator. + /** + * writes a line and positions the file cursor after the new line separator. * - * @param str - a line to write to the file + * @param str + * - a line to write to the file */ private void writeln(String str) { - reportData.append(str); - reportData.append(Constants.NEWLINE); + reportData.append(str); + writeNewline(); } /* * write a line separator */ private void writeNewline() { - reportData.append(Constants.NEWLINE); + reportData.append(Constants.NEWLINE); } - - /* - * writes the report to disk + /** + * Writes the report to disk. + * + * @param report + * The file to write the report to. */ - private void writeToDisk(){ - String filename = report.getAbsolutePath(); - BufferedWriter bufferedWriter = null; + public void writeToDisk(final File report) throws IOException { + Writer outWriter = null; try { - bufferedWriter = new BufferedWriter(new FileWriter(filename)); - bufferedWriter.append(Constants.EOL); - //bufferedWriter.newLine(); - bufferedWriter.append(reportData.toString()); - } catch (FileNotFoundException fnfe) { - log.error("Could not find file "+ filename, fnfe); - System.exit(0); - } catch (IOException e) { - log.error("Exception occured ",e); - System.exit(0); + outWriter = new BufferedWriter(new FileWriter(report)); + outWriter.write(Constants.EOL); + outWriter.write(reportData.toString()); } finally { - try { - if (bufferedWriter != null) { - bufferedWriter.flush(); - bufferedWriter.close(); - } - } catch (IOException e) { - log.error("Exception occured ",e); - System.exit(0); + if (outWriter != null) { + outWriter.close(); } - } } - - } \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RunReportAlarmSrv.java b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RunReportAlarmSrv.java new file mode 100644 index 0000000000..0eb6ad519f --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.ohd/src/com/raytheon/uf/edex/ohd/reportalarm/RunReportAlarmSrv.java @@ -0,0 +1,159 @@ +/** + * 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 com.raytheon.uf.edex.ohd.reportalarm; + +import java.io.File; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; + +import com.raytheon.edex.textdb.dbapi.impl.TextDB; +import com.raytheon.uf.common.ohd.AppsDefaults; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.common.util.FileUtil; + +/** + * Provides SHEF with the ability to generate alert/alarms report products and + * write them to the text database. + *

+ * Based on AlertalarmStdTextProductUtil.java originally written by jnjanga. + * + *

+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 12, 2014  #2783     dgilling     Initial creation
+ * 
+ * 
+ * + * @author dgilling + * @version 1.0 + */ + +public final class RunReportAlarmSrv { + + private static final DateFormat START_END_TIME_FORMAT = new SimpleDateFormat( + "EEE MMM dd HH:mm:ss z yyyy"); + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(RunReportAlarmSrv.class); + + private RunReportAlarmSrv() { + // no-op + } + + public static void executeRunReportAlarm() { + statusHandler.info("------------------------------ "); + String currentTime = START_END_TIME_FORMAT.format(TimeUtil.newDate()); + statusHandler.info("Invoking report_alarm at " + currentTime); + + try { + ReportOptions options = null; + try { + options = loadConfiguration(); + } catch (IllegalArgumentException e) { + statusHandler + .error("Invalid configuration value specified.", e); + return; + } + + ReportWriter reportWriter; + try { + AlertalarmRecord aaRecord = RecordMgr.getAlarmData(options); + reportWriter = new ReportWriter(options, TimeUtil.newDate()); + reportWriter.generateReport(aaRecord); + } catch (Exception e) { + statusHandler.error("Could not generate Alertalarm report.", e); + return; + } + + File outputFile; + try { + outputFile = createOutputFile(options.getFileName()); + reportWriter.writeToDisk(outputFile); + } catch (IOException e) { + statusHandler.error("Could not write output file.", e); + return; + } + String fileName = outputFile.getPath(); + + int alarmCount = reportWriter.getAlarmCount(); + if (alarmCount == 0) { + statusHandler.info("No alarms reported, info sent to " + + fileName); + statusHandler.info("File NOT sent to text database."); + } else { + statusHandler.info(alarmCount + + " alarms reported, report written " + fileName); + statusHandler.info("Writing " + fileName + " to textdb as id " + + options.getProductId()); + + try { + saveProductToTextDb(reportWriter.getReportData(), + options.getProductId()); + } catch (Exception e) { + statusHandler.error("Could not write product to textdb", e); + } + } + } finally { + currentTime = START_END_TIME_FORMAT.format(TimeUtil.newDate()); + statusHandler.info("Completed report_alarm at " + currentTime); + } + } + + private static ReportOptions loadConfiguration() { + AppsDefaults appsDefaults = AppsDefaults.getInstance(); + ReportOptions userOptions = new ReportOptions(appsDefaults); + return userOptions; + } + + private static File createOutputFile(final String fileName) + throws IOException { + AppsDefaults appDefaults = AppsDefaults.getInstance(); + String basePath = appDefaults.getToken(Constants.WHFS_PRODUCT_DIR); + if (basePath == null) { + throw new IllegalArgumentException( + "whfs_product_dir directory undefined"); + } + + String fullPath = FileUtil.join(basePath, fileName); + File outFile = new File(fullPath); + outFile.createNewFile(); + + return outFile; + } + + private static void saveProductToTextDb(final String productText, + final String productId) throws Exception { + TextDB textdb = new TextDB(); + long statusCode = textdb.writeProduct(productId, productText, true, + null); + + if (statusCode != Long.MIN_VALUE) { + statusHandler.info("Product successfully sent"); + } else { + statusHandler.error("Product send error detected."); + } + } +} diff --git a/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_alarm_whfs b/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_alarm_whfs index 2533da9c7f..4afa570df9 100755 --- a/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_alarm_whfs +++ b/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_alarm_whfs @@ -44,7 +44,9 @@ echo Starting alarm_whfs at $Dte >> $LOGFILE $WHFS_LOCAL_BIN_DIR/run_roc_checker -$WHFS_LOCAL_BIN_DIR/run_report_alarm +# The run_report_alarm script has been replaced by an EDEX service +# com.raytheon.uf.edex.ohd.reportalarm.RunReportAlarmSrv +# See A2 redmine DR #2783 Dte=`date -u ` echo Completed alarm_whfs at $Dte >> $LOGFILE diff --git a/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_report_alarm b/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_report_alarm index 719032977e..9b9f875ee4 100644 --- a/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_report_alarm +++ b/nativeLib/files.native/awipsShare/hydroapps/whfs/bin/run_report_alarm @@ -5,157 +5,21 @@ # a product and send them to the text database # -# Revised:Sep 11, 2012 +# Revised:Feb 14, 2014 ###################################################################### -# This allows you to call this script from outside of ./standard/bin -RUN_FROM_DIR=`dirname $0` - -# set up SOME environment variables for WHFS applications -# Run from local bin dir -. $RUN_FROM_DIR/../../set_hydro_env -. $RUN_FROM_DIR/../../check_app_context - -export EDEX_HOME=/awips2/edex -export DB_NAME=$(get_apps_defaults db_name) -export FXA_DB_NAME=fxatext -export WHFS_UTIL_LOG_DIR=$(get_apps_defaults whfs_util_log_dir) -export WHFS_PRODUCT_DIR=$(get_apps_defaults whfs_product_dir) -export WHFS_BIN_DIR=$(get_apps_defaults whfs_bin_dir) -export SYS_JAVA_DIR=$(get_apps_defaults sys_java_dir) -export UTILITYDIR=$EDEX_HOME/data/utility - - +# This script has been made obsolete by a new java-based service that +# runs within the EDEX ingest JVM named +# com.raytheon.uf.edex.ohd.reportalarm.RunReportAlarmSrv. # -# Report output goes to dedicated files named by product_id and the -# file suffix, which is normally set according to the system time. -# Log output and error messages should appear in the redirected output of the program. +# This new service can still be configured using a site-level override +# to the standard Apps_defaults file. # - -LOGFILE=$WHFS_UTIL_LOG_DIR/report_alarm.log -TEMPNAME=$WHFS_UTIL_LOG_DIR/report_alarm.tmp - -# setup the AWIPS environment -# redirect any output from this script to the log file +# Configuration options for that file are defined within the base file. # - -/awips2/fxa/bin/setup.env >> $LOGFILE 2>&1 - - +# Logging for the run_report_alarm process has been moved to +# /awips2/edex/logs/edex-ingest-ohd-YYYYMMDD.log. # -# save only the latest events in the log file -# -if [ -e "${LOGFILE}" ] -then - tail -1200 $LOGFILE > $TEMPNAME - mv $TEMPNAME $LOGFILE -fi - -# log start of script -# -echo "------------------------------ " >> $LOGFILE -Dte=`date -u` -echo Invoking report_alarm at $Dte >> $LOGFILE - -# -# program usage: -# report_alarm -d -p <--required args -# -r -s -m <-- optional args -# -f -e <-- optional args -# - -# define the product id as per local needs - SET LOCALLY !!!!!!!!!!!!!!!!!!!!! -# - -PRODUCT_ID=CCCACRXXX -# -# define the file suffix based on the system time -# use extr var to avoid SCCS problem - -hstr="%H" -SUFFIX=`date -u +%m%d.$hstr%M` - -# -# the name of the created file is set according to how the program -# builds the name - -FILENAME=$WHFS_PRODUCT_DIR/$PRODUCT_ID.$SUFFIX - -# -# To discover dependencies and dynamically -# build associated classpath. -# - -function buildClassPath { - targetDir=$1 - pattern=$2 - targetDirListing=`find $targetDir -name "$pattern"` - list= - for i in $targetDirListing - do - list=${list}:${i} - done - printf " $list " -} - - -# set dependencies base directories -LOG4J_CONF=$WHFS_BIN_DIR -DEPENDENCY_DIR=$EDEX_HOME/lib/dependencies -HIBERNATE_DIR=$DEPENDENCY_DIR/org.hibernate -CAMEL_DIR=$DEPENDENCY_DIR/org.apache.camel -SPRING_ORM_DIR=$DEPENDENCY_DIR/org.springframework - - -# set patterns for target dependencies -PATTERN='*\.jar' -COMMONS_PATTERN='commons*\.jar' - -# get dependencies path -PLUGINS="$EDEX_HOME/lib/plugins/*" -CAMEL="$DEPENDENCY_DIR/org.apache.camel/*" -GEOTOOLS="$DEPENDENCY_DIR/org.geotools/*" -JAVAX_MEASURE="$DEPENDENCY_DIR/javax.measure/*" -JAVAX_PERSISTANCE="$DEPENDENCY_DIR/javax.persistence/*" -MCHANGE="$DEPENDENCY_DIR/com.mchange/*" -LOG4J="$DEPENDENCY_DIR/org.apache.log4j/*" -SLF4J="$DEPENDENCY_DIR/org.slf4j/*" -DOM4J="$DEPENDENCY_DIR/org.dom4j/*" -SPRING="$DEPENDENCY_DIR/org.springframework/*" -HIBERNATE="$DEPENDENCY_DIR/org.hibernate/*" -APACHE_COMMONS=`buildClassPath $DEPENDENCY_DIR $COMMONS_PATTERN` - - -# set the application classpath -export CLASSPATH=$HIBERNATE:$SPRING:$DB_DRIVER_PATH:$CAMEL:$GEOTOOLS:$JAVAX_MEASURE:$MCHANGE:$LOG4J:$SLF4J:$JAVAX_PERSISTANCE:$DOM4J:$APACHE_COMMONS:$PLUGINS:$CLASSPATH - -# -# run the application -# -$SYS_JAVA_DIR/bin/java -Xms64m -Xmx512m com.raytheon.edex.plugin.shef.alarms.AlertalarmStdTextProductUtil -d$DB_NAME -p$PRODUCT_ID -s$SUFFIX -rNEAREST >> $LOGFILE 2>&1 -NUM_ALARMS=$? - - -if [ $NUM_ALARMS -eq 0 ] -then - print No alarms reported, info sent to $FILENAME >> $LOGFILE - print File NOT sent to text database >> $LOGFILE - -else - print $NUM_ALARMS alarms reported, report written to $FILENAME >> $LOGFILE - - echo Writing $FILENAME to textdb as id $PRODUCT_ID >> $LOGFILE - /awips2/fxa/bin/textdb -w $PRODUCT_ID < $FILENAME >> $LOGFILE 2>&1 - RETURN_STATUS=$? - - if [ $RETURN_STATUS -eq 0 ] - then - print Product successfully sent >> $LOGFILE - else - print Product send error detected, status= $RETURN_STATUS >> $LOGFILE - fi -fi - -Dte=`date -u ` -echo Completed report_alarm at $Dte >> $LOGFILE +# For more information on this change please refer to A2 redmine +# DR #2783.