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.fog.FogRecord.FOG_THREAT;
import com.raytheon.uf.common.geospatial.SpatialException;
import com.raytheon.uf.common.monitor.MonitorAreaUtils;
import com.raytheon.uf.common.monitor.config.FogMonitorConfigurationManager;
import com.raytheon.uf.common.monitor.data.AdjacentWfoMgr;
@ -145,12 +146,11 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
private Geometry geoAdjAreas = null;
/** Data URI pattern for fog **/
private final Pattern fogPattern = Pattern.compile(DataURI.SEPARATOR
+ OBS + DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR
+ wildCard + DataURI.SEPARATOR + cwa + DataURI.SEPARATOR
+ wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR
+ "fog");
private final Pattern fogPattern = Pattern.compile(DataURI.SEPARATOR + OBS
+ DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + cwa + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + "fog");
/**
* Private constructor, singleton
@ -490,6 +490,7 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
public void algorithmUpdate() {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
Iterator<IFogResourceListener> iter = fogResources.iterator();
@ -524,6 +525,7 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
*
* @param drawTime
*/
@Override
public void updateDialogTime(Date dialogTime) {
this.dialogTime = dialogTime;
fireMonitorEvent(zoneDialog.getClass().getName());
@ -549,6 +551,7 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
* com.raytheon.uf.viz.monitor.fog.listeners.IFogResourceListener#closeDialog
* ()
*/
@Override
public void closeDialog() {
if (zoneDialog != null) {
monitor.removeMonitorListener(zoneDialog);
@ -586,7 +589,11 @@ public class FogMonitor extends ObsMonitor implements IFogResourceListener {
* Get adjacent areas.
*/
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.fog.FogRecord;
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.config.SSMonitorConfigurationManager;
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>();
/** Pattern for SAFESEAS **/
private final Pattern ssPattern = Pattern
.compile(DataURI.SEPARATOR + OBS + DataURI.SEPARATOR
+ wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + cwa + DataURI.SEPARATOR
+ wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + "ss");
private final Pattern ssPattern = Pattern.compile(DataURI.SEPARATOR + OBS
+ DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + cwa + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + wildCard + DataURI.SEPARATOR + wildCard
+ DataURI.SEPARATOR + "ss");
/**
* Private constructor, singleton
@ -411,6 +410,7 @@ public class SafeSeasMonitor extends ObsMonitor implements ISSResourceListener {
*
* @param dialogTime
*/
@Override
public void updateDialogTime(Date dialogTime) {
this.dialogTime = dialogTime;
fireMonitorEvent(zoneDialog.getClass().getName());
@ -586,7 +586,11 @@ public class SafeSeasMonitor extends ObsMonitor implements ISSResourceListener {
* Gets adjacent areas
*/
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
public void fogUpdate() {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
Iterator<ISSResourceListener> iter = fogResources.iterator();
while (iter.hasNext()) {

View file

@ -20,6 +20,7 @@
package com.raytheon.uf.common.monitor.data;
import java.util.ArrayList;
import java.util.List;
import com.raytheon.uf.common.geospatial.ISpatialQuery;
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.site.xml.AdjacentWfoXML;
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.io.WKBReader;
@ -44,7 +48,8 @@ import com.vividsolutions.jts.io.WKBReader;
* SOFTWARE HISTORY
* 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>
*
@ -53,6 +58,9 @@ import com.vividsolutions.jts.io.WKBReader;
*/
public class AdjacentWfoMgr {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(AdjacentWfoMgr.class);
/** Configuration XML. */
private AdjacentWfoXML adjXML = null;
@ -65,16 +73,17 @@ public class AdjacentWfoMgr {
/** Path to Adjacent WFO XML. */
private static final String fileName = "allAdjacentWFOs.xml";
private Geometry geoAdjAreas = null;
/** Adjacent area geometry */
private Geometry geoAdjAreas = null;
/**
* Constructor.
*
* @param fullPath
* The full path the the configuration XML file.
* @param currentSite
* The current site
*/
public AdjacentWfoMgr(String currentSite) {
System.out.println("**********************AdjacentWfoMgr instantiated with "
statusHandler.debug("****AdjacentWfoMgr instantiated with "
+ currentSite);
this.currentSite = currentSite;
readAdjXml();
@ -92,12 +101,12 @@ public class AdjacentWfoMgr {
String path = pm.getFile(
pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.BASE), fileName)
.getAbsolutePath();
.getAbsolutePath();
System.out.println("**** path = " + path);
statusHandler.debug("**** path = " + path);
adjXML = (AdjacentWfoXML) SerializationUtil
.jaxbUnmarshalFromXmlFile(path.toString());
adjXML = SerializationUtil.jaxbUnmarshalFromXmlFile(
AdjacentWfoXML.class, path);
ArrayList<CwaXML> list = adjXML.getAreaIds();
for (CwaXML cx : list) {
@ -110,37 +119,10 @@ public class AdjacentWfoMgr {
}
}
} 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
*/
@ -176,91 +158,108 @@ public class AdjacentWfoMgr {
return idList;
}
/**
* Gets geometry of all adjacent CWAs
*
* @param wfo
* @return
*/
public static Geometry getAdjacentAreas(String wfo) {
/**
* Gets geometry of all adjacent CWAs
*
* @param wfo
* The WFO
* @return The adjacent Geometry
* @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);
AdjacentWfoMgr adjMgr = new AdjacentWfoMgr(wfo);
Geometry adjAreaGeometry = getCwaGeomtry(wfo);
if (adjAreaGeometry == null) {
throw new SpatialException("CWA Geometry is null for " + wfo);
}
for (String area : adjMgr.getAdjIdList()) {
Geometry areaGeo = getCwaGeomtry(area);
adjAreaGeometry = adjAreaGeometry.union(areaGeo);
}
AdjacentWfoMgr adjMgr = new AdjacentWfoMgr(wfo);
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);
}
/**
* Gets you the CWA geometry
*
* @param cwa
* @return
*/
public static Geometry getCwaGeomtry(String cwa) {
if (invalidGeom) {
StringBuilder sb = new StringBuilder("Missing geometries for:");
for (String site : areaList) {
sb.append(StringUtil.NEWLINE).append(site);
}
UFStatus.getHandler(AdjacentWfoMgr.class).warn(sb.toString());
}
ISpatialQuery sq = null;
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 + "'";
return adjAreaGeometry;
}
try {
sq = SpatialQueryFactory.create();
Object[] results = sq.dbRequest(sql, "maps");
if (results.length > 0) {
geo = MonitorAreaUtils.readGeometry(results[0], wkbReader);
}
// marine zones
Object[] mresults = sq.dbRequest(msql, "maps");
if (mresults.length > 0) {
for (Object res : mresults) {
if (res instanceof Object[]) {
res = ((Object[]) res)[0];
}
Geometry mgeo = MonitorAreaUtils.readGeometry(res,
wkbReader);
geo = geo.union(mgeo);
}
}
} catch (SpatialException e) {
e.printStackTrace();
}
return geo;
// return geo.convexHull(); ????
}
/**
* Gets you the CWA geometry
*
* @param cwa
* The CWA
* @return The Geometry for the CWA
*/
public static Geometry getCwaGeomtry(String cwa) {
ISpatialQuery sq = null;
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 + "'";
// /**
// * extract geometry
// *
// * @param object
// * @return
// */
//
// private static Geometry readGeometry(Object object, WKBReader wkbReader)
// {
// Geometry geometry = null;
// try {
// geometry = wkbReader.read((byte[]) object);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// return geometry.buffer(0);
// }
try {
sq = SpatialQueryFactory.create();
Object[] results = sq.dbRequest(sql, "maps");
if (results.length > 0) {
geo = MonitorAreaUtils.readGeometry(results[0], wkbReader);
}
// marine zones
Object[] mresults = sq.dbRequest(msql, "maps");
if (mresults.length > 0) {
for (Object res : mresults) {
if (res instanceof Object[]) {
res = ((Object[]) res)[0];
}
Geometry mgeo = MonitorAreaUtils.readGeometry(res,
wkbReader);
geo = geo.union(mgeo);
}
}
} catch (SpatialException e) {
UFStatus.getHandler(AdjacentWfoMgr.class).error(
"Error getting CWA Geometry", e);
}
public void setGeoAdjAreas(Geometry geoAdjAreas) {
this.geoAdjAreas = geoAdjAreas;
}
return geo;
}
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;
}
}