Issue #2217 - Added better error handling

Change-Id: Ia15b57fbee9e3cecb93ac711ca3d99529df3ac00

Former-commit-id: 45b0119059 [formerly 8ac8e405ec] [formerly e584ddbf45 [formerly b7a602066d1c01a9b6399d2dade3ed3dd487103e]]
Former-commit-id: e584ddbf45
Former-commit-id: f98a232c8b
This commit is contained in:
Mike Duff 2013-07-24 13:54:33 -05:00
parent fe41d0e590
commit b808324f11
3 changed files with 140 additions and 129 deletions

View file

@ -37,6 +37,7 @@ import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.dataplugin.annotations.DataURI; import com.raytheon.uf.common.dataplugin.annotations.DataURI;
import com.raytheon.uf.common.dataplugin.fog.FogRecord.FOG_THREAT; import com.raytheon.uf.common.dataplugin.fog.FogRecord.FOG_THREAT;
import com.raytheon.uf.common.geospatial.SpatialException;
import com.raytheon.uf.common.monitor.MonitorAreaUtils; import com.raytheon.uf.common.monitor.MonitorAreaUtils;
import com.raytheon.uf.common.monitor.config.FogMonitorConfigurationManager; import com.raytheon.uf.common.monitor.config.FogMonitorConfigurationManager;
import com.raytheon.uf.common.monitor.data.AdjacentWfoMgr; import com.raytheon.uf.common.monitor.data.AdjacentWfoMgr;
@ -145,12 +146,11 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
private Geometry geoAdjAreas = null; private Geometry geoAdjAreas = null;
/** Data URI pattern for fog **/ /** Data URI pattern for fog **/
private final Pattern fogPattern = Pattern.compile(DataURI.SEPARATOR private final Pattern fogPattern = Pattern.compile(DataURI.SEPARATOR + OBS
+ OBS + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ wildCard + DataURI.SEPARATOR + cwa + DataURI.SEPARATOR + DataURI.SEPARATOR + cwa + DataURI.SEPARATOR + wildCard
+ wildCard + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + DataURI.SEPARATOR + "fog");
+ "fog");
/** /**
* Private constructor, singleton * Private constructor, singleton
@ -490,6 +490,7 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
public void algorithmUpdate() { public void algorithmUpdate() {
Display.getDefault().asyncExec(new Runnable() { Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() { public void run() {
Iterator<IFogResourceListener> iter = fogResources.iterator(); Iterator<IFogResourceListener> iter = fogResources.iterator();
@ -524,6 +525,7 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
* *
* @param drawTime * @param drawTime
*/ */
@Override
public void updateDialogTime(Date dialogTime) { public void updateDialogTime(Date dialogTime) {
this.dialogTime = dialogTime; this.dialogTime = dialogTime;
fireMonitorEvent(zoneDialog.getClass().getName()); fireMonitorEvent(zoneDialog.getClass().getName());
@ -549,6 +551,7 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
* com.raytheon.uf.viz.monitor.fog.listeners.IFogResourceListener#closeDialog * com.raytheon.uf.viz.monitor.fog.listeners.IFogResourceListener#closeDialog
* () * ()
*/ */
@Override
public void closeDialog() { public void closeDialog() {
if (zoneDialog != null) { if (zoneDialog != null) {
monitor.removeMonitorListener(zoneDialog); monitor.removeMonitorListener(zoneDialog);
@ -586,7 +589,11 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
* Get adjacent areas. * Get adjacent areas.
*/ */
public void getAdjAreas() { public void getAdjAreas() {
this.geoAdjAreas = AdjacentWfoMgr.getAdjacentAreas(cwa); try {
this.geoAdjAreas = AdjacentWfoMgr.getAdjacentAreas(cwa);
} catch (SpatialException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
} }
/** /**

View file

@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.dataplugin.annotations.DataURI; import com.raytheon.uf.common.dataplugin.annotations.DataURI;
import com.raytheon.uf.common.dataplugin.fog.FogRecord; import com.raytheon.uf.common.dataplugin.fog.FogRecord;
import com.raytheon.uf.common.dataplugin.fog.FogRecord.FOG_THREAT; import com.raytheon.uf.common.dataplugin.fog.FogRecord.FOG_THREAT;
import com.raytheon.uf.common.geospatial.SpatialException;
import com.raytheon.uf.common.monitor.MonitorAreaUtils; import com.raytheon.uf.common.monitor.MonitorAreaUtils;
import com.raytheon.uf.common.monitor.config.SSMonitorConfigurationManager; import com.raytheon.uf.common.monitor.config.SSMonitorConfigurationManager;
import com.raytheon.uf.common.monitor.data.AdjacentWfoMgr; import com.raytheon.uf.common.monitor.data.AdjacentWfoMgr;
@ -147,13 +148,11 @@ public class SafeSeasMonitor extends ObsMonitor implements ISSResourceListener {
private final List<ISSResourceListener> fogResources = new ArrayList<ISSResourceListener>(); private final List<ISSResourceListener> fogResources = new ArrayList<ISSResourceListener>();
/** Pattern for SAFESEAS **/ /** Pattern for SAFESEAS **/
private final Pattern ssPattern = Pattern private final Pattern ssPattern = Pattern.compile(DataURI.SEPARATOR + OBS
.compile(DataURI.SEPARATOR + OBS + DataURI.SEPARATOR + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ wildCard + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + cwa + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + cwa + DataURI.SEPARATOR + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ wildCard + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + "ss");
+ DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + "ss");
/** /**
* Private constructor, singleton * Private constructor, singleton
@ -411,6 +410,7 @@ public class SafeSeasMonitor extends ObsMonitor implements ISSResourceListener {
* *
* @param dialogTime * @param dialogTime
*/ */
@Override
public void updateDialogTime(Date dialogTime) { public void updateDialogTime(Date dialogTime) {
this.dialogTime = dialogTime; this.dialogTime = dialogTime;
fireMonitorEvent(zoneDialog.getClass().getName()); fireMonitorEvent(zoneDialog.getClass().getName());
@ -586,7 +586,11 @@ public class SafeSeasMonitor extends ObsMonitor implements ISSResourceListener {
* Gets adjacent areas * Gets adjacent areas
*/ */
public void getAdjAreas() { public void getAdjAreas() {
this.setGeoAdjAreas(AdjacentWfoMgr.getAdjacentAreas(cwa)); try {
this.setGeoAdjAreas(AdjacentWfoMgr.getAdjacentAreas(cwa));
} catch (SpatialException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
} }
/** /**
@ -620,6 +624,7 @@ public class SafeSeasMonitor extends ObsMonitor implements ISSResourceListener {
@Override @Override
public void fogUpdate() { public void fogUpdate() {
Display.getDefault().asyncExec(new Runnable() { Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() { public void run() {
Iterator<ISSResourceListener> iter = fogResources.iterator(); Iterator<ISSResourceListener> iter = fogResources.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {

View file

@ -20,6 +20,7 @@
package com.raytheon.uf.common.monitor.data; package com.raytheon.uf.common.monitor.data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import com.raytheon.uf.common.geospatial.ISpatialQuery; import com.raytheon.uf.common.geospatial.ISpatialQuery;
import com.raytheon.uf.common.geospatial.SpatialException; import com.raytheon.uf.common.geospatial.SpatialException;
@ -33,6 +34,9 @@ import com.raytheon.uf.common.monitor.scan.ScanUtils;
import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.site.xml.AdjacentWfoXML; import com.raytheon.uf.common.site.xml.AdjacentWfoXML;
import com.raytheon.uf.common.site.xml.CwaXML; import com.raytheon.uf.common.site.xml.CwaXML;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.util.StringUtil;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKBReader; import com.vividsolutions.jts.io.WKBReader;
@ -44,7 +48,8 @@ import com.vividsolutions.jts.io.WKBReader;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Dec 22, 2009 mpduff Initial creation * Dec 22, 2009 mpduff Initial creation
* Jul 24, 2013 2219 mpduff Improve error handling.
* *
* </pre> * </pre>
* *
@ -53,6 +58,9 @@ import com.vividsolutions.jts.io.WKBReader;
*/ */
public class AdjacentWfoMgr { public class AdjacentWfoMgr {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(AdjacentWfoMgr.class);
/** Configuration XML. */ /** Configuration XML. */
private AdjacentWfoXML adjXML = null; private AdjacentWfoXML adjXML = null;
@ -65,16 +73,17 @@ public class AdjacentWfoMgr {
/** Path to Adjacent WFO XML. */ /** Path to Adjacent WFO XML. */
private static final String fileName = "allAdjacentWFOs.xml"; private static final String fileName = "allAdjacentWFOs.xml";
private Geometry geoAdjAreas = null; /** Adjacent area geometry */
private Geometry geoAdjAreas = null;
/** /**
* Constructor. * Constructor.
* *
* @param fullPath * @param currentSite
* The full path the the configuration XML file. * The current site
*/ */
public AdjacentWfoMgr(String currentSite) { public AdjacentWfoMgr(String currentSite) {
System.out.println("**********************AdjacentWfoMgr instantiated with " statusHandler.debug("****AdjacentWfoMgr instantiated with "
+ currentSite); + currentSite);
this.currentSite = currentSite; this.currentSite = currentSite;
readAdjXml(); readAdjXml();
@ -92,12 +101,12 @@ public class AdjacentWfoMgr {
String path = pm.getFile( String path = pm.getFile(
pm.getContext(LocalizationType.COMMON_STATIC, pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.BASE), fileName) LocalizationLevel.BASE), fileName)
.getAbsolutePath(); .getAbsolutePath();
System.out.println("**** path = " + path); statusHandler.debug("**** path = " + path);
adjXML = (AdjacentWfoXML) SerializationUtil adjXML = SerializationUtil.jaxbUnmarshalFromXmlFile(
.jaxbUnmarshalFromXmlFile(path.toString()); AdjacentWfoXML.class, path);
ArrayList<CwaXML> list = adjXML.getAreaIds(); ArrayList<CwaXML> list = adjXML.getAreaIds();
for (CwaXML cx : list) { for (CwaXML cx : list) {
@ -110,37 +119,10 @@ public class AdjacentWfoMgr {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); statusHandler.error("Error setting up adjacent WFO data", e);
} }
} }
/**
* Save the XML adjacent data to the current XML file name.
*/
// public void saveAdjXml() {
// IPathManager pm = PathManagerFactory.getPathManager();
// LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
// LocalizationLevel.SITE);
// LocalizationFile newXmlFile = pm.getLocalizationFile(lc, fileName);
//
// 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());
// SerializationUtil.jaxbMarshalToXmlFile(adjXML, newXmlFile
// .getFile().getAbsolutePath());
// newXmlFile.save();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
/** /**
* @return the adjXML * @return the adjXML
*/ */
@ -176,91 +158,108 @@ public class AdjacentWfoMgr {
return idList; return idList;
} }
/** /**
* Gets geometry of all adjacent CWAs * Gets geometry of all adjacent CWAs
* *
* @param wfo * @param wfo
* @return * The WFO
*/ * @return The adjacent Geometry
public static Geometry getAdjacentAreas(String wfo) { * @throws SpatialException
* if problem with wfo geometry
*/
public static Geometry getAdjacentAreas(String wfo) throws SpatialException {
boolean invalidGeom = false;
List<String> areaList = new ArrayList<String>();
Geometry adjAreaGeometry = getCwaGeomtry(wfo); Geometry adjAreaGeometry = getCwaGeomtry(wfo);
AdjacentWfoMgr adjMgr = new AdjacentWfoMgr(wfo); if (adjAreaGeometry == null) {
throw new SpatialException("CWA Geometry is null for " + wfo);
}
for (String area : adjMgr.getAdjIdList()) { AdjacentWfoMgr adjMgr = new AdjacentWfoMgr(wfo);
Geometry areaGeo = getCwaGeomtry(area);
adjAreaGeometry = adjAreaGeometry.union(areaGeo);
}
return adjAreaGeometry; for (String area : adjMgr.getAdjIdList()) {
} Geometry areaGeo = getCwaGeomtry(area);
// verify areaGeo is not null
if (areaGeo == null) {
invalidGeom = true;
areaList.add(area);
continue;
}
adjAreaGeometry = adjAreaGeometry.union(areaGeo);
}
/** if (invalidGeom) {
* Gets you the CWA geometry StringBuilder sb = new StringBuilder("Missing geometries for:");
* for (String site : areaList) {
* @param cwa sb.append(StringUtil.NEWLINE).append(site);
* @return }
*/ UFStatus.getHandler(AdjacentWfoMgr.class).warn(sb.toString());
public static Geometry getCwaGeomtry(String cwa) { }
ISpatialQuery sq = null; return adjAreaGeometry;
Geometry geo = null; }
WKBReader wkbReader = new WKBReader();
String sql = "select AsBinary(" + ScanUtils.getStandardResolutionLevel("cwa") + ") from mapdata.cwa where cwa = '"
+ cwa + "'";
String msql = "select AsBinary(" + ScanUtils.getStandardResolutionLevel("marinezones") + ") from mapdata.marinezones where wfo = '"
+ cwa + "'";
try { /**
sq = SpatialQueryFactory.create(); * Gets you the CWA geometry
Object[] results = sq.dbRequest(sql, "maps"); *
if (results.length > 0) { * @param cwa
geo = MonitorAreaUtils.readGeometry(results[0], wkbReader); * The CWA
} * @return The Geometry for the CWA
// marine zones */
Object[] mresults = sq.dbRequest(msql, "maps"); public static Geometry getCwaGeomtry(String cwa) {
if (mresults.length > 0) { ISpatialQuery sq = null;
for (Object res : mresults) { Geometry geo = null;
if (res instanceof Object[]) { WKBReader wkbReader = new WKBReader();
res = ((Object[]) res)[0]; String sql = "select AsBinary("
} + ScanUtils.getStandardResolutionLevel("cwa")
Geometry mgeo = MonitorAreaUtils.readGeometry(res, + ") from mapdata.cwa where cwa = '" + cwa + "'";
wkbReader); String msql = "select AsBinary("
geo = geo.union(mgeo); + ScanUtils.getStandardResolutionLevel("marinezones")
} + ") from mapdata.marinezones where wfo = '" + cwa + "'";
}
} catch (SpatialException e) {
e.printStackTrace();
}
return geo;
// return geo.convexHull(); ????
}
// /** try {
// * extract geometry sq = SpatialQueryFactory.create();
// * Object[] results = sq.dbRequest(sql, "maps");
// * @param object if (results.length > 0) {
// * @return geo = MonitorAreaUtils.readGeometry(results[0], wkbReader);
// */ }
// // marine zones
// private static Geometry readGeometry(Object object, WKBReader wkbReader) Object[] mresults = sq.dbRequest(msql, "maps");
// { if (mresults.length > 0) {
// Geometry geometry = null; for (Object res : mresults) {
// try { if (res instanceof Object[]) {
// geometry = wkbReader.read((byte[]) object); res = ((Object[]) res)[0];
// } catch (Exception e) { }
// e.printStackTrace(); Geometry mgeo = MonitorAreaUtils.readGeometry(res,
// } wkbReader);
// geo = geo.union(mgeo);
// return geometry.buffer(0); }
// } }
} catch (SpatialException e) {
UFStatus.getHandler(AdjacentWfoMgr.class).error(
"Error getting CWA Geometry", e);
}
public void setGeoAdjAreas(Geometry geoAdjAreas) { return geo;
this.geoAdjAreas = geoAdjAreas; }
}
public Geometry getGeoAdjAreas() { /**
return geoAdjAreas; * Set the geometry for adjacent areas
} *
* @param geoAdjAreas
* The geometry
*/
public void setGeoAdjAreas(Geometry geoAdjAreas) {
this.geoAdjAreas = geoAdjAreas;
}
/**
* Get the geometry for adjacent areas
*
* @return The geometry
*/
public Geometry getGeoAdjAreas() {
return geoAdjAreas;
}
} }