diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDlg.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDlg.java index 8246bde5e6..12df601a22 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDlg.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/TimeSeriesDlg.java @@ -80,6 +80,7 @@ import com.raytheon.viz.hydro.timeseries.util.GraphData; import com.raytheon.viz.hydro.timeseries.util.GroupInfo; import com.raytheon.viz.hydro.timeseries.util.LIDData; import com.raytheon.viz.hydro.timeseries.util.PageInfo; +import com.raytheon.viz.hydro.timeseries.util.PreferredOrderManager; import com.raytheon.viz.hydro.timeseries.util.TimeSeriesUtil; import com.raytheon.viz.hydro.timeseries.util.TraceData; import com.raytheon.viz.hydrocommon.HydroConstants; @@ -126,6 +127,8 @@ import com.raytheon.viz.hydrocommon.util.StnClassSyncUtil; * Jul 21, 2015 4500 rjpeter Use Number in blind cast. * Oct 13, 2015 4933 rferrel Log error if unable to find group definition file * Fixed formatter resource leaks. + * 30 Oct, 2015 15102 wkwock Implements preferred order for PE-D-TS-EXT list + * * * * @author lvenable @@ -1512,9 +1515,13 @@ public class TimeSeriesDlg extends CaveHydroSWTDialog { ArrayList data = (ArrayList) dataManager .getSitePEData(selectedLid); + PreferredOrderManager pom = PreferredOrderManager.getInstance(); + Map peMap = pom.getPreferedOrder(selectedLid); + bottomDataList.removeAll(); /* Get the lists of PE data */ + LinkedHashMap> preferredMap = new LinkedHashMap>(); LinkedHashMap> hMap = new LinkedHashMap>(); LinkedHashMap> qMap = new LinkedHashMap>(); LinkedHashMap> pMap = new LinkedHashMap>(); @@ -1533,7 +1540,30 @@ public class TimeSeriesDlg extends CaveHydroSWTDialog { si.setExt((String) row[3]); si.setDur(((Number) row[4]).intValue()); - if (si.getPe().startsWith("H")) { + boolean preferredLstFlg = false; + if (peMap!=null){ + String[] typeSrcLst = peMap.get(si.getPe()); + + if (typeSrcLst != null) { + for (String typesrc : typeSrcLst) { + + if (typesrc.equalsIgnoreCase(si.getTs())) { + preferredLstFlg = true; + break; + } + } + } else if (peMap.containsKey(si.getPe())) { + preferredLstFlg = true; + } + } + if (preferredLstFlg) { + if (!si.getPe().equals(prevPE)) { + preferredMap.put(si.getPe(), new ArrayList()); + prevPE = si.getPe(); + } + + preferredMap.get(si.getPe()).add(si); + } else if (si.getPe().startsWith("H")) { if (!si.getPe().equals(prevPE)) { hMap.put(si.getPe(), new ArrayList()); prevPE = si.getPe(); @@ -1591,6 +1621,7 @@ public class TimeSeriesDlg extends CaveHydroSWTDialog { tsSelected = false; } + populatePreferredDataInOrder(preferredMap,peMap); processDataList(hMap, tsSelected); processDataList(qMap, tsSelected); processDataList(pMap, tsSelected); @@ -1601,7 +1632,41 @@ public class TimeSeriesDlg extends CaveHydroSWTDialog { selectedDataLbl.setText(selectedLid); bottomDataList.setSelection(0); } catch (VizException e) { - e.printStackTrace(); + statusHandler.error("Failed to populate time series list",e); + } + } + + /** + * populate data to bottomDataList base on preferred predefined order + * @param preferredMap + * @param peMap + */ + private void populatePreferredDataInOrder (LinkedHashMap>preferredMap, Map peMap) { + if (peMap!=null && preferredMap!=null ){ + for (String pe:peMap.keySet()){ + java.util.List siList = preferredMap.get(pe); + + if (siList == null) { + continue; + } + + String[] tsList = peMap.get(pe); + if (tsList==null) { //There's PE but no TS in preffered_order.txt + for(SiteInfo si : siList) { + bottomDataList.add(formatDataLine(si)); + siteInfoList.add(si); + } + } else { //There's both PE and TS in preferred_order.txt + for (String ts: tsList){ + for(SiteInfo si : siList) { + if (ts.equalsIgnoreCase(si.getTs())) { + bottomDataList.add(formatDataLine(si)); + siteInfoList.add(si); + } + } + } + } + } } } diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/util/PreferredOrderManager.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/util/PreferredOrderManager.java new file mode 100644 index 0000000000..032166f062 --- /dev/null +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/timeseries/util/PreferredOrderManager.java @@ -0,0 +1,156 @@ +package com.raytheon.viz.hydro.timeseries.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedHashMap; +import java.util.Map; + +import com.raytheon.uf.common.localization.FileUpdatedMessage; +import com.raytheon.uf.common.localization.ILocalizationFileObserver; +import com.raytheon.uf.common.localization.IPathManager; +import com.raytheon.uf.common.localization.LocalizationFile; +import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.exception.LocalizationException; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.viz.hydrocommon.HydroConstants; + +/** + * This class read the user preferred predefined PE-D-TS-EXT list from file: + * hydro/preferred_order.txt File format: lines start with # is a comment One + * line per LID LID PE1:TS1,TS2 PE2:TS2,TS3 ... Duplicated LID will replaced by + * last one. + * + * @author wkwock + * + *
+ * SOFTWARE HISTORY 
+ * Date       Ticket#    Engineer    Description 
+ * ---------- ---------- ----------- -------------------------- 
+ * 6/22/2015  DCS15102    wkwock      Initial creation.
+ * 
+ */ +public class PreferredOrderManager implements ILocalizationFileObserver { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(PreferredOrderManager.class); + + private static PreferredOrderManager pom = null; + + private Map> lidHm = new LinkedHashMap>(); + + private boolean readFileFlag = true; + + private static final String COMMA_REGEX = "\\s*,\\s*"; + // For remove space around commas. + + private static final String COLON_REGEX = "\\s*:\\s*"; + // For remove spaces around colons. + + private static final String SPACE_REGEX = "\\s+"; + + private PreferredOrderManager() { + IPathManager pm = PathManagerFactory.getPathManager(); + LocalizationFile file = pm + .getStaticLocalizationFile(HydroConstants.PREFERRED_ORDER); + if (file == null || !file.exists()) { + return; + } + + file.addFileUpdatedObserver(this); + } + + private void readPreferredOrderFile() { + IPathManager pm = PathManagerFactory.getPathManager(); + LocalizationFile file = pm + .getStaticLocalizationFile(HydroConstants.PREFERRED_ORDER); + lidHm.clear(); + + if (file == null || !file.exists()) { + return; + } + + StringBuilder message = new StringBuilder(); + + BufferedReader in = null; + try { + in = new BufferedReader(new InputStreamReader( + file.openInputStream())); + String line; + inloop: while ((line = in.readLine()) != null) { + String str = line.trim(); + if (str.startsWith("#") || str.length() == 0) { + continue;// This is a comment or blank line + } + + str = str.replaceAll(COMMA_REGEX, ",").replaceAll(COLON_REGEX, + ":"); + String[] lineSplit = str.split(SPACE_REGEX); + if (lineSplit.length < 2) { + message.append(line + "\n"); + continue; + } + String lid = lineSplit[0].toUpperCase(); + LinkedHashMap peHm = new LinkedHashMap(); + for (int index = 1; index < lineSplit.length; index++) { + String[] peSplit = lineSplit[index].split(":"); + if (peSplit.length > 2) { + message.append(line + "\n"); + continue inloop; + } + String pe = peSplit[0].toUpperCase(); + + if (peSplit.length == 2) { + String[] tsSplit = peSplit[1].split(","); + peHm.put(pe, tsSplit); + } else { + peHm.put(pe, null); + } + } + lidHm.put(lid, peHm); + } + + if (message.length() > 0) { + message.insert(0,"Invalid line in file "+HydroConstants.PREFERRED_ORDER+":\n"); + message.append("Valid example: ACCM2 PP:RZ,RG TA:RZ\n"); + } + } catch (IOException | LocalizationException e) { + message.append("Failed to read file "+HydroConstants.PREFERRED_ORDER); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + message.append("Failed to close file "+HydroConstants.PREFERRED_ORDER); + } + } + } + + if (message.length() > 0) { + statusHandler.warn(message.toString()); + } + } + + public final static synchronized PreferredOrderManager getInstance() { + if (pom == null) { + pom = new PreferredOrderManager(); + } + + return pom; + } + + public Map getPreferedOrder(String lid) { + if (readFileFlag) { + readPreferredOrderFile(); + readFileFlag = false; + } + + Map peMap = lidHm.get(lid); + return peMap; + } + + @Override + public void fileUpdated(FileUpdatedMessage message) { + readFileFlag = true; + } +} diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/HydroConstants.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/HydroConstants.java index cb091db728..1d743a4240 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/HydroConstants.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/HydroConstants.java @@ -33,6 +33,7 @@ import org.eclipse.swt.graphics.RGB; * ------------ ---------- ----------- -------------------------- * Jun 17, 2008 1194 M. Duff Initial creation. * 11/18/2008 1662 grichard Added physical element enum type. + * 14 Sep, 2015 15102 wkwock Implements preferred order for PE-D-TS-EXT list * * * @@ -262,6 +263,8 @@ public class HydroConstants { public static final String RFCMOSAIC_DIR_TOKEN = "gaq_xmrg_1hr_dir"; + public static final String PREFERRED_ORDER = "/hydro/preferred_order.txt"; + /** * Enumeration used for selection of physical element. */