From ee32011be03e32f37f9c43a5adf251fe6ed75891 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Wed, 20 May 2015 12:21:47 -0500 Subject: [PATCH] Omaha #4510 Sending TAF now uses forecaster ID instead of name. Change-Id: If8dd7c6cbea2da7b5c392786e26e67c96eb616c4 Former-commit-id: 81e54aad427a151b1fd61a3d2ea25ecd50686a04 --- .../viz/aviation/observer/SendDialog.java | 61 +++++++++++- .../xml/AviationForecasterConfig.java | 75 ++++++++++++++ .../viz/aviation/xml/ForecasterConfig.java | 99 +++++++++++++++++++ .../avnwatch/aviationForecasterConfig.xml | 42 ++++++++ 4 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/AviationForecasterConfig.java create mode 100644 cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/ForecasterConfig.java create mode 100644 localization/localization.OAX/utility/cave_static/site/OAX/aviation/avnwatch/aviationForecasterConfig.xml diff --git a/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/observer/SendDialog.java b/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/observer/SendDialog.java index 841d7863d9..5cd8077192 100644 --- a/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/observer/SendDialog.java +++ b/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/observer/SendDialog.java @@ -19,12 +19,15 @@ **/ package com.raytheon.viz.aviation.observer; +import java.io.File; import java.util.ArrayList; import java.util.Calendar; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.xml.bind.JAXB; + import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -38,6 +41,7 @@ import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; +import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -51,6 +55,9 @@ import com.raytheon.uf.viz.core.requests.ThriftClient; import com.raytheon.viz.aviation.AviationDialog; import com.raytheon.viz.aviation.editor.EditorTafTabComp; import com.raytheon.viz.aviation.resource.ResourceConfigMgr; +import com.raytheon.viz.aviation.xml.AviationForecasterConfig; +import com.raytheon.viz.aviation.xml.ForecasterConfig; +import com.raytheon.viz.avnconfig.AvnConfigFileUtil; import com.raytheon.viz.avnconfig.IStatusSettable; import com.raytheon.viz.avnconfig.ITafSiteConfig; import com.raytheon.viz.avnconfig.TafSiteConfigFactory; @@ -71,6 +78,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; * 09OCT2012 1229 rferrel Make dialog non-blocking. * 0yJUN2013 1981 mpduff Set user on the request. * 06May2014 3091 rferrel Use OUP authorization to bring up send dialog. + * 20May2015 4510 rferrel Added {@link #getForecasterId()}. * * * @@ -83,6 +91,14 @@ public class SendDialog extends CaveSWTDialog { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(SendDialog.class); + /** Site file to use to find user's forecater id. */ + private final String FORECAST_CONFIG_FILE = "aviation" + + IPathManager.SEPARATOR + "avnwatch" + IPathManager.SEPARATOR + + "aviationForecasterConfig.xml"; + + /** Default forecaster id. */ + private final String DEFAULT_ID = "000"; + /** * Expression to find time stamp in a TAF. */ @@ -352,7 +368,7 @@ public class SendDialog extends CaveSWTDialog { request.setUser(UserController.getUserObject()); // Forecaster ID - String forecasterId = forecasterLabel.getText(); + String forecasterId = getForecasterId(); Calendar xmitTime = Calendar.getInstance(); xmitTime.setTimeZone(TimeZone.getTimeZone("GMT")); xmitTime.set(Calendar.HOUR_OF_DAY, hourSpnr.getSelection()); @@ -507,4 +523,47 @@ public class SendDialog extends CaveSWTDialog { return type + "A"; } + + /** + * Determine forcaster's id for the user. When none found return the + * {@link #DEFAULT_ID}. This string will be in the VFT product. + * + * @return forecasterId - padded to 3 character so an id of 1 will return + * 001 + */ + private String getForecasterId() { + File f = AvnConfigFileUtil.getStaticFile(FORECAST_CONFIG_FILE); + ArrayList fcList = null; + String forecasterName = AviationDialog.getForecaster(); + + if (f == null) { + statusHandler + .handle(Priority.PROBLEM, "Unable to load, " + + FORECAST_CONFIG_FILE + ", using default ID " + + DEFAULT_ID); + return DEFAULT_ID; + } + + try { + fcList = JAXB.unmarshal(f, AviationForecasterConfig.class) + .getForecasterConfig(); + } catch (RuntimeException ex) { + statusHandler.handle(Priority.PROBLEM, + "Unable to parse, " + FORECAST_CONFIG_FILE + + ", using default ID " + DEFAULT_ID, ex); + return DEFAULT_ID; + } + + if ((fcList != null) && !fcList.isEmpty()) { + for (ForecasterConfig fc : fcList) { + if (forecasterName.equals(fc.getName())) { + return fc.getFormattedId(); + } + } + } + + statusHandler.handle(Priority.PROBLEM, "No forecaster Id for " + + forecasterName + "using default " + DEFAULT_ID); + return DEFAULT_ID; + } } diff --git a/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/AviationForecasterConfig.java b/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/AviationForecasterConfig.java new file mode 100644 index 0000000000..0a7fadedb2 --- /dev/null +++ b/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/AviationForecasterConfig.java @@ -0,0 +1,75 @@ +/** + * 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.viz.aviation.xml; + +import java.util.ArrayList; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import com.raytheon.uf.common.serialization.ISerializableObject; + +/** + * Aviation Forecaster Configuration + * + *
+ * 
+ *    SOFTWARE HISTORY
+ *   
+ *    Date         Ticket#     Engineer    Description
+ *    ------------ ----------  ----------- --------------------------
+ *    2/7/2008     817         grichard    Initial Creation.
+ * 
+ * 
+ * + * @author grichard + * @version 1.0 + */ +@XmlRootElement(name = "aviationForecasterConfig") +@XmlAccessorType(XmlAccessType.NONE) +public class AviationForecasterConfig implements ISerializableObject { + + /** + * The aviation forecaster configuration. + */ + @XmlElement(name = "forecaster") + private ArrayList forecasterConfig; + + /** + * Method that gets the aviation forecaster configuration + * + * @return forecasterConfig + */ + public ArrayList getForecasterConfig() { + return forecasterConfig; + } + + /** + * Method that sets the aviation forecaster configuration + * + * @param forecasterConfig + * -- the aviation forecaster configuration + */ + public void setForecasterConfig(ArrayList forecasterConfig) { + this.forecasterConfig = forecasterConfig; + } +} \ No newline at end of file diff --git a/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/ForecasterConfig.java b/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/ForecasterConfig.java new file mode 100644 index 0000000000..9922f77664 --- /dev/null +++ b/cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/xml/ForecasterConfig.java @@ -0,0 +1,99 @@ +/** + * 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.viz.aviation.xml; + +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +/** + * Forecaster Configuration class + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * 2/6/2008     817        grichard    Initial creation
+ * 5/20/2015    4510       rferrel     Added {@link #getFormattedId()}.
+ * 
+ * 
+ * + * @author grichard + * @version 1.0 + */ +@XmlAccessorType +public class ForecasterConfig { + /** + * The forecaster's id number + */ + @XmlElement(name = "id") + private int forecasterId = 0; + + /** + * The forecaster's name + */ + @XmlElement(name = "name") + private String forecasterName; + + /** + * The forecaster's transmit privilege + */ + @XmlElement(name = "xmit") + private String xmitPrivilege; + + /** + * Getters and setters + */ + + public String getName() { + return forecasterName; + } + + public boolean getXmitPrivilege() { + return Boolean.parseBoolean(xmitPrivilege); + } + + public int getId() { + return forecasterId; + } + + /** + * This formats the id to a 3 character string needed for generating the VFT + * products. + * + * @return formattedId + */ + public String getFormattedId() { + return String.format("%1$03d", forecasterId); + } + + public void setName(String name) { + this.forecasterName = name; + } + + public void setXmit(boolean privilege) { + this.xmitPrivilege = Boolean.toString(privilege); + } + + public void setId(int id) { + this.forecasterId = id; + } +} diff --git a/localization/localization.OAX/utility/cave_static/site/OAX/aviation/avnwatch/aviationForecasterConfig.xml b/localization/localization.OAX/utility/cave_static/site/OAX/aviation/avnwatch/aviationForecasterConfig.xml new file mode 100644 index 0000000000..26eda594ac --- /dev/null +++ b/localization/localization.OAX/utility/cave_static/site/OAX/aviation/avnwatch/aviationForecasterConfig.xml @@ -0,0 +1,42 @@ + + + + 001 + Amanda + true + + + 002 + Bailing + true + + + 003 + Belinda + true + + + 004 + George + true + + + 005 + Mark + true + + + 006 + Matt + true + + + 007 + Mike + true + + \ No newline at end of file