Omaha #4354: Fix NullPointerException in OpenGeoJsonPropertiesDlgAction,

remove support for loading 15.1 damage path output format.

Change-Id: I3980769f1e429de324b1ae08ee599b17aceb32c6

Former-commit-id: 2f497367f2967e19c394ba97d8ea4a67803f4269
This commit is contained in:
David Gillingham 2015-06-30 15:26:12 -05:00
parent 40e2c9acc9
commit 0168e82627
4 changed files with 19 additions and 95 deletions

View file

@ -26,7 +26,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@ -38,7 +37,6 @@ import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.Name;
import com.raytheon.uf.common.json.JsonException;
import com.raytheon.uf.common.json.geo.BasicJsonService;
import com.raytheon.uf.common.json.geo.GeoJsonMapUtil;
import com.raytheon.uf.common.json.geo.IGeoJsonService;
import com.raytheon.uf.common.json.geo.SimpleGeoJsonService;
@ -62,6 +60,8 @@ import com.vividsolutions.jts.operation.valid.IsValidOp;
* Jun 05, 2015 #4375 dgilling Initial creation
* Jun 18, 2015 #4354 dgilling Support FeatureCollections so each polygon
* can have its own properties.
* Jun 30, 2015 #4354 dgilling Remove unnecessary back compat code for
* 15.1 version of damage path tool.
*
* </pre>
*
@ -71,8 +71,6 @@ import com.vividsolutions.jts.operation.valid.IsValidOp;
public final class DamagePathLoader {
private static final String UNSUPPORTED_GEOJSON_TYPE = "Damage path file is unsupported GeoJSON object type %s. This tool only supports Feature and Geometry objects.";
private static final String UNSUPPORTED_GEOM_TYPE = "Damage path file contains invalid geometry type %s at geometry index %d. Must only contain Polygons.";
private static final String INVALID_POLYGON = "Damage path file contains an invalid Polyon at index %d: %s";
@ -119,85 +117,6 @@ public final class DamagePathLoader {
}
private void loadFromInputStream(final InputStream is) throws JsonException {
Geometry deserializedGeom = null;
Map<String, String> deserializedProps = Collections.emptyMap();
GeoJsonMapUtil geoJsonUtil = new GeoJsonMapUtil();
/*
* For compatibility with any users that may have an autosaved damage
* path file from previous builds, we'll support deserializing Geometry,
* Feature and FeatureCollection GeoJSON types.
*
* TODO: remove this code for code that just expects the file to always
* be a FeatureCollection.
*/
Map<String, Object> jsonObject = (Map<String, Object>) new BasicJsonService()
.deserialize(is, LinkedHashMap.class);
String geoJsonType = jsonObject.get(GeoJsonMapUtil.TYPE_KEY).toString();
if (geoJsonType.equals(GeoJsonMapUtil.FEATURE_COLL_TYPE)) {
FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = geoJsonUtil
.populateFeatureCollection(jsonObject);
populateDataFromFeatureCollection(featureCollection);
return;
} else if (geoJsonType.equals(GeoJsonMapUtil.FEATURE_TYPE)) {
SimpleFeature feature = geoJsonUtil.populateFeature(jsonObject);
deserializedGeom = (Geometry) feature.getDefaultGeometry();
Name defaultGeomAttrib = feature.getDefaultGeometryProperty()
.getName();
deserializedProps = new LinkedHashMap<>();
deserializedProps.put(GeoJsonMapUtil.ID_KEY, feature.getID());
for (Property p : feature.getProperties()) {
if (!defaultGeomAttrib.equals(p.getName())) {
deserializedProps.put(p.getName().toString(), p.getValue()
.toString());
}
}
} else if (isGeometryType(geoJsonType)) {
deserializedGeom = geoJsonUtil.populateGeometry(jsonObject);
} else {
throw new JsonException(String.format(UNSUPPORTED_GEOJSON_TYPE,
geoJsonType));
}
int numGeometries = deserializedGeom.getNumGeometries();
for (int i = 0; i < numGeometries; i++) {
Geometry geomN = deserializedGeom.getGeometryN(i);
if (geomN instanceof Polygon) {
Polygon newPolygon = (Polygon) geomN;
IsValidOp validator = new IsValidOp(newPolygon);
if (validator.isValid()) {
Pair<Polygon, Map<String, String>> polygonAndProps = new Pair<>(
newPolygon, deserializedProps);
damagePathData.add(polygonAndProps);
} else {
throw new JsonException(String.format(INVALID_POLYGON, i,
validator.getValidationError()));
}
} else {
throw new JsonException(String.format(UNSUPPORTED_GEOM_TYPE,
geomN.getGeometryType(), i));
}
}
}
private boolean isGeometryType(String geoJsonType) {
return ((GeoJsonMapUtil.GEOM_COLL_TYPE.equals(geoJsonType))
|| (GeoJsonMapUtil.LINE_STR_TYPE.equals(geoJsonType))
|| (GeoJsonMapUtil.MULT_LINE_STR_TYPE.equals(geoJsonType))
|| (GeoJsonMapUtil.MULT_POINT_TYPE.equals(geoJsonType))
|| (GeoJsonMapUtil.MULT_POLY_TYPE.equals(geoJsonType))
|| (GeoJsonMapUtil.POINT_TYPE.equals(geoJsonType)) || (GeoJsonMapUtil.POLY_TYPE
.equals(geoJsonType)));
}
/*
* TODO: Replace loadFromInputStream with this method when we no longer
* desire supporting the version 15.1 GeoJSON formatted damage path files.
*/
@SuppressWarnings("unused")
private void loadFromInputStreamFuture(final InputStream is)
throws JsonException {
IGeoJsonService json = new SimpleGeoJsonService();
FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = json
.deserializeFeatureCollection(is);

View file

@ -23,7 +23,6 @@ import java.util.Collections;
import java.util.Map;
import com.raytheon.uf.viz.drawing.polygon.DrawablePolygon;
import com.raytheon.uf.viz.drawing.polygon.PolygonLayer;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Polygon;
@ -37,6 +36,7 @@ import com.vividsolutions.jts.geom.Polygon;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 18, 2015 #4354 dgilling Initial creation
* Jun 30, 2015 #4354 dgilling Force setProperties to trigger a save.
*
* </pre>
*
@ -51,23 +51,23 @@ public class DamagePathPolygon extends DrawablePolygon {
private Map<String, String> properties;
public DamagePathPolygon(PolygonLayer<?> polygonLayer) {
super(polygonLayer);
public DamagePathPolygon(DamagePathLayer<?> layer) {
super(layer);
this.properties = DEFAULT_PROPS;
}
public DamagePathPolygon(Polygon polygon, PolygonLayer<?> polygonLayer) {
this(polygon, DEFAULT_PROPS, polygonLayer);
public DamagePathPolygon(Polygon polygon, DamagePathLayer<?> layer) {
this(polygon, DEFAULT_PROPS, layer);
}
public DamagePathPolygon(Polygon polygon, Map<String, String> properties,
PolygonLayer<?> polygonLayer) {
super(polygon, polygonLayer);
DamagePathLayer<?> layer) {
super(polygon, layer);
this.properties = properties;
}
public DamagePathPolygon(Coordinate[] coords, PolygonLayer<?> polygonLayer) {
super(coords, polygonLayer);
public DamagePathPolygon(Coordinate[] coords, DamagePathLayer<?> layer) {
super(coords, layer);
this.properties = DEFAULT_PROPS;
}
@ -87,5 +87,6 @@ public class DamagePathPolygon extends DrawablePolygon {
public void setProperties(Map<String, String> properties) {
this.properties = properties;
((DamagePathLayer<?>) polygonLayer).scheduleSaveJob();
}
}

View file

@ -41,6 +41,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* Jun 09, 2015 #4355 dgilling Rename action for UI.
* Jun 18, 2015 #4354 dgilling Allow individual properties object for
* each polygon.
* Jun 30, 2015 #4354 dgilling Fix NullPointerException.
*
* </pre>
*
@ -65,7 +66,6 @@ public class OpenGeoJsonPropertiesDlgAction extends AbstractRightClickAction {
Shell shell = VizWorkbenchManager.getInstance()
.getCurrentWindow().getShell();
final DamagePathLayer<?> layer = (DamagePathLayer<?>) getSelectedRsc();
final Map<String, String> geoJsonProps = damagePath
.getProperties();
EditGeoJsonPropertiesDlg dlg = new EditGeoJsonPropertiesDlg(
@ -78,7 +78,6 @@ public class OpenGeoJsonPropertiesDlgAction extends AbstractRightClickAction {
&& (!geoJsonProps.equals(returnValue))) {
Map<String, String> updatedProperties = (Map<String, String>) returnValue;
damagePath.setProperties(updatedProperties);
layer.scheduleSaveJob();
}
}
});

View file

@ -51,6 +51,8 @@ import com.vividsolutions.jts.geom.Polygon;
* ------------ ---------- ----------- --------------------------
* May 27, 2015 #4375 dgilling Initial creation
* Jun 18, 2015 #4354 dgilling Correct behavior of project.
* Jun 30, 2015 #4354 dgilling Make PolygonLayer visible to
* subclasses.
*
* </pre>
*
@ -69,7 +71,10 @@ public class DrawablePolygon implements IRenderable2 {
private final Object lock;
private final PolygonLayer<?> polygonLayer;
/**
* The PolygonLayer this polygon is attached to.
*/
protected final PolygonLayer<?> polygonLayer;
public DrawablePolygon(PolygonLayer<?> polygonLayer) {
this.lock = new Object();