diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/META-INF/MANIFEST.MF index 841535b801..98df745783 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: FFMP common Plug-in Bundle-SymbolicName: com.raytheon.uf.common.dataplugin.ffmp -Bundle-Version: 1.14.0.qualifier +Bundle-Version: 1.16.0.qualifier Bundle-Vendor: RAYTHEON Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Export-Package: com.raytheon.uf.common.dataplugin.ffmp, diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPTemplates.java b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPTemplates.java index 5f22b2ecff..230299f352 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPTemplates.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/FFMPTemplates.java @@ -1,19 +1,19 @@ /** * 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. **/ @@ -23,6 +23,7 @@ import java.awt.Rectangle; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.HashMap; @@ -35,17 +36,20 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; import com.raytheon.uf.common.datastorage.StorageException; import com.raytheon.uf.common.gridcoverage.GridCoverage; import com.raytheon.uf.common.hydro.spatial.HRAPCoordinates; import com.raytheon.uf.common.hydro.spatial.HRAPSubGrid; +import com.raytheon.uf.common.localization.ILocalizationFile; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.monitor.config.FFMPRunConfigurationManager; import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager; @@ -60,7 +64,6 @@ import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; -import com.raytheon.uf.common.util.FileUtil; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; @@ -73,18 +76,18 @@ import com.vividsolutions.jts.io.WKBReader; /** * FFMPHucTemplate maker/factory - * + * *
- * 
+ *
  * SOFTWARE HISTORY
- * 
+ *
  * Date         Ticket#     Engineer    Description
  * ------------ ----------  ----------- --------------------------
  * 07/29/09      2152       D. Hladky   Initial release
  * 07/09/10      3914       D. Hladky   Localization work
  * 12/13/10      7484       D. Hladky   Service Backup
  * 02/01/13      1569       D.Hladky    Constants
- * 03/01/13      DR13228    G. Zhang    Add VGB county and related code 
+ * 03/01/13      DR13228    G. Zhang    Add VGB county and related code
  * 02/20/13      1635       D. Hladky   Constants
  * 03/18/13      1817       D. Hladky   Fixed issue with BOX where only 1 HUC was showing up.
  * 04/15/13      1902       M. Duff     Generic List
@@ -94,9 +97,10 @@ import com.vividsolutions.jts.io.WKBReader;
  * Nov 18, 2014  3831       dhladky     StatusHandler logging. Proper list sizing. Geometry chunk sizing.
  * Aug 08, 2015  4722       dhladky     Improved Grid support.
  * Nov 12, 2015  4834       njensen     Changed LocalizationOpFailedException to LocalizationException
- * 
+ * Feb 15, 2016  5244       nabowle     Replace deprecated LocalizationFile methods.
+ *
  * 
- * + * * @author dhladky * @version 1 */ @@ -168,7 +172,7 @@ public class FFMPTemplates { /** * Single constructor - * + * * @return */ public static synchronized FFMPTemplates getInstance(DomainXML domain, @@ -183,7 +187,7 @@ public class FFMPTemplates { /** * Multiple constructor loads multiple - * + * * @return */ public static synchronized FFMPTemplates getInstance(DomainXML primaryCWA, @@ -198,7 +202,7 @@ public class FFMPTemplates { /** * EDEX constructor - * + * * @param primaryCWA * @param mode */ @@ -323,7 +327,7 @@ public class FFMPTemplates { /** * Gets the FFMPBasinData template file/object - * + * * @param hucName * @param cwa * @return @@ -355,7 +359,7 @@ public class FFMPTemplates { /** * Gets the FFMPBasinData template file/object - * + * * @param hucName * @param cwa * @return @@ -379,7 +383,7 @@ public class FFMPTemplates { /** * Writes out the byte array from thrift - * + * * @param map * @param cwa * @param dataKey @@ -398,21 +402,28 @@ public class FFMPTemplates { } try { - LocalizationContext lc = pathManager.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile lfmap = pathManager.getLocalizationFile(lc, + ILocalizationFile lfmap = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, "VIRTUAL", cwa, "map")); - LocalizationFile lflist = pathManager.getLocalizationFile(lc, + ILocalizationFile lflist = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, "VIRTUAL", cwa, "list")); - FileUtil.bytes2File(SerializationUtil.transformToThrift(list), - lflist.getFile(), true); - lflist.save(); + try (SaveableOutputStream listSos = lflist.openOutputStream(); + GZIPOutputStream listGos = new GZIPOutputStream(listSos); + SaveableOutputStream mapSos = lfmap.openOutputStream(); + GZIPOutputStream mapGos = new GZIPOutputStream(mapSos)) { - FileUtil.bytes2File(SerializationUtil.transformToThrift(map), - lfmap.getFile(), true); - lfmap.save(); + listGos.write(SerializationUtil.transformToThrift(list)); + listGos.finish(); + listGos.flush(); + listSos.save(); + + mapGos.write(SerializationUtil.transformToThrift(map)); + mapGos.finish(); + mapGos.flush(); + mapSos.save(); + } list = null; @@ -433,7 +444,7 @@ public class FFMPTemplates { /** * Writes out the byte array from thrift - * + * * @param huc * @param cwa * @param map @@ -451,44 +462,34 @@ public class FFMPTemplates { } try { - if (huc.equals(FFMPRecord.ALL)) { + LocalizationContext lc = pathManager.getContext( + LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationContext lc = pathManager.getContext( - LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); + ILocalizationFile lflist = pathManager.getLocalizationFile(lc, + getAbsoluteFileName(dataKey, huc, cwa, "list")); + ILocalizationFile lfmap = pathManager.getLocalizationFile(lc, + getAbsoluteFileName(dataKey, huc, cwa, "map")); - LocalizationFile lflist = pathManager.getLocalizationFile(lc, - getAbsoluteFileName(dataKey, huc, cwa, "list")); - LocalizationFile lfmap = pathManager.getLocalizationFile(lc, - getAbsoluteFileName(dataKey, huc, cwa, "map")); + try (SaveableOutputStream listSos = lflist.openOutputStream(); + GZIPOutputStream listGos = new GZIPOutputStream(listSos); + SaveableOutputStream mapSos = lfmap.openOutputStream(); + GZIPOutputStream mapGos = new GZIPOutputStream(mapSos)) { - FileUtil.bytes2File(SerializationUtil.transformToThrift(list), - lflist.getFile(), true); - FileUtil.bytes2File(SerializationUtil.transformToThrift(map), - lfmap.getFile(), true); + listGos.write(SerializationUtil.transformToThrift(list)); + listGos.finish(); + listGos.flush(); - lflist.save(); - lfmap.save(); - - } else { - - LocalizationContext lc = pathManager.getContext( - LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - - LocalizationFile lfmap = pathManager.getLocalizationFile(lc, - getAbsoluteFileName(dataKey, huc, cwa, "map")); - LocalizationFile lflist = pathManager.getLocalizationFile(lc, - getAbsoluteFileName(dataKey, huc, cwa, "list")); - - FileUtil.bytes2File( - SerializationUtil - .transformToThrift(toPrimitive((LinkedHashMap>) map)), - lfmap.getFile(), true); - FileUtil.bytes2File(SerializationUtil.transformToThrift(list), - lflist.getFile(), true); - - lfmap.save(); - lflist.save(); + if (huc.equals(FFMPRecord.ALL)) { + mapGos.write(SerializationUtil.transformToThrift(map)); + } else { + mapGos.write(SerializationUtil + .transformToThrift(toPrimitive((LinkedHashMap>) map))); + } + mapGos.finish(); + mapGos.flush(); + listSos.save(); + mapSos.save(); } list = null; @@ -512,7 +513,7 @@ public class FFMPTemplates { /** * Gets the completed filename - * + * * @return */ @@ -532,7 +533,7 @@ public class FFMPTemplates { /** * Gets the template file directory - * + * * @return */ public String getTemplateFileLocation() { @@ -541,7 +542,7 @@ public class FFMPTemplates { /** * Double for max Extent of the radar - * + * * @return */ public double getMaxExtent() { @@ -550,7 +551,7 @@ public class FFMPTemplates { /** * This maxExtent - * + * * @param maxExtent */ public void setMaxExtent(Double maxExtent) { @@ -559,7 +560,7 @@ public class FFMPTemplates { /** * Gets a basin - * + * * @param pfaf * @return */ @@ -578,7 +579,7 @@ public class FFMPTemplates { /** * Gets a basin in terms of total loaded domains and sites - * + * * @param pfaf * @return */ @@ -639,7 +640,7 @@ public class FFMPTemplates { /** * Finds the aggregated pfaf of a given pfaf - * + * * @param pfaf * @return */ @@ -658,7 +659,7 @@ public class FFMPTemplates { /** * Finds the aggregated pfaf of a given VGB - * + * * @param lid * @param dataKey * @param huc @@ -698,7 +699,7 @@ public class FFMPTemplates { /** * Gets the aggregate mappings for all domains - * + * * @param pfaf * @return */ @@ -725,7 +726,7 @@ public class FFMPTemplates { /** * Gets the aggregate mappings for all domains, used by the FFFG dialog If * you want ALL and I mean ALL of the basins in a given coverage - * + * * @param pfaf * @return */ @@ -765,7 +766,7 @@ public class FFMPTemplates { /** * Gets the aggreagate mappings by domain - * + * * @param pfaf * @param domain * @param huc @@ -803,7 +804,7 @@ public class FFMPTemplates { /** * Don't ever call this for anything other than FFTI or FFFG calls - * + * * @param pfaf * @param huc * @return @@ -830,7 +831,7 @@ public class FFMPTemplates { /** * Get the basin by Lat/Lon - * + * * @param coor * @return */ @@ -872,7 +873,7 @@ public class FFMPTemplates { /** * Gets the pfaf by basinId - * + * * @param basinId * @return */ @@ -894,7 +895,7 @@ public class FFMPTemplates { /** * Finds the center of an aggregation of basins (Roughly) - * + * * @param pfaf * @param dataKey * @param huc @@ -937,7 +938,7 @@ public class FFMPTemplates { /** * Check to see if file is there - * + * * @param hucName * @return */ @@ -949,9 +950,9 @@ public class FFMPTemplates { LocalizationContext lc = pathManager.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile listf = pathManager.getLocalizationFile(lc, + ILocalizationFile listf = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, huc, cwa, "list")); - LocalizationFile mapf = pathManager.getLocalizationFile(lc, + ILocalizationFile mapf = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, huc, cwa, "map")); if (listf.exists()) { @@ -979,7 +980,7 @@ public class FFMPTemplates { /** * Gets the starting index for searching - * + * * @return */ public int getHucDepthStart() { @@ -988,7 +989,7 @@ public class FFMPTemplates { /** * Sets the starting index for searching - * + * * @param hucDepthStart */ public void setHucDepthStart(int hucDepthStart) { @@ -997,7 +998,7 @@ public class FFMPTemplates { /** * Get a listing of the counties in the FFMP monitored area - * + * * @return */ public FFMPCounties getCounties(String dataKey) { @@ -1041,7 +1042,7 @@ public class FFMPTemplates { /** * Finds the parent aggregated pfaf of a given pfaf. - * + * * @param key * @param dataKey * @param huc @@ -1072,7 +1073,7 @@ public class FFMPTemplates { /** * Find the extents of this domain - * + * * @param cwa * @return */ @@ -1085,7 +1086,7 @@ public class FFMPTemplates { /** * Find the extents of the collective sites - * + * * @param cwa * @return */ @@ -1149,7 +1150,7 @@ public class FFMPTemplates { /** * Sets the extents - * + * * @param maxExtent */ public void setExtents(double maxExtent) { @@ -1162,7 +1163,7 @@ public class FFMPTemplates { /** * gets the virtuals or not - * + * * @return */ public boolean getVirtual() { @@ -1171,7 +1172,7 @@ public class FFMPTemplates { /** * Get the maps from storage or create them - * + * * @param huc * @param cwa * @return @@ -1329,7 +1330,7 @@ public class FFMPTemplates { /** * load up the maps - * + * * @param huc * @return */ @@ -1363,7 +1364,7 @@ public class FFMPTemplates { /** * Find the list of pfafs for this HUC level - * + * * @param siteKey * @param huc * @param domains @@ -1384,7 +1385,7 @@ public class FFMPTemplates { /** * Gets the template config manager - * + * * @return */ public FFMPTemplateConfigurationManager getTemplateMgr() { @@ -1393,7 +1394,7 @@ public class FFMPTemplates { /** * Read the file or generate VGB's for primary domain - * + * * @param cwa * @return */ @@ -1468,7 +1469,7 @@ public class FFMPTemplates { /** * Generate the Virtual Gage Basins Meta Data for primary domain - * + * * @return */ public synchronized LinkedHashMap getVirtualGageBasins( @@ -1551,7 +1552,7 @@ public class FFMPTemplates { /** * Gets the Virtual Gage Basin MetaData - * + * * @param lid * @return */ @@ -1572,7 +1573,7 @@ public class FFMPTemplates { /** * Gets the Virtual Gage Basin MetaData - * + * * @param dataKey * @param cwa * @param parentPfaf @@ -1605,7 +1606,7 @@ public class FFMPTemplates { /** * Finds the Lid string used by the aggregated VGB's - * + * * @param fbmd * @param huc * @return @@ -1624,7 +1625,7 @@ public class FFMPTemplates { /** * Gets you the list of pfafs that have VGB's for a given HUC level DONT * EVER CALL THIS WITH "ALL" HUC level use getVirtualGageBasins() for that - * + * * @param huc * @return */ @@ -1645,7 +1646,7 @@ public class FFMPTemplates { /** * Check for VGB's in aggregate pfaf - * + * * @param pfaf * @param dataKey * @param huc @@ -1662,7 +1663,7 @@ public class FFMPTemplates { /** * Gets the Virtual Gage Basin MetaData - * + * * @param pfaf * @return */ @@ -1689,7 +1690,7 @@ public class FFMPTemplates { /** * Gets you the list of pfafs that have VGB's for a given HUC level DONT * EVER CALL THIS WITH "ALL" HUC level use getVirtualGageBasins() for that - * + * * @param huc * @return */ @@ -1700,14 +1701,14 @@ public class FFMPTemplates { * getAggregatePfafs(pfaf, dataKey, huc)) { if * (getVirtualGageBasinMetaData(dataKey, iPfaf) != null) { if (vgbPfafs == * null) { vgbPfafs = new ArrayList(); } vgbPfafs.add(iPfaf); } } - * + * * return vgbPfafs; } */ /** * Gets list of aggregate pfafs that have VGB's within them * DONT EVER CALL * THIS WITH "ALL" HUC level - * + * * @param huc * @param cwa * @return @@ -1719,13 +1720,13 @@ public class FFMPTemplates { * getMap(dataKey, domain.getCwa(), huc).keySet()) { if * (getVGBsInAggregate(iPfaf, dataKey, huc) != null) { if (vgbPfafs == null) * { vgbPfafs = new ArrayList(); } vgbPfafs.add(iPfaf); } } } - * + * * return vgbPfafs; } */ /** * Gets the Virtual Gage Basin MetaData - * + * * @param pfaf * @return */ @@ -1759,7 +1760,7 @@ public class FFMPTemplates { /** * Writes out all basins from DB by CWA - * + * * @param results */ private LinkedHashMap loadBasins(String siteKey, @@ -1825,7 +1826,7 @@ public class FFMPTemplates { /** * compress to primitive - * + * * @param list * @return */ @@ -1844,7 +1845,7 @@ public class FFMPTemplates { /** * back to LinkedHash - * + * * @param longs * @return */ @@ -1864,7 +1865,7 @@ public class FFMPTemplates { /** * Get the basin ID of the county - * + * * @param dataKey * @param nameState * @return @@ -1892,7 +1893,7 @@ public class FFMPTemplates { /** * Sets the domains to load for this template instance - * + * * @param domains */ public synchronized void setDomains(ArrayList domains) { @@ -1901,7 +1902,7 @@ public class FFMPTemplates { /** * Gets the domains in this template - * + * * @return */ public synchronized ArrayList getDomains() { @@ -1910,7 +1911,7 @@ public class FFMPTemplates { /** * Add domains to the templates, This method is used by EDEX to add domains - * + * * @param domain */ public synchronized void addDomain(DomainXML domain) { @@ -1949,7 +1950,7 @@ public class FFMPTemplates { /** * Add domains to the templates, This method is used by EDEX to add domains - * + * * @param domain */ public synchronized void addDomain(String dataKey, DomainXML domain) { @@ -1964,7 +1965,7 @@ public class FFMPTemplates { /** * dump a domain on the fly, CAVE side - * + * * @param domainName */ public synchronized void removeDomain(String dataKey, String domainName) { @@ -1982,7 +1983,7 @@ public class FFMPTemplates { /** * dump a dataKey - * + * * @param domainName */ public synchronized void removeDataKey(String dataKey) { @@ -1999,7 +2000,7 @@ public class FFMPTemplates { /** * Gets the primary - * + * * @return */ public DomainXML getPrimaryDomain() { @@ -2008,7 +2009,7 @@ public class FFMPTemplates { /** * Gets the list for all of the pfafs - * + * * @param huc * @param cwa * @return @@ -2019,18 +2020,16 @@ public class FFMPTemplates { LocalizationContext lc = pathManager.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile f = pathManager.getLocalizationFile(lc, + ILocalizationFile f = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, huc, cwa, "list")); - try { - list = SerializationUtil.transformFromThrift(long[].class, - FileUtil.file2bytes(f.getFile(), true)); - } catch (SerializationException se) { - statusHandler.error("Serialization Exception: Read Domain: cwa: " - + cwa + " dataKey: " + dataKey + " huc: " + huc, se); - } catch (IOException e) { - statusHandler.error("IO Exception: Read Domain: cwa: " + cwa - + " dataKey: " + dataKey + " huc: " + huc, e); + try (InputStream is = f.openInputStream(); + GZIPInputStream gis = new GZIPInputStream(is)) { + list = SerializationUtil.transformFromThrift(long[].class, gis); + } catch (SerializationException | IOException | LocalizationException e) { + statusHandler.error( + "Exception reading domain list: Read Domain. cwa: " + cwa + + " dataKey: " + dataKey + " huc: " + huc, e); } return list; @@ -2038,7 +2037,7 @@ public class FFMPTemplates { /** * Reads the actual domain map - * + * * @param huc * @param cwa * @return @@ -2050,24 +2049,15 @@ public class FFMPTemplates { LocalizationContext lc = pathManager.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile f = pathManager.getLocalizationFile(lc, + ILocalizationFile f = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, huc, cwa, "map")); - try { - if (huc.equals(FFMPRecord.ALL)) { - - map = SerializationUtil.transformFromThrift(HashMap.class, - FileUtil.file2bytes(f.getFile(), true)); - } else { - map = SerializationUtil.transformFromThrift(HashMap.class, - FileUtil.file2bytes(f.getFile(), true)); - } - } catch (SerializationException se) { - statusHandler.error("Serialization Exception: Domain Map: " - + dataKey + " cwa:" + cwa + " huc: " + huc, se); - } catch (IOException e) { - statusHandler.error("IO Exception: Domain Map: " + dataKey - + " cwa:" + cwa + " huc: " + huc, e); + try (InputStream is = f.openInputStream(); + GZIPInputStream gis = new GZIPInputStream(is)) { + map = SerializationUtil.transformFromThrift(HashMap.class, gis); + } catch (SerializationException | IOException | LocalizationException e) { + statusHandler.error("Exception reading domain map. Domain Map: " + + dataKey + " cwa:" + cwa + " huc: " + huc, e); } return map; @@ -2075,7 +2065,7 @@ public class FFMPTemplates { /** * Reads the actual VGB domain map - * + * * @param huc * @param cwa * @return @@ -2088,26 +2078,24 @@ public class FFMPTemplates { LocalizationContext lc = pathManager.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile f = pathManager.getLocalizationFile(lc, + ILocalizationFile f = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, FFMPRecord.VIRTUAL, cwa, "map")); - try { - map = SerializationUtil.transformFromThrift(HashMap.class, - FileUtil.file2bytes(f.getFile(), true)); - } catch (SerializationException se) { - statusHandler.error("Serialization Exception: Virtual Basins: " - + dataKey + " cwa: " + cwa, se); - } catch (IOException e) { - statusHandler.error("IO Exception: Virtual Basins: " + dataKey - + " cwa: " + cwa, e); + try (InputStream is = f.openInputStream(); + GZIPInputStream gis = new GZIPInputStream(is)) { + map = SerializationUtil.transformFromThrift(HashMap.class, gis); + } catch (SerializationException | IOException | LocalizationException e) { + statusHandler.error( + "Exception reading VHB Domain map. Virtual Basins: " + + dataKey + " cwa: " + cwa, e); } return map; } /** - * Reads the actual VGB domain map - * + * Reads the actual VGB domain list + * * @param huc * @param cwa * @return @@ -2118,19 +2106,16 @@ public class FFMPTemplates { LocalizationContext lc = pathManager.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile f = pathManager.getLocalizationFile(lc, + ILocalizationFile f = pathManager.getLocalizationFile(lc, getAbsoluteFileName(dataKey, FFMPRecord.VIRTUAL, cwa, "list")); - try { - list = SerializationUtil.transformFromThrift(String[].class, - FileUtil.file2bytes(f.getFile(), true)); - } catch (SerializationException se) { + try (InputStream is = f.openInputStream(); + GZIPInputStream gis = new GZIPInputStream(is)) { + list = SerializationUtil.transformFromThrift(String[].class, gis); + } catch (SerializationException | IOException | LocalizationException e) { statusHandler.error( - "Serialization Exception: : Read Virtual Domain: cwa: " - + cwa + " dataKey: " + dataKey, se); - } catch (IOException e) { - statusHandler.error("IO Exception: : Read Virtual Domain: cwa: " - + cwa + " dataKey: " + dataKey, e); + "Exception reading VGB Domain List. Read Virtual Domain: cwa: " + + cwa + " dataKey: " + dataKey, e); } return list; @@ -2175,7 +2160,7 @@ public class FFMPTemplates { } /** - * + * * @param cwa * @return */ @@ -2204,7 +2189,7 @@ public class FFMPTemplates { /** * Look for overlaps - * + * * @param pfaf * @param huc * @return @@ -2225,7 +2210,7 @@ public class FFMPTemplates { /** * Get the areas for a list of pfafs - * + * * @param pfafs * @return */ @@ -2239,7 +2224,7 @@ public class FFMPTemplates { /** * gets all up and down stream basins for a given pfaf - * + * * @param dataKey * @param pfaf * @return @@ -2267,7 +2252,7 @@ public class FFMPTemplates { /** * Gets the down stream trace - * + * * @param dataKey * @param pfaf * @return @@ -2300,7 +2285,7 @@ public class FFMPTemplates { /** * Get the FIPS for the pfaf being looked at - * + * * @param dataKey * @param pfaf * @return @@ -2336,7 +2321,7 @@ public class FFMPTemplates { /** * Gets a metadata basin contained within the domain listed. - * + * * @param dataKey * @param domains * @param pfafs @@ -2368,7 +2353,7 @@ public class FFMPTemplates { /** * Check for site load or not - * + * * @param siteKey * @return */ @@ -2382,7 +2367,7 @@ public class FFMPTemplates { /** * Work around for bad shape files - * + * * @param cwa * @param dataKey * @return @@ -2420,7 +2405,7 @@ public class FFMPTemplates { /** * Get the county info - * + * * @param siteKey * @param countyPfaf * @return @@ -2457,37 +2442,36 @@ public class FFMPTemplates { LocalizationContext lc = pathManager.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile lfTemplateDir = pathManager.getLocalizationFile(lc, - "ffmp/"); + ILocalizationFile[] lfs = pathManager.listFiles(lc, "ffmp/", null, + false, false); - if (lfTemplateDir != null) { - File templateDirFile = lfTemplateDir.getFile(); - if (templateDirFile != null) { - File[] files = templateDirFile.listFiles(); - if (files.length > 0) { - synchronized (files) { - for (File file : files) { - if (file.isDirectory() - && file.listFiles().length > 0) { - for (File iFile : file.listFiles()) { - iFile.delete(); - } - statusHandler.handle( - Priority.INFO, - "Deleted Template directory..." - + file.getName()); - } + if (lfs != null) { + for (ILocalizationFile lf : lfs) { + if (lf.isDirectory()) { + ILocalizationFile[] files = pathManager.listFiles(lc, + lf.getPath(), null, false, true); + for (ILocalizationFile file : files) { + try { + file.delete(); + } catch (LocalizationException e) { + statusHandler + .handle(Priority.PROBLEM, + "Error deleting " + file.getPath(), e); } - - // write out the config XML so templates - // don't keep regening - ftcm.setRegenerate(false); - ftcm.saveConfigXml(); - template = null; } + statusHandler.handle( + Priority.INFO, + "Deleted Template directory..." + + lf.getPath()); } } } + + // write out the config XML so templates + // don't keep regening + ftcm.setRegenerate(false); + ftcm.saveConfigXml(); + template = null; } /** diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/HucLevelGeometriesFactory.java b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/HucLevelGeometriesFactory.java index e12b9ad146..126ff48cab 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/HucLevelGeometriesFactory.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.ffmp/src/com/raytheon/uf/common/dataplugin/ffmp/HucLevelGeometriesFactory.java @@ -1,27 +1,25 @@ /** * 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.common.dataplugin.ffmp; import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStream; import java.lang.ref.SoftReference; import java.util.ArrayList; @@ -33,6 +31,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; @@ -40,12 +39,12 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; -import com.raytheon.uf.common.util.FileUtil; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; @@ -58,11 +57,11 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; * The first time FFMP is loaded the geometries will be simplified and stored to * localization for faster retrieval. All geometries and envelopes are held in * memory by a soft reference or until they are explicitly cleared. - * + * *
- * 
+ *
  * SOFTWARE HISTORY
- * 
+ *
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Dec 9, 2010             rjpeter     Initial creation
@@ -71,9 +70,10 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
  * Apr 25, 2013 1954       bsteffen    Undo last commit to avoid invalid geoms.
  * Jul 03, 2013 2152       rjpeter     Use streams for serialization
  * Nov 12, 2015 4834       njensen     Changed LocalizationOpFailedException to LocalizationException
- * 
+ * Feb 15, 2016 5244       nabowle     Replace deprecated LocalizationFile methods.
+ *
  * 
- * + * * @author rjpeter * @version 1.0 */ @@ -133,23 +133,19 @@ public class HucLevelGeometriesFactory { getGeomPath(dataKey, cwa, huc)); if (f.exists()) { - InputStream is = null; boolean deleteFile = false; + long length = f.getFile().length(); - try { - File file = f.getFile(); - long length = file.length(); + // read from disk in 8k chunks + int bufferSize = 8 * 1024; + if (bufferSize > length) { + bufferSize = (int) length; + } - // read from disk in 8k chunks - int bufferSize = 8 * 1024; - if (bufferSize > length) { - bufferSize = (int) length; - } + try (InputStream is = f.openInputStream(); + GZIPInputStream gis = new GZIPInputStream(is, bufferSize)) { - is = new GZIPInputStream(new FileInputStream(file), - bufferSize); - - map = SerializationUtil.transformFromThrift(Map.class, is); + map = SerializationUtil.transformFromThrift(Map.class, gis); int sizeGuess = Math.max( Math.abs(pfafs.size() - map.size()), 10); pfafsToGenerate = new ArrayList(sizeGuess); @@ -166,14 +162,6 @@ public class HucLevelGeometriesFactory { deleteFile = true; pfafsToGenerate = pfafs; } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e1) { - // ignore - } - } - if (deleteFile) { try { f.delete(); @@ -292,7 +280,7 @@ public class HucLevelGeometriesFactory { /** * Attempts to remove interior holes on a polygon. Will take up to 3 passes * over the polygon expanding any interior rings and merging rings back in. - * + * * @param gf * @param p * @return @@ -317,7 +305,7 @@ public class HucLevelGeometriesFactory { /** * Gets the huc that is one aggregation smaller. - * + * * @param tempate * @param huc * @return @@ -337,7 +325,7 @@ public class HucLevelGeometriesFactory { /** * Returns a map of pfafs to a collection of child pfafs for the child huc. - * + * * @param template * @param cwa * @param huc @@ -387,9 +375,14 @@ public class HucLevelGeometriesFactory { LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); LocalizationFile lf = pathManager.getLocalizationFile(lc, getGeomPath(dataKey, cwa, huc)); - FileUtil.bytes2File(SerializationUtil.transformToThrift(map), - lf.getFile(), true); - lf.save(); + + try (SaveableOutputStream mapSos = lf.openOutputStream(); + GZIPOutputStream mapGos = new GZIPOutputStream(mapSos)) { + mapGos.write(SerializationUtil.transformToThrift(map)); + mapGos.finish(); + mapGos.flush(); + mapSos.save(); + } } protected synchronized String getGeomPath(String dataKey, String cwa, @@ -448,23 +441,18 @@ public class HucLevelGeometriesFactory { getEnvelopePath(dataKey, cwa, huc)); if (f.exists()) { - InputStream is = null; boolean deleteFile = false; + long length = f.getFile().length(); - try { - File file = f.getFile(); - long length = file.length(); + // read from disk in 8k chunks + int bufferSize = 8 * 1024; + if (bufferSize > length) { + bufferSize = (int) length; + } + try (InputStream is = f.openInputStream(); + GZIPInputStream gis = new GZIPInputStream(is, bufferSize)) { - // read from disk in 8k chunks - int bufferSize = 8 * 1024; - if (bufferSize > length) { - bufferSize = (int) length; - } - - is = new GZIPInputStream(new FileInputStream(file), - bufferSize); - - map = SerializationUtil.transformFromThrift(Map.class, is); + map = SerializationUtil.transformFromThrift(Map.class, gis); int sizeGuess = Math.max( Math.abs(pfafs.size() - map.size()), 10); pfafsToGenerate = new ArrayList(sizeGuess); @@ -481,14 +469,6 @@ public class HucLevelGeometriesFactory { deleteFile = true; pfafsToGenerate = pfafs; } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e1) { - // ignore - } - } - if (deleteFile) { try { f.delete(); @@ -534,8 +514,14 @@ public class HucLevelGeometriesFactory { LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); LocalizationFile lf = pathManager.getLocalizationFile(lc, getEnvelopePath(dataKey, cwa, huc)); - FileUtil.bytes2File(SerializationUtil.transformToThrift(map), - lf.getFile(), true); + + try (SaveableOutputStream sos = lf.openOutputStream(); + GZIPOutputStream gos = new GZIPOutputStream(sos)) { + SerializationUtil.transformToThriftUsingStream(map, gos); + gos.finish(); + gos.flush(); + sos.save(); + } } public synchronized void clear() { diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java index 8835b01e67..28067af773 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java @@ -1,24 +1,26 @@ /** * 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.common.dataplugin.grid.dataset; +import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; @@ -28,28 +30,30 @@ import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; 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.serialization.SerializationException; import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; /** - * + * * Provides logic to read datasetInfo files from localization and provide lookup * by datasetId. - * + * *
- * 
+ *
  * SOFTWARE HISTORY
- * 
+ *
  * Date          Ticket#  Engineer    Description
  * ------------- -------- ----------- --------------------------
  * Feb 27, 2012           bsteffen     Initial creation
  * Dec 16, 2013  2574     bsteffen     Update deprecated method call.
  * Jul 21, 2014  3373     bclement     changed to use single type JAXB manager
- * 
+ * Feb 15, 2016  5244     nabowle      Replace deprecated LocalizationFile methods.
+ *
  * 
- * + * * @author bsteffen * @version 1.0 */ @@ -99,15 +103,15 @@ public class DatasetInfoLookup { if (file == null || !file.exists()) { return; } - try { - DatasetInfoSet set = manager.unmarshalFromXmlFile(file - .getFile()); + try (InputStream is = file.openInputStream()) { + DatasetInfoSet set = manager.unmarshalFromInputStream(is); for (DatasetInfo info : set.getInfos()) { infoMap.put(info.getDatasetId(), info); } - } catch (SerializationException e) { + } catch (SerializationException | IOException + | LocalizationException e) { statusHandler.error( - "Error reading dataset info: " + file.getName() + "Error reading dataset info: " + file.getPath() + " has been ignored.", e); } } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/META-INF/MANIFEST.MF index 64a69705ea..6c69d8ac22 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Radar Bundle-SymbolicName: com.raytheon.uf.common.dataplugin.radar -Bundle-Version: 1.14.1.qualifier +Bundle-Version: 1.16.0.qualifier Eclipse-RegisterBuddy: org.geotools Bundle-Vendor: RAYTHEON Require-Bundle: com.raytheon.uf.common.dataplugin;bundle-version="1.12.1174", diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/RadarsInUseUtil.java b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/RadarsInUseUtil.java index e0ff752b60..22ce21ab09 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/RadarsInUseUtil.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/RadarsInUseUtil.java @@ -1,19 +1,19 @@ /** * 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. **/ @@ -21,8 +21,8 @@ package com.raytheon.uf.common.dataplugin.radar.util; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -36,6 +36,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManager; 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.uf.common.status.UFStatus.Priority; @@ -43,16 +44,18 @@ import com.raytheon.uf.common.status.UFStatus.Priority; /** * Provides easy interface to grab configured sites for radar and various other * things - * + * *
- * 
+ *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Jul 14, 2010            mnash     Initial creation
+ * Jul 14, 2010            mnash       Initial creation
+ * Feb 15, 2016 5244       nabowle     Replace deprecated LocalizationFile methods.
  * 
+ *
  * 
- * + * * @author mnash * @version 1.0 */ @@ -118,25 +121,27 @@ public class RadarsInUseUtil { + radarSite + ". Using the base file."); } if (file != null) { - BufferedReader buf = new BufferedReader(new FileReader( - file.getFile())); - String temp = buf.readLine(); - temp = buf.readLine(); - String radarType = ""; - List sites = new ArrayList(); - while (temp != null) { - temp = temp.trim(); - if (temp.startsWith("#")) { - sites = new ArrayList(); - radarType = temp.substring(1, temp.indexOf(" ", 2)); - siteMap.put(radarType.trim(), sites); - } else if (!temp.trim().isEmpty()) { - sites.add(temp); - } + try (BufferedReader buf = new BufferedReader(new InputStreamReader( + file.openInputStream()))) { + String temp = buf.readLine(); temp = buf.readLine(); + String radarType = ""; + List sites = new ArrayList(); + while (temp != null) { + temp = temp.trim(); + if (temp.startsWith("#")) { + sites = new ArrayList(); + radarType = temp.substring(1, temp.indexOf(" ", 2)); + siteMap.put(radarType.trim(), sites); + } else if (!temp.trim().isEmpty()) { + sites.add(temp); + } + temp = buf.readLine(); + } + } catch (LocalizationException e) { + throw new IOException("Error while reading " + file.getPath(), + e); } - buf.close(); - } } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/SsssRadarUtil.java b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/SsssRadarUtil.java index 33579f2b58..ee0546ac45 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/SsssRadarUtil.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.radar/src/com/raytheon/uf/common/dataplugin/radar/util/SsssRadarUtil.java @@ -1,19 +1,19 @@ /** * 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. **/ @@ -21,53 +21,55 @@ package com.raytheon.uf.common.dataplugin.radar.util; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import com.raytheon.uf.common.localization.LocalizationContext; -import com.raytheon.uf.common.localization.LocalizationFile; -import com.raytheon.uf.common.localization.PathManager; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; +import com.raytheon.uf.common.localization.LocalizationFile; +import com.raytheon.uf.common.localization.PathManager; 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.uf.common.status.UFStatus.Priority; /** * TODO Add Description - * + * *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * 03/07/13     DR15495    zwang       Handle SSSS radars
- * 
+ * Feb 15, 2016 5244       nabowle     Replace deprecated LocalizationFile methods.
+ *
  * 
- * + * * @author zwang * @version 1.0 */ public class SsssRadarUtil { - - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(RadarsInUseUtil.class); - - private static final IUFStatusHandler handler = UFStatus - .getHandler(RadarsInUseUtil.class); - - private static List ssssRadars; - private static boolean parsed = false; + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(RadarsInUseUtil.class); + + private static final IUFStatusHandler handler = UFStatus + .getHandler(RadarsInUseUtil.class); + + private static List ssssRadars; + + private static boolean parsed = false; private static synchronized void parseFile() throws IOException{ PathManager pm = (PathManager) PathManagerFactory.getPathManager(); LocalizationContext context = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); - + if (parsed) { return; } @@ -81,48 +83,50 @@ public class SsssRadarUtil { statusHandler.info("File ssssRadars.txt not found "); } else{ - BufferedReader buf = new BufferedReader(new FileReader( - file.getFile())); - String temp = buf.readLine(); - while (temp != null) { - temp = temp.trim(); - if (temp.startsWith("#")) { - // Skip comment lines if any - break; - } else if (!temp.trim().isEmpty()) { - ssssRadars.add(temp); + try (BufferedReader buf = new BufferedReader(new InputStreamReader( + file.openInputStream()))) { + String temp = buf.readLine(); + while (temp != null) { + temp = temp.trim(); + if (temp.startsWith("#")) { + // Skip comment lines if any + break; + } else if (!temp.trim().isEmpty()) { + ssssRadars.add(temp); + } + temp = buf.readLine(); } - temp = buf.readLine(); + } catch (LocalizationException e) { + throw new IOException("Error reading " + file.getPath(), e); } - buf.close(); } } public static List getSsssRadars() { if (parsed) - return ssssRadars; + return ssssRadars; else { - try { - parseFile(); - } catch (IOException e) { - handler.handle(Priority.ERROR, "Error occurred looking up radars", - e); - } + try { + parseFile(); + } catch (IOException e) { + handler.handle(Priority.ERROR, + "Error occurred looking up radars", e); + } } return ssssRadars; } public static boolean isSsssRadar(String radar) { - if (!parsed) { - try { - parseFile(); - } catch (IOException e) { - handler.handle(Priority.ERROR, "Error occurred looking up radars", - e); - } - } - - return ssssRadars.contains(radar); + if (!parsed) { + try { + parseFile(); + } catch (IOException e) { + handler.handle(Priority.ERROR, + "Error occurred looking up radars", e); + } + } + + return ssssRadars.contains(radar); } } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/util/WarnFileUtil.java b/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/util/WarnFileUtil.java index adafb372a7..3d17b9d29a 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/util/WarnFileUtil.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/util/WarnFileUtil.java @@ -1,10 +1,9 @@ package com.raytheon.uf.common.dataplugin.warning.util; import java.io.BufferedReader; -import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import com.raytheon.uf.common.dataplugin.warning.WarningConstants; import com.raytheon.uf.common.localization.IPathManager; @@ -13,6 +12,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.exception.LocalizationException; /** * Utility class to retrieve the appropriate file in localization and in backup @@ -26,6 +26,7 @@ import com.raytheon.uf.common.localization.PathManagerFactory; * ------------ ---------- ----------- -------------------------- * Apr 28, 2014 3033 jsanchez Searches the backup site directory before the localized site directory. * Jul 02, 2014 DR 17450 D. Friedman Support using list of templates from backup site. + * Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods. * * * @author jsanchez @@ -45,7 +46,7 @@ public class WarnFileUtil { * the issuingSiteID is applied. For example, if a file exists in the * issuingSiteID directory then that the file with the returned. Otherwise, * the base level version of the file will be returned. - * + * * @param filename * @param issuingSiteID * (optional) @@ -115,7 +116,7 @@ public class WarnFileUtil { * Locates the appropriate file in the localization hierarchy including the * backupSite directory (if provided) and converts the content of the file * into a string. - * + * * @param filename * @param localizedSite * @param backupSite @@ -126,38 +127,29 @@ public class WarnFileUtil { public static String convertFileContentsToString(String filename, String localizedSite, String backupSite) throws FileNotFoundException, IOException { - File file = findFileInLocalizationIncludingBackupSite(filename, localizedSite, backupSite) - .getFile(); + LocalizationFile file = findFileInLocalizationIncludingBackupSite( + filename, localizedSite, backupSite); return convertFileContentsToString(file); } public static String convertFileContentsToStringNoUser(String filename, String site) throws FileNotFoundException { - File file = findFileInLocalizationIncludingBackupSite(filename, site, null, false).getFile(); + LocalizationFile file = findFileInLocalizationIncludingBackupSite( + filename, site, null, false); return convertFileContentsToString(file); } - private static String convertFileContentsToString(File file) { + private static String convertFileContentsToString(LocalizationFile file) { StringBuffer sb = new StringBuffer(); - BufferedReader input = null; - try { - input = new BufferedReader(new FileReader(file)); + try (BufferedReader input = new BufferedReader(new InputStreamReader( + file.openInputStream()))) { String line = null; while ((line = input.readLine()) != null) { sb.append(line + "\n"); } - } catch (IOException e) { + } catch (IOException | LocalizationException e) { - } finally { - if (input != null) { - try { - input.close(); - input = null; - } catch (Exception e) { - input = null; - } - } } return sb.toString(); } diff --git a/edexOsgi/com.raytheon.uf.common.monitor.cpg/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.monitor.cpg/META-INF/MANIFEST.MF index 602ffcf324..92ef3a3494 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor.cpg/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.monitor.cpg/META-INF/MANIFEST.MF @@ -2,11 +2,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Cpg Plug-in Bundle-SymbolicName: com.raytheon.uf.common.monitor.cpg -Bundle-Version: 1.14.0.qualifier +Bundle-Version: 1.16.0.qualifier Bundle-Vendor: RAYTHEON Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Export-Package: com.raytheon.uf.common.monitor.cpg Require-Bundle: com.raytheon.uf.common.localization;bundle-version="1.11.17", com.raytheon.uf.common.serialization;bundle-version="1.11.26", - com.raytheon.uf.common.serialization.comm;bundle-version="1.11.26" + com.raytheon.uf.common.serialization.comm;bundle-version="1.11.26", + com.raytheon.uf.common.status;bundle-version="1.15.0" diff --git a/edexOsgi/com.raytheon.uf.common.monitor.cpg/src/com/raytheon/uf/common/monitor/cpg/MonitorStateConfigurationManager.java b/edexOsgi/com.raytheon.uf.common.monitor.cpg/src/com/raytheon/uf/common/monitor/cpg/MonitorStateConfigurationManager.java index 8e57b2e6a6..752f94b527 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor.cpg/src/com/raytheon/uf/common/monitor/cpg/MonitorStateConfigurationManager.java +++ b/edexOsgi/com.raytheon.uf.common.monitor.cpg/src/com/raytheon/uf/common/monitor/cpg/MonitorStateConfigurationManager.java @@ -1,25 +1,26 @@ /** * 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.common.monitor.cpg; import java.io.File; +import java.io.InputStream; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; @@ -28,6 +29,9 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; /** * Monitor State Configuration XML File Manager. @@ -39,6 +43,9 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; * ------------ ---------- ----------- -------------------------- * Jan 05, 2009 dhladky Initial creation * Oct 01, 2013 2361 njensen Use JAXBManager for XML + * Feb 15, 2016 5244 nabowle Replace deprecated LocalizationFile methods. + * Replace system.out with UFStatus. + * * * * @@ -48,6 +55,9 @@ import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; public class MonitorStateConfigurationManager { + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(MonitorStateConfigurationManager.class); + /** Path to Monitoring Area Configuration XML. */ private static final String CONFIG_FILE_NAME = "monitoring" + File.separatorChar + "MonitorPluginState.xml"; @@ -71,7 +81,7 @@ public class MonitorStateConfigurationManager { /** * Get an instance of this singleton. - * + * * @return Instance of this class */ public static synchronized MonitorStateConfigurationManager getInstance() { @@ -82,38 +92,6 @@ public class MonitorStateConfigurationManager { return instance; } - /** - * Save the XML configuration data to the current XML file name. - */ - public void saveConfigXml() { - // Save the xml object to disk - IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, - LocalizationLevel.BASE); - LocalizationFile newXmlFile = pm.getLocalizationFile(lc, - CONFIG_FILE_NAME); - - if (newXmlFile.getFile().getParentFile().exists() == false) { - System.out.println("Creating new directory"); - - if (newXmlFile.getFile().getParentFile().mkdirs() == false) { - System.out.println("Could not create new directory..."); - } - } - - try { - System.out.println("Saving -- " - + newXmlFile.getFile().getAbsolutePath()); - jaxb.marshalToXmlFile(configXml, newXmlFile.getFile() - .getAbsolutePath()); - newXmlFile.save(); - } catch (Exception e) { - e.printStackTrace(); - } - - readConfigXml(); - } - /** * Read the XML configuration data for the current XML file name. */ @@ -122,21 +100,24 @@ public class MonitorStateConfigurationManager { IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext lc = pm.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); - File file = pm.getFile(lc, CONFIG_FILE_NAME); - System.out.println("Reading -- " + file.getAbsolutePath()); - MonitorStateXML configXmltmp = jaxb.unmarshalFromXmlFile(file - .getAbsolutePath()); - configXml = configXmltmp; + LocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); + + statusHandler.handle(Priority.INFO, "Reading -- " + lf.getPath()); + try (InputStream is = lf.openInputStream()) { + MonitorStateXML configXmltmp = jaxb + .unmarshalFromInputStream(is); + configXml = configXmltmp; + } } catch (Exception e) { - e.printStackTrace(); - System.err.println("No configuration file found"); + statusHandler.handle(Priority.INFO, "No configuration file found", + e); } } /** * FFMP state - * + * * @return */ public boolean getFFMPState() { @@ -145,7 +126,7 @@ public class MonitorStateConfigurationManager { /** * CWAT state - * + * * @return */ public boolean getCWATState() { @@ -154,7 +135,7 @@ public class MonitorStateConfigurationManager { /** * VIL state - * + * * @return */ public boolean getVILState() { @@ -163,7 +144,7 @@ public class MonitorStateConfigurationManager { /** * QPF state - * + * * @return */ public boolean getQPFState() { @@ -172,7 +153,7 @@ public class MonitorStateConfigurationManager { /** * Fog state - * + * * @return */ public boolean getFogState() { @@ -181,7 +162,7 @@ public class MonitorStateConfigurationManager { /** * Fog state - * + * * @return */ public boolean getPrecipRateState() { @@ -195,10 +176,10 @@ public class MonitorStateConfigurationManager { public boolean getHydroDualPolState() { return configXml.isHydroDualPol(); } - + /** * Fog state - * + * * @return */ public boolean getScanState() { @@ -207,7 +188,7 @@ public class MonitorStateConfigurationManager { /** * Fog state - * + * * @return */ public boolean getFSSState() { diff --git a/edexOsgi/com.raytheon.uf.common.monitor/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.monitor/META-INF/MANIFEST.MF index 7743c6c07e..e7069663e5 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.monitor/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Monitor Plug-in Bundle-SymbolicName: com.raytheon.uf.common.monitor -Bundle-Version: 1.14.0.qualifier +Bundle-Version: 1.16.0.qualifier Bundle-Vendor: RAYTHEON Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFFGXmlMgr.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFFGXmlMgr.java index 11faa51b0d..a54696f70a 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFFGXmlMgr.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFFGXmlMgr.java @@ -21,37 +21,46 @@ package com.raytheon.uf.common.monitor.config; import java.util.ArrayList; +import com.raytheon.uf.common.localization.ILocalizationFile; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.monitor.xml.FFFGDataXML; import com.raytheon.uf.common.monitor.xml.FFFGSourceItemXML; import com.raytheon.uf.common.monitor.xml.FFFGSourceXML; import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; /** - * + * * FFFG XML manager for the master data and the user data. - * + * *
- * 
+ *
  * SOFTWARE HISTORY
- * 
+ *
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Mar 10, 2010 #4517      lvenable    Initial creation
  * Oct 02, 2013  2361      njensen     Use JAXBManager for XML
- * 
+ * Feb 15, 2016  5244      nabowle     Replace deprecated LocalizationFile methods.
+ *                                     Replace System.out calls.
+ *
  * 
- * + * * @author lvenable * @version 1.0 */ public class FFFGXmlMgr { + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(FFFGXmlMgr.class); + private static final SingleTypeJAXBManager jaxb = SingleTypeJAXBManager .createWithoutException(FFFGDataXML.class); @@ -89,7 +98,7 @@ public class FFFGXmlMgr { /** * Constructor. - * + * * @param dataFileName * Data file name. * @param dataFilePath @@ -105,7 +114,7 @@ public class FFFGXmlMgr { /** * Get the data file name. - * + * * @return The data file name. */ public String getDataFileName() { @@ -114,7 +123,7 @@ public class FFFGXmlMgr { /** * Set the data XML. - * + * * @param newDataXML * New data XML. */ @@ -124,7 +133,7 @@ public class FFFGXmlMgr { /** * Get the data XML. - * + * * @return The data XML. */ public FFFGDataXML getXMLData() { @@ -133,7 +142,7 @@ public class FFFGXmlMgr { /** * Load the data file. - * + * * @param dataFileName * Data file name. */ @@ -154,20 +163,19 @@ public class FFFGXmlMgr { IPathManager pm = PathManagerFactory.getPathManager(); String path = pm.getStaticFile(fullPathAndFileName) .getAbsolutePath(); - // System.out.println("*** reading XML path = " + path); dataXML = jaxb.unmarshalFromXmlFile(path); setForcingConfigured(); } catch (Exception e) { - // e.printStackTrace(); - System.out.println("*** FFFGMasterData.xml not available."); + statusHandler.handle(Priority.WARN, + "*** FFFGMasterData.xml not available.", e); dataXML = null; } } /** * Save the XML to a different file name. - * + * * @param newFileName * New file name. */ @@ -186,22 +194,15 @@ public class FFFGXmlMgr { IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext context = pm.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile locFile = pm.getLocalizationFile(context, + ILocalizationFile locFile = pm.getLocalizationFile(context, fullPathAndFileName); - if (locFile.getFile().getParentFile().exists() == false) { - System.out.println("Creating new directory"); + statusHandler.handle(Priority.INFO, + "--- Saving XML path = " + locFile.getPath()); - if (locFile.getFile().getParentFile().mkdirs() == false) { - System.out.println("Could not create new directory..."); - } - } - - try { - System.out.println("--- Saving XML path = " - + locFile.getFile().getAbsolutePath()); - jaxb.marshalToXmlFile(dataXML, locFile.getFile().getAbsolutePath()); - locFile.save(); + try (SaveableOutputStream sos = locFile.openOutputStream()) { + jaxb.marshalToStream(dataXML, sos); + sos.save(); } catch (Exception e) { e.printStackTrace(); } @@ -214,41 +215,47 @@ public class FFFGXmlMgr { */ public void printData() { if (xmlType == FFFGXmlType.MASTER) { - System.out.println("******* Master XML Data *********"); + statusHandler.handle(Priority.INFO, + "******* Master XML Data *********"); } else { - System.out.println("******* User XML Data *********"); + statusHandler.handle(Priority.INFO, + "******* User XML Data *********"); } - System.out.println("Experation Time = " + dataXML.getExpTimeInMillis()); + statusHandler.handle(Priority.INFO, + "Expiration Time = " + dataXML.getExpTimeInMillis()); ArrayList sources = dataXML.getSources(); for (FFFGSourceXML src : sources) { if (src.getSourceName() == null) { - System.out.println("+++ Source Name is null "); + statusHandler.handle(Priority.INFO, "+++ Source Name is null "); } else { - System.out.println("+++ Source Name = " + src.getSourceName()); + statusHandler.handle(Priority.INFO, + "+++ Source Name = " + src.getSourceName()); } if (src.getAreaFFGValue() == null) { - System.out.println("+++ Area FFG is null"); + statusHandler.handle(Priority.INFO, "+++ Area FFG is null"); } else { - System.out - .println("+++ Area FFG = " + src.getAreaFFGValue()); + statusHandler.handle(Priority.INFO, + "+++ Area FFG = " + src.getAreaFFGValue()); } ArrayList srcItems = src.getSourceItems(); if (srcItems == null) { - System.out.println("Source Items are null"); + statusHandler.handle(Priority.INFO, "Source Items are null"); return; } for (FFFGSourceItemXML si : srcItems) { - System.out.println("------ type = " + si.getType()); - System.out.println("------ name = " + si.getName()); - System.out.println("------ id = " + si.getId()); - System.out.println("------ val = " + si.getValue()); + statusHandler.handle( + Priority.INFO, + "------ type = " + si.getType() + "\n------ name = " + + si.getName() + "\n------ id = " + + si.getId() + "\n------ val = " + + si.getValue()); } } } @@ -261,7 +268,7 @@ public class FFFGXmlMgr { /** * Are any forcings configured? - * + * * @return true if forcings are configured */ public boolean isForcingConfigured() { diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPRunConfigurationManager.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPRunConfigurationManager.java index c328065ef1..ae449f1c4c 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPRunConfigurationManager.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPRunConfigurationManager.java @@ -1,37 +1,39 @@ /** * 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.common.monitor.config; -import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.concurrent.CopyOnWriteArrayList; -import com.raytheon.uf.common.localization.FileUpdatedMessage; -import com.raytheon.uf.common.localization.ILocalizationFileObserver; +import com.raytheon.uf.common.localization.ILocalizationFile; +import com.raytheon.uf.common.localization.ILocalizationPathObserver; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; +import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.monitor.events.MonitorConfigEvent; import com.raytheon.uf.common.monitor.events.MonitorConfigListener; import com.raytheon.uf.common.monitor.xml.DomainXML; @@ -48,9 +50,9 @@ import com.raytheon.uf.common.status.UFStatus.Priority; /** * FFMPRunConfigurationManager - * + * *
- * 
+ *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
@@ -58,12 +60,13 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
  * Apr 26, 2013 1954       bsteffen    Minor code cleanup throughout FFMP.
  * Aug 13, 2013 1742       dhladky     Concurrent mod exception on update fixed
  * Oct 02, 2013 2361       njensen     Use JAXBManager for XML
- * 
+ * Feb 15, 2016 5244       nabowle     Replace deprecated LocalizationFile methods.
+ *
  * 
- * + * */ -public class FFMPRunConfigurationManager implements ILocalizationFileObserver { +public class FFMPRunConfigurationManager implements ILocalizationPathObserver { /** Path to FFMP Source config. */ private static final String CONFIG_FILE_NAME = "ffmp" @@ -82,14 +85,12 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { protected boolean isPopulated; - private LocalizationFile lf = null; - private CopyOnWriteArrayList listeners = new CopyOnWriteArrayList(); /** Singleton instance of this class */ private static FFMPRunConfigurationManager instance = new FFMPRunConfigurationManager(); - /* Private Constructor */ + /** Private Constructor */ private FFMPRunConfigurationManager() { isPopulated = false; @@ -103,7 +104,7 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { /** * Get an instance of this singleton. - * + * * @return Instance of this class * @throws FileNotFoundException */ @@ -136,19 +137,23 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - lf.addFileUpdatedObserver(this); - File file = lf.getFile(); + ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); + pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this); // System.out.println("Reading -- " + file.getAbsolutePath()); - if (!file.exists()) { - System.out.println("WARNING [FFMP] FFMPRunConfigurationManager: " - + file.getAbsolutePath() + " does not exist."); + if (!lf.exists()) { + statusHandler.handle(Priority.WARN, lf.getPath() + + " does not exist."); return; } FFMPRunConfigXML configXmltmp = null; - configXmltmp = jaxb.unmarshalFromXmlFile(file.getAbsolutePath()); + try (InputStream is = lf.openInputStream()) { + configXmltmp = jaxb.unmarshalFromInputStream(is); + } catch (IOException | LocalizationException e) { + throw new SerializationException("Error unmarshalling " + + lf.getPath(), e); + } configXml = configXmltmp; isPopulated = true; @@ -164,25 +169,12 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile newXmlFile = pm.getLocalizationFile(lc, + ILocalizationFile newXmlFile = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - if (newXmlFile.getFile().getParentFile().exists() == false) { - // System.out.println("Creating new directory"); - - if (newXmlFile.getFile().getParentFile().mkdirs() == false) { - // System.out.println("Could not create new directory..."); - } - } - - try { - // System.out.println("Saving -- " - // + newXmlFile.getFile().getAbsolutePath()); - jaxb.marshalToXmlFile(configXml, newXmlFile.getFile() - .getAbsolutePath()); - newXmlFile.save(); - - lf = newXmlFile; + try (SaveableOutputStream sos = newXmlFile.openOutputStream()) { + jaxb.marshalToStream(configXml, sos); + sos.save(); } catch (Exception e) { statusHandler.handle(Priority.ERROR, "Couldn't save config file.", e); @@ -191,7 +183,7 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { /** * Get the FFMP runners - * + * * @return */ public ArrayList getFFMPRunners() { @@ -204,7 +196,7 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { /** * Sets the run configuration for FFMP - * + * * @param runners */ public void setFFMPRunners(ArrayList runners) { @@ -272,9 +264,8 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { } @Override - public void fileUpdated(FileUpdatedMessage message) { - - if (message.getFileName().equals(CONFIG_FILE_NAME)) { + public void fileChanged(ILocalizationFile file) { + if (file.getPath().equals(CONFIG_FILE_NAME)) { try { readConfigXml(); @@ -285,7 +276,7 @@ public class FFMPRunConfigurationManager implements ILocalizationFileObserver { } catch (SerializationException e) { statusHandler.handle(Priority.WARN, - "FFMPRunConfigurationManager: " + message.getFileName() + "FFMPRunConfigurationManager: " + file.getPath() + " couldn't be updated.", e); } } diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPSourceConfigurationManager.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPSourceConfigurationManager.java index c56c8ff9c4..da75cf9d35 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPSourceConfigurationManager.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPSourceConfigurationManager.java @@ -1,37 +1,39 @@ /** * 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.common.monitor.config; -import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import com.raytheon.uf.common.localization.FileUpdatedMessage; -import com.raytheon.uf.common.localization.ILocalizationFileObserver; +import com.raytheon.uf.common.localization.ILocalizationFile; +import com.raytheon.uf.common.localization.ILocalizationPathObserver; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; +import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.monitor.events.MonitorConfigEvent; import com.raytheon.uf.common.monitor.events.MonitorConfigListener; import com.raytheon.uf.common.monitor.xml.FFMPSourceConfigXML; @@ -45,9 +47,9 @@ import com.raytheon.uf.common.status.UFStatus.Priority; /** * FFMPSourceConfigurationManager - * + * *
- * 
+ *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
@@ -57,13 +59,14 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
  * Oct 02, 2013  2361      njensen     Use JAXBManager for XML
  * Aug 15, 2015  4722      dhladky     Added new types to be used for new Guidance sources, etc
  * Sep 17, 2015  4756      dhladky     Fixed bugs for multiple guidance sources.
- * 
+ * Feb 15, 2016 5244       nabowle     Replace deprecated LocalizationFile methods.
+ *
  * 
- * + * */ public class FFMPSourceConfigurationManager implements - ILocalizationFileObserver { + ILocalizationPathObserver { /** Path to FFMP Source config. */ private static final String CONFIG_FILE_NAME = "ffmp" @@ -72,10 +75,11 @@ public class FFMPSourceConfigurationManager implements private static final IUFStatusHandler statusHandler = UFStatus .getHandler(FFMPSourceConfigurationManager.class); - // This needs to initialize before the instance since the constructor will - // makes use of JAXB. JVM spec 12.4.2 step 9 indicates this will - // initialize ahead of the instance since it is earlier in - // in the text source. + /* + * This needs to initialize before the instance since the constructor will + * makes use of JAXB. JVM spec 12.4.2 step 9 indicates this will initialize + * ahead of the instance since it is earlier in in the text source. + */ private static final SingleTypeJAXBManager jaxb = SingleTypeJAXBManager .createWithoutException(FFMPSourceConfigXML.class); @@ -97,19 +101,19 @@ public class FFMPSourceConfigurationManager implements private List accumulators = null; - private LocalizationFile lf = null; - private List listeners = new CopyOnWriteArrayList(); /* Private Constructor */ private FFMPSourceConfigurationManager() { configXml = new FFMPSourceConfigXML(); + IPathManager pm = PathManagerFactory.getPathManager(); + pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this); readConfigXml(); } /** * Get an instance of this singleton. - * + * * @return Instance of this class */ public static FFMPSourceConfigurationManager getInstance() { @@ -129,32 +133,32 @@ public class FFMPSourceConfigurationManager implements */ public synchronized void readConfigXml() { IPathManager pm = PathManagerFactory.getPathManager(); - try { LocalizationContext lc = pm.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - lf.addFileUpdatedObserver(this); - File file = lf.getFile(); + ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - FFMPSourceConfigXML configXmltmp = jaxb.unmarshalFromXmlFile(file); - - configXml = configXmltmp; + try (InputStream is = lf.openInputStream()) { + FFMPSourceConfigXML configXmltmp = jaxb + .unmarshalFromInputStream(is); + configXml = configXmltmp; + } } catch (Exception e) { statusHandler.error("No SITE FFMP Source configuration file found"); // fall back to BASE LocalizationContext lc = pm.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.BASE); - lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - lf.addFileUpdatedObserver(this); - File file = lf.getFile(); + ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); FFMPSourceConfigXML configXmltmp = null; - try { - configXmltmp = jaxb.unmarshalFromXmlFile(file); - } catch (SerializationException e1) { + try (InputStream is = lf.openInputStream()) { + configXmltmp = jaxb.unmarshalFromInputStream(is); + + configXml = configXmltmp; + } catch (SerializationException | LocalizationException + | IOException e1) { statusHandler.handle(Priority.ERROR, "Couldn't deserialize file.", e1); } @@ -173,19 +177,12 @@ public class FFMPSourceConfigurationManager implements IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile newXmlFile = pm.getLocalizationFile(lc, + ILocalizationFile newXmlFile = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - File file = newXmlFile.getFile(); - if (file.getParentFile().exists() == false) { - file.getParentFile().mkdirs(); - } - - try { - jaxb.marshalToXmlFile(configXml, file.getAbsolutePath()); - newXmlFile.save(); - lf = newXmlFile; - lf.addFileUpdatedObserver(this); + try (SaveableOutputStream sos = newXmlFile.openOutputStream()) { + jaxb.marshalToStream(configXml, sos); + sos.save(); } catch (Exception e) { statusHandler.handle(Priority.ERROR, "Couldn't save config file.", e); @@ -195,7 +192,7 @@ public class FFMPSourceConfigurationManager implements /** * Gets you your sources for this product - * + * * @param productName * @return */ @@ -205,7 +202,7 @@ public class FFMPSourceConfigurationManager implements /** * Get the rate sourceXML by product - * + * * @return */ public SourceXML getSource(String source) { @@ -214,7 +211,7 @@ public class FFMPSourceConfigurationManager implements /** * source by display name - * + * * @param displayName * @return */ @@ -224,7 +221,7 @@ public class FFMPSourceConfigurationManager implements /** * Get the virtual gage basin implementations - * + * * @param name * @return */ @@ -243,7 +240,7 @@ public class FFMPSourceConfigurationManager implements /** * Get the Guidance sources - * + * * @return */ public ArrayList getGuidances() { @@ -262,7 +259,7 @@ public class FFMPSourceConfigurationManager implements /** * Get the Guidance Display Names - * + * * @return List of display names */ public ArrayList getGuidanceDisplayNames() { @@ -282,7 +279,7 @@ public class FFMPSourceConfigurationManager implements /** * Get the QPE sources - * + * * @return */ public List getQPESources() { @@ -300,7 +297,7 @@ public class FFMPSourceConfigurationManager implements /** * Get the Rate sources - * + * * @return */ public List getRates() { @@ -319,7 +316,7 @@ public class FFMPSourceConfigurationManager implements /** * Get the QPF sources - * + * * @return */ public ArrayList getQPFSources() { @@ -334,10 +331,10 @@ public class FFMPSourceConfigurationManager implements } return forecasts; } - + /** * Get sources with the same family, used for source bins in FFMPGenerator - * + * * @return */ public ArrayList getFamilySources(String family) { @@ -354,9 +351,9 @@ public class FFMPSourceConfigurationManager implements } /** - * + * * Enumeration of the types of FFMP can process - * + * * @author dhladky * @version 1.0 */ @@ -377,9 +374,9 @@ public class FFMPSourceConfigurationManager implements }; /** - * + * * Enumeration of the types of data types - * + * * @author dhladky * @version 1.0 */ @@ -399,9 +396,9 @@ public class FFMPSourceConfigurationManager implements }; /** - * + * * Enumeration of the types of data types - * + * * @author dhladky * @version 1.0 */ @@ -421,9 +418,9 @@ public class FFMPSourceConfigurationManager implements }; /** - * + * * Enumeration of Guidance data types - * + * * @author dhladky * @version 1.0 */ @@ -443,9 +440,9 @@ public class FFMPSourceConfigurationManager implements }; /** - * + * * Enumeration of the types of data FFMP can process - * + * * @author dhladky * @version 1.0 */ @@ -477,7 +474,7 @@ public class FFMPSourceConfigurationManager implements /** * Gets the product XML - * + * * @param productName * @return */ @@ -500,7 +497,7 @@ public class FFMPSourceConfigurationManager implements /** * Finds the primary source this source is within - * + * * @param source * @return */ @@ -514,8 +511,8 @@ public class FFMPSourceConfigurationManager implements } @Override - public void fileUpdated(FileUpdatedMessage message) { - if (message.getFileName().equals(CONFIG_FILE_NAME)) { + public void fileChanged(ILocalizationFile file) { + if (file.getPath().equals(CONFIG_FILE_NAME)) { try { readConfigXml(); // inform listeners @@ -526,11 +523,10 @@ public class FFMPSourceConfigurationManager implements statusHandler.handle( Priority.WARN, "FFMPSourceConfigurationManager: " - + message.getFileName() + + file.getPath() + " couldn't be updated.", e); } } - } } diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPTemplateConfigurationManager.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPTemplateConfigurationManager.java index 4f90df0533..d213090661 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPTemplateConfigurationManager.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFMPTemplateConfigurationManager.java @@ -1,36 +1,37 @@ /** * 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.common.monitor.config; import java.io.File; +import java.io.InputStream; import java.util.ArrayList; import java.util.concurrent.CopyOnWriteArrayList; -import com.raytheon.uf.common.localization.FileUpdatedMessage; -import com.raytheon.uf.common.localization.ILocalizationFileObserver; +import com.raytheon.uf.common.localization.ILocalizationFile; +import com.raytheon.uf.common.localization.ILocalizationPathObserver; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.monitor.events.MonitorConfigEvent; import com.raytheon.uf.common.monitor.events.MonitorConfigListener; import com.raytheon.uf.common.monitor.xml.FFMPTemplateXML; @@ -42,9 +43,9 @@ import com.raytheon.uf.common.status.UFStatus.Priority; /** * Template area configuration xml. - * + * *
- * 
+ *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
@@ -52,14 +53,15 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
  * Oct 25, 2012 DR 15514   gzhang       Adding getHucLevelsInArray()
  * Aug 18, 2013  1742      dhladky      Concurrent mod exception on update fixed
  * Oct 02, 2013  2361      njensen      Use JAXBManager for XML
+ * Feb 15, 2016 5244       nabowle      Replace deprecated LocalizationFile methods.
  * 
- * + * * @author dhladky * @version 1.0 */ public class FFMPTemplateConfigurationManager implements - ILocalizationFileObserver { + ILocalizationPathObserver { /** Path to FFMP Template config. */ private static final String CONFIG_FILE_NAME = "ffmp" + File.separatorChar @@ -78,8 +80,6 @@ public class FFMPTemplateConfigurationManager implements private ArrayList hucLevels = null; - private LocalizationFile lf = null; - private CopyOnWriteArrayList listeners = new CopyOnWriteArrayList(); private static final IUFStatusHandler statusHandler = UFStatus @@ -91,13 +91,12 @@ public class FFMPTemplateConfigurationManager implements IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - lf.addFileUpdatedObserver(this); + pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this); } /** * Get an instance of this singleton. - * + * * @return Instance of this class */ public static synchronized FFMPTemplateConfigurationManager getInstance() { @@ -121,18 +120,15 @@ public class FFMPTemplateConfigurationManager implements */ public void readConfigXml() throws Exception { - if (lf == null) { - IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationContext lc = pm.getContext( - LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - lf.addFileUpdatedObserver(this); - } + IPathManager pm = PathManagerFactory.getPathManager(); + LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, + LocalizationLevel.SITE); + ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - File file = lf.getFile(); - FFMPTemplateXML configXmltmp = jaxb.unmarshalFromXmlFile(file - .getAbsolutePath()); - configXml = configXmltmp; + try (InputStream is = lf.openInputStream()) { + FFMPTemplateXML configXmltmp = jaxb.unmarshalFromInputStream(is); + configXml = configXmltmp; + } } /** @@ -143,25 +139,12 @@ public class FFMPTemplateConfigurationManager implements IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile newXmlFile = pm.getLocalizationFile(lc, + ILocalizationFile newXmlFile = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - if (newXmlFile.getFile().getParentFile().exists() == false) { - // System.out.println("Creating new directory"); - - if (newXmlFile.getFile().getParentFile().mkdirs() == false) { - // System.out.println("Could not create new directory..."); - } - } - - try { - // System.out.println("Saving -- " - // + newXmlFile.getFile().getAbsolutePath()); - jaxb.marshalToXmlFile(configXml, newXmlFile.getFile() - .getAbsolutePath()); - newXmlFile.save(); - - lf = newXmlFile; + try (SaveableOutputStream sos = newXmlFile.openOutputStream()) { + jaxb.marshalToStream(configXml, sos); + sos.save(); } catch (Exception e) { statusHandler.handle(Priority.ERROR, "Couldn't save config file.", e); @@ -170,7 +153,7 @@ public class FFMPTemplateConfigurationManager implements /** * Gets the Huc Depth - * + * * @return */ public int getHucDepth() { @@ -183,7 +166,7 @@ public class FFMPTemplateConfigurationManager implements /** * Do we have virtual basins? - * + * * @return */ public boolean getVirtual() { @@ -196,7 +179,7 @@ public class FFMPTemplateConfigurationManager implements /** * Gets you the number of HUC levels - * + * * @return */ public int getNumberOfHuc() { @@ -209,7 +192,7 @@ public class FFMPTemplateConfigurationManager implements /** * Get HUC Levels. Ordered for template and geometry unification order. - * + * * @return */ public ArrayList getHucLevels() { @@ -256,9 +239,9 @@ public class FFMPTemplateConfigurationManager implements } @Override - public void fileUpdated(FileUpdatedMessage message) { + public void fileChanged(ILocalizationFile localizationFile) { - if (message.getFileName().equals(CONFIG_FILE_NAME)) { + if (localizationFile.getPath().equals(CONFIG_FILE_NAME)) { try { readConfigXml(); // inform listeners @@ -271,7 +254,7 @@ public class FFMPTemplateConfigurationManager implements statusHandler.handle( Priority.WARN, "FFMPTemplateConfigurationManager: " - + message.getFileName() + + localizationFile.getPath() + " couldn't be updated.", e); } } diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFTIDataManager.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFTIDataManager.java index a2e17e509c..8fbb90b776 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFTIDataManager.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/config/FFTIDataManager.java @@ -1,19 +1,19 @@ /** * 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. **/ @@ -21,38 +21,47 @@ package com.raytheon.uf.common.monitor.config; import java.io.File; +import java.io.InputStream; import java.util.ArrayList; -import com.raytheon.uf.common.localization.FileUpdatedMessage; -import com.raytheon.uf.common.localization.ILocalizationFileObserver; +import com.raytheon.uf.common.localization.ILocalizationFile; +import com.raytheon.uf.common.localization.ILocalizationPathObserver; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.monitor.xml.FFTIDataXML; import com.raytheon.uf.common.monitor.xml.FFTISettingXML; import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; /** * Singleton data manager for FFTI. - * + * *
- * 
+ *
  * SOFTWARE HISTORY
- * 
+ *
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * --/--/----                          Initial creation
  * Oct 02, 2013 2361       njensen     Use JAXBManager for XML
- * 
+ * Feb 15, 2016 5244       nabowle     Replace deprecated LocalizationFile methods.
+ *                                     Replace system.out with UFStatus.
+ *
  * 
- * + * * @author lvenable * @version 1.0 */ -public class FFTIDataManager implements ILocalizationFileObserver { +public class FFTIDataManager implements ILocalizationPathObserver { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(FFTIDataManager.class); /** Path to FFTI config. */ private static final String CONFIG_FILE_NAME = "ffmp" + File.separatorChar @@ -73,17 +82,17 @@ public class FFTIDataManager implements ILocalizationFileObserver { */ protected FFTIDataXML configXml; - private LocalizationFile lf = null; - /* Private Constructor */ private FFTIDataManager() { configXml = new FFTIDataXML(); + IPathManager pm = PathManagerFactory.getPathManager(); + pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this); readConfigXml(); } /** * Get an instance of this singleton. - * + * * @return Instance of this class */ public static FFTIDataManager getInstance() { @@ -98,18 +107,16 @@ public class FFTIDataManager implements ILocalizationFileObserver { IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext lc = pm.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - lf.addFileUpdatedObserver(this); + ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - File file = lf.getFile(); - - FFTIDataXML configXmltmp = jaxb.unmarshalFromXmlFile(file - .getAbsolutePath()); - - configXml = configXmltmp; + try (InputStream is = lf.openInputStream()) { + FFTIDataXML configXmltmp = jaxb.unmarshalFromInputStream(is); + configXml = configXmltmp; + } } catch (Exception e) { - System.err.println("No SITE FFTI Source configuration file found."); + statusHandler.handle(Priority.WARN, + "No SITE FFTI Source configuration file found."); } } @@ -121,28 +128,15 @@ public class FFTIDataManager implements ILocalizationFileObserver { IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile newXmlFile = pm.getLocalizationFile(lc, + ILocalizationFile newXmlFile = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); - if (newXmlFile.getFile().getParentFile().exists() == false) { - // System.out.println("Creating new directory"); - - if (newXmlFile.getFile().getParentFile().mkdirs() == false) { - // System.out.println("Could not create new directory..."); - } - } - - try { - // System.out.println("Saving -- " - // + newXmlFile.getFile().getAbsolutePath()); - jaxb.marshalToXmlFile(configXml, newXmlFile.getFile() - .getAbsolutePath()); - newXmlFile.save(); - - lf = newXmlFile; + try (SaveableOutputStream sos = newXmlFile.openOutputStream()) { + jaxb.marshalToStream(configXml, sos); + sos.save(); } catch (Exception e) { - System.err - .println("Failed to save SITE FFTI Source configuration file."); + statusHandler.handle(Priority.WARN, + "Failed to save SITE FFTI Source configuration file."); } } @@ -171,14 +165,15 @@ public class FFTIDataManager implements ILocalizationFileObserver { } @Override - public void fileUpdated(FileUpdatedMessage message) { + public void fileChanged(ILocalizationFile file) { try { - if (message.getFileName().equals(CONFIG_FILE_NAME)) { + if (file.getPath().equals(CONFIG_FILE_NAME)) { readConfigXml(); } } catch (Exception e) { - e.printStackTrace(); + statusHandler.handle(Priority.WARN, "Error handling file changed.", + e); } } diff --git a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/scan/config/TrendSetConfigMgr.java b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/scan/config/TrendSetConfigMgr.java index a4e8e953e7..28038d3155 100644 --- a/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/scan/config/TrendSetConfigMgr.java +++ b/edexOsgi/com.raytheon.uf.common.monitor/src/com/raytheon/uf/common/monitor/scan/config/TrendSetConfigMgr.java @@ -1,60 +1,70 @@ /** * 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.common.monitor.scan.config; import java.io.File; +import java.io.InputStream; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Set; +import com.raytheon.uf.common.localization.ILocalizationFile; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.monitor.scan.xml.SCANTrendSetXML; import com.raytheon.uf.common.monitor.scan.xml.SCANTrendSetsXML; import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; /** - * + * * Manages the Trend Sets configuration. This will handle either CELL or DMD * trend sets. - * + * *
- * 
+ *
  * SOFTWARE HISTORY
- * 
+ *
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Dec 3, 2009  #3039      lvenable    Initial creation
  * Oct 2, 2013   2361      njensen     Use JAXBManager for XML
- * 
+ * Feb 15, 2016 5244       nabowle     Replace deprecated LocalizationFile methods.
+ *                                     Add statusHandler.
+ *
  * 
- * + * * @author lvenable * @version 1.0 */ public class TrendSetConfigMgr { + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(TrendSetConfigMgr.class); + private static final SingleTypeJAXBManager jaxb = SingleTypeJAXBManager .createWithoutException(SCANTrendSetsXML.class); @@ -63,10 +73,6 @@ public class TrendSetConfigMgr { */ private String configXml = null; - /** - * Full XML file path. - */ - private String fullXMLFilePath = null; /** * Trend sets XML. @@ -80,7 +86,7 @@ public class TrendSetConfigMgr { /** * Constructor. - * + * * @param defCfgXML * Default configuration XML name. */ @@ -106,11 +112,14 @@ public class TrendSetConfigMgr { private void readDefaultConfig() { try { IPathManager pm = PathManagerFactory.getPathManager(); - fullXMLFilePath = pm.getStaticFile(getFullConfigFileNameStr()) - .getAbsolutePath(); - trendSets = jaxb.unmarshalFromXmlFile(fullXMLFilePath); + ILocalizationFile file = pm + .getStaticLocalizationFile(getFullConfigFileNameStr()); + try (InputStream is = file.openInputStream()) { + trendSets = jaxb.unmarshalFromInputStream(is); + } } catch (Exception e) { - e.printStackTrace(); + statusHandler.handle(Priority.WARN, + "Error reading default config.", e); } } @@ -130,7 +139,7 @@ public class TrendSetConfigMgr { /** * Get the full path/file name of the configuration XML. - * + * * @return Full file name and path. */ private String getFullConfigFileNameStr() { @@ -143,7 +152,7 @@ public class TrendSetConfigMgr { /** * Get the trend sets map. - * + * * @return The trend sets map. */ public final LinkedHashMap getTrendSetMap() { @@ -152,7 +161,7 @@ public class TrendSetConfigMgr { /** * Get the trend sets configuration XML. - * + * * @return The trend sets configuration XML. */ public SCANTrendSetsXML getTrendSets() { @@ -186,29 +195,20 @@ public class TrendSetConfigMgr { IPathManager pm = PathManagerFactory.getPathManager(); LocalizationContext context = pm.getContext( LocalizationType.CAVE_STATIC, LocalizationLevel.SITE); - LocalizationFile locFile = pm.getLocalizationFile(context, + ILocalizationFile locFile = pm.getLocalizationFile(context, getFullConfigFileNameStr()); - if (locFile.getFile().exists() == false) { - if (locFile.getFile().getParentFile().mkdirs() == false) { - System.out.println("Did not not create directory(ies): " - + locFile.getFile().getAbsolutePath()); - } - } - - try { - jaxb.marshalToXmlFile(trendSets, locFile.getFile() - .getAbsolutePath()); - - locFile.save(); + try (SaveableOutputStream sos = locFile.openOutputStream()) { + jaxb.marshalToStream(trendSets, sos); + sos.save(); } catch (Exception e) { - e.printStackTrace(); + statusHandler.handle(Priority.WARN, "Error saving trend sets.", e); } } /** * Remove a trend set. - * + * * @param name * Trend set name to remove. */ @@ -218,7 +218,7 @@ public class TrendSetConfigMgr { /** * Add/Update a trend set. - * + * * @param name * @param attibute */ @@ -228,7 +228,7 @@ public class TrendSetConfigMgr { /** * Get a list of trend sets that do not have at least 2 attributes. - * + * * @return Array on trend set names. */ public String[] getInvalidAttributeNumber() { @@ -248,7 +248,7 @@ public class TrendSetConfigMgr { /** * Get a string array of attributes for the specified trend set name. - * + * * @param trendName * Trend set name. * @return String array of attributes. @@ -264,7 +264,7 @@ public class TrendSetConfigMgr { /** * Get an array on trend set names. - * + * * @return Array of trend set names. */ public String[] getTrendSetNames() {