@Test(expected = ParameterValueException.class) public void convertAvoidAreasInvalidType() throws StatusCodeException { JSONObject geomJSON = new JSONObject(); geomJSON.put("type", "LineString"); JSONArray poly = generateGeoJSONPolyCoords(); geomJSON.put("coordinates", poly); handler.convertAvoidAreas(geomJSON, 1); }
protected Polygon[] convertAvoidAreas(JSONObject geoJson, int profileType) throws StatusCodeException { org.json.JSONObject complexJson = new org.json.JSONObject(); complexJson.put("type", geoJson.get("type")); List<List<Double[]>> coordinates = (List<List<Double[]>>) geoJson.get("coordinates"); complexJson.put("coordinates", coordinates); Geometry convertedGeom; try { convertedGeom = GeometryJSON.parse(complexJson); } catch (Exception e) { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } Polygon[] avoidAreas; if (convertedGeom instanceof Polygon) { avoidAreas = new Polygon[]{(Polygon) convertedGeom}; } else if (convertedGeom instanceof MultiPolygon) { MultiPolygon multiPoly = (MultiPolygon) convertedGeom; avoidAreas = new Polygon[multiPoly.getNumGeometries()]; for (int i = 0; i < multiPoly.getNumGeometries(); i++) avoidAreas[i] = (Polygon) multiPoly.getGeometryN(i); } else { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } return avoidAreas; }
GenericHandler { protected Polygon[] convertAvoidAreas(JSONObject geoJson, int profileType) throws StatusCodeException { org.json.JSONObject complexJson = new org.json.JSONObject(); complexJson.put("type", geoJson.get("type")); List<List<Double[]>> coordinates = (List<List<Double[]>>) geoJson.get("coordinates"); complexJson.put("coordinates", coordinates); Geometry convertedGeom; try { convertedGeom = GeometryJSON.parse(complexJson); } catch (Exception e) { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } Polygon[] avoidAreas; if (convertedGeom instanceof Polygon) { avoidAreas = new Polygon[]{(Polygon) convertedGeom}; } else if (convertedGeom instanceof MultiPolygon) { MultiPolygon multiPoly = (MultiPolygon) convertedGeom; avoidAreas = new Polygon[multiPoly.getNumGeometries()]; for (int i = 0; i < multiPoly.getNumGeometries(); i++) avoidAreas[i] = (Polygon) multiPoly.getGeometryN(i); } else { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } return avoidAreas; } }
GenericHandler { protected Polygon[] convertAvoidAreas(JSONObject geoJson, int profileType) throws StatusCodeException { org.json.JSONObject complexJson = new org.json.JSONObject(); complexJson.put("type", geoJson.get("type")); List<List<Double[]>> coordinates = (List<List<Double[]>>) geoJson.get("coordinates"); complexJson.put("coordinates", coordinates); Geometry convertedGeom; try { convertedGeom = GeometryJSON.parse(complexJson); } catch (Exception e) { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } Polygon[] avoidAreas; if (convertedGeom instanceof Polygon) { avoidAreas = new Polygon[]{(Polygon) convertedGeom}; } else if (convertedGeom instanceof MultiPolygon) { MultiPolygon multiPoly = (MultiPolygon) convertedGeom; avoidAreas = new Polygon[multiPoly.getNumGeometries()]; for (int i = 0; i < multiPoly.getNumGeometries(); i++) avoidAreas[i] = (Polygon) multiPoly.getGeometryN(i); } else { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } return avoidAreas; } GenericHandler(); }
GenericHandler { protected Polygon[] convertAvoidAreas(JSONObject geoJson, int profileType) throws StatusCodeException { org.json.JSONObject complexJson = new org.json.JSONObject(); complexJson.put("type", geoJson.get("type")); List<List<Double[]>> coordinates = (List<List<Double[]>>) geoJson.get("coordinates"); complexJson.put("coordinates", coordinates); Geometry convertedGeom; try { convertedGeom = GeometryJSON.parse(complexJson); } catch (Exception e) { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } Polygon[] avoidAreas; if (convertedGeom instanceof Polygon) { avoidAreas = new Polygon[]{(Polygon) convertedGeom}; } else if (convertedGeom instanceof MultiPolygon) { MultiPolygon multiPoly = (MultiPolygon) convertedGeom; avoidAreas = new Polygon[multiPoly.getNumGeometries()]; for (int i = 0; i < multiPoly.getNumGeometries(); i++) avoidAreas[i] = (Polygon) multiPoly.getGeometryN(i); } else { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } return avoidAreas; } GenericHandler();  }
GenericHandler { protected Polygon[] convertAvoidAreas(JSONObject geoJson, int profileType) throws StatusCodeException { org.json.JSONObject complexJson = new org.json.JSONObject(); complexJson.put("type", geoJson.get("type")); List<List<Double[]>> coordinates = (List<List<Double[]>>) geoJson.get("coordinates"); complexJson.put("coordinates", coordinates); Geometry convertedGeom; try { convertedGeom = GeometryJSON.parse(complexJson); } catch (Exception e) { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } Polygon[] avoidAreas; if (convertedGeom instanceof Polygon) { avoidAreas = new Polygon[]{(Polygon) convertedGeom}; } else if (convertedGeom instanceof MultiPolygon) { MultiPolygon multiPoly = (MultiPolygon) convertedGeom; avoidAreas = new Polygon[multiPoly.getNumGeometries()]; for (int i = 0; i < multiPoly.getNumGeometries(); i++) avoidAreas[i] = (Polygon) multiPoly.getGeometryN(i); } else { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } return avoidAreas; } GenericHandler();  static final String KEY_PROFILE; }