Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix createInstanceFromJson for PolyLine Polygon and Multipoint #2422

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- [cygnus-ngsi][arcgis] Fix json parse for instance of PolyLine, Polygon and Multipoint (#2423)
- [cygnus-ngsi][arcgis] Check feature table is connected before use it (#2405)
- [cygnus-ngsi][arcgis] Set feature table to not connected after a connection error (#2405)
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public JsonObject toJSON() {
*/
public static Geometry createInstanceFromJson(JsonObject json) throws ArcgisException {
try {
return new MultiPoint(json.get(POINTS_TAG).getAsString());
return new MultiPoint(json.toString());
} catch (Exception e) {
LOGGER.error(e.getClass().getSimpleName() + " error " + e.getMessage() + " parsing MultiPoint from json " + json);
throw new ArcgisException("Unable to parse MultiPoint from json " + json + " due to " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public JsonObject toJSON() {
*/
public static Geometry createInstanceFromJson(JsonObject json) throws ArcgisException {
try {
return new PolyLine(json.get(PATHS_TAG).getAsString());
return new PolyLine(json.toString());
} catch (Exception e) {
LOGGER.error(e.getClass().getSimpleName() + " error " + e.getMessage() + " parsing PolyLine from json " + json);
throw new ArcgisException("Unable to parse PolyLine from json " + json + " due to " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public JsonObject toJSON() {
*/
public static Geometry createInstanceFromJson(JsonObject json) throws ArcgisException {
try {
return new Polygon(json.get(RINGS_TAG).getAsString());
return new Polygon(json.toString());
} catch (Exception e) {
LOGGER.error(e.getClass().getSimpleName() + " error " + e.getMessage() + " parsing Polygon from json " + json);
throw new ArcgisException("Unable to parse Polygon from json " + json + " due to " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import com.google.gson.JsonObject;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -177,17 +176,17 @@ public void getPolyFeatureTest() {
String paths = "{ \"paths\": [ [ [-97.06138, 32.837], [-97.06133, 33.836], [-98.2, 34.834], [-97, 40] ] ] }";
PolyLine polyline = new PolyLine(paths);
System.out.println("POLYLINE: " + polyline.toString());

} catch (Exception e) {
System.out.println("Exception");
System.out.println(e.getClass().getSimpleName() + " " + e.getMessage());
}
Feature polyline = FeatureTestFactory.getNewPolyLineFeature("Mi PolyLine", 33);
System.out.println("feature with polyline - " + polyline.toJson());
Feature polyline2 = FeatureTestFactory.getNewPolyLineFeature2("Mi PolyLine2", 33);
System.out.println("feature with polyline2 - " + polyline2.toJson());
assertTrue("ok.", true);
}


/**
*
*/
Expand All @@ -198,13 +197,14 @@ public void getPolygonTest() {
String rings = "{ \"rings\": [ [ [-97.06138,32.837,35.1,4.8], [-97.06133,32.836,35.2,4.1], [-97.06124,32.834,35.3,4.2], [-97.06138,32.837,35.1,4.8] ], [ [-97.06326,32.759,35.4], [-97.06298,32.755,35.5], [-97.06153,32.749,35.6], [-97.06326,32.759,35.4] ] ] }";
Polygon poly = new Polygon(rings);
System.out.println("POLYGON: " + poly.toString());

} catch (Exception e) {
System.out.println("Exception");
System.out.println(e.getClass().getSimpleName() + " " + e.getMessage());
}
Feature polygon = FeatureTestFactory.getNewPolygonFeature("Mi Polygon", 33);
System.out.println("feature with polygon - " + polygon.toJson());
Feature polygon2 = FeatureTestFactory.getNewPolygonFeature("Mi Polygon2", 33);
System.out.println("feature with polygon2 - " + polygon2.toJson());
assertTrue("ok.", true);
}

Expand All @@ -225,7 +225,9 @@ public void getMultiPointTest() {
}
Feature multipoint = FeatureTestFactory.getNewMultiPointFeature("Mi MultiPoint", 33);
System.out.println("feature with multipoint - " + multipoint.toJson());
Feature multipoint2 = FeatureTestFactory.getNewMultiPointFeature("Mi MultiPoint2", 33);
System.out.println("feature with multipoint2 - " + multipoint2.toJson());
assertTrue("ok.", true);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,40 @@ public static Feature getNewPolyLineFeature(String description, Integer external
return feature;
}

public static Feature getNewPolyLineFeature2(String description, Integer externalId) {
Map<String, Object> attributes = new LinkedHashMap<String, Object>();
attributes.put("IDEXTERNO", externalId);
attributes.put("DESCRIPCION", description);
attributes.put("RAZONSOCIAL", "Razon social");
attributes.put("NUMEROPOSTAL", null);
attributes.put("TIPOOCUPACION", 0);
attributes.put("FINI", new Date());
attributes.put("UNIDADMEDIDA", null);
attributes.put("EXCSABDOM", 0);
attributes.put("EXCFESTIVOS", 0);
attributes.put("PRESENCIAPOLICIAL", 0);
attributes.put("REVISADO", 0);
attributes.put("IDACTIVIDAD", 0);
attributes.put("ACTIVIDAD", "actividad");
attributes.put("IDCLASE", 0);
attributes.put("CLASE", "clase");
attributes.put("IDESTADO", 0);
attributes.put("ESTADO", "estado");
attributes.put("CALLE", "calle");
attributes.put("FFIN", new GregorianCalendar());
attributes.put("CANTIDADOCUPADA", null);
String jsonString = "{ \"paths\": [ [ [-97.06138, 32.837], [-97.06133, 33.836], [-98.2, 34.834], [-97, 40] ] ] }";
Feature feature = null;
try {
feature = Feature.createInstanceFromJson(jsonString);
feature.setAttributes(attributes);
} catch (Exception e) {
System.out.println("Exception");
System.out.println(e.getClass().getSimpleName() + " " + e.getMessage());
}
return feature;
}

/**
*
* @param description
Expand Down Expand Up @@ -177,6 +211,46 @@ public static Feature getNewPolygonFeature(String description, Integer externalI
return feature;
}

/**
*
* @param description
* @param externalId
* @return
*/
public static Feature getNewPolygonFeature2(String description, Integer externalId) {
Map<String, Object> attributes = new LinkedHashMap<String, Object>();
attributes.put("IDEXTERNO", externalId);
attributes.put("DESCRIPCION", description);
attributes.put("RAZONSOCIAL", "Razon social");
attributes.put("NUMEROPOSTAL", null);
attributes.put("TIPOOCUPACION", 0);
attributes.put("FINI", new Date());
attributes.put("UNIDADMEDIDA", null);
attributes.put("EXCSABDOM", 0);
attributes.put("EXCFESTIVOS", 0);
attributes.put("PRESENCIAPOLICIAL", 0);
attributes.put("REVISADO", 0);
attributes.put("IDACTIVIDAD", 0);
attributes.put("ACTIVIDAD", "actividad");
attributes.put("IDCLASE", 0);
attributes.put("CLASE", "clase");
attributes.put("IDESTADO", 0);
attributes.put("ESTADO", "estado");
attributes.put("CALLE", "calle");
attributes.put("FFIN", new GregorianCalendar());
attributes.put("CANTIDADOCUPADA", null);
String jsonString = "{ \"rings\": [ [ [-97.06138,32.837,35.1,4.8], [-97.06133,32.836,35.2,4.1], [-97.06124,32.834,35.3,4.2], [-97.06138,32.837,35.1,4.8] ], [ [-97.06326,32.759,35.4], [-97.06298,32.755,35.5], [-97.06153,32.749,35.6], [-97.06326,32.759,35.4] ] ] }";
Feature feature = null;
try {
feature = Feature.createInstanceFromJson(jsonString);
feature.setAttributes(attributes);
} catch (Exception e) {
System.out.println("Exception");
System.out.println(e.getClass().getSimpleName() + " " + e.getMessage());
}
return feature;
}

/**
*
* @param description
Expand Down Expand Up @@ -209,7 +283,47 @@ public static Feature getNewMultiPointFeature(String description, Integer extern
Feature feature = Feature.createMultiPointFeature(jsonString);
feature.setAttributes(attributes);
return feature;
}
}

/**
*
* @param description
* @param externalId
* @return
*/
public static Feature getNewMultiPointFeature2(String description, Integer externalId) {
Map<String, Object> attributes = new LinkedHashMap<String, Object>();
attributes.put("IDEXTERNO", externalId);
attributes.put("DESCRIPCION", description);
attributes.put("RAZONSOCIAL", "Razon social");
attributes.put("NUMEROPOSTAL", null);
attributes.put("TIPOOCUPACION", 0);
attributes.put("FINI", new Date());
attributes.put("UNIDADMEDIDA", null);
attributes.put("EXCSABDOM", 0);
attributes.put("EXCFESTIVOS", 0);
attributes.put("PRESENCIAPOLICIAL", 0);
attributes.put("REVISADO", 0);
attributes.put("IDACTIVIDAD", 0);
attributes.put("ACTIVIDAD", "actividad");
attributes.put("IDCLASE", 0);
attributes.put("CLASE", "clase");
attributes.put("IDESTADO", 0);
attributes.put("ESTADO", "estado");
attributes.put("CALLE", "calle");
attributes.put("FFIN", new GregorianCalendar());
attributes.put("CANTIDADOCUPADA", null);
String jsonString = "{ \"points\": [ [-97.06138, 32.837], [-97.06133, 33.836], [-98.2, 34.834], [-97, 40] ] }";
Feature feature = null;
try {
feature = Feature.createInstanceFromJson(jsonString);
feature.setAttributes(attributes);
} catch (Exception e) {
System.out.println("Exception");
System.out.println(e.getClass().getSimpleName() + " " + e.getMessage());
}
return feature;
}

/**
*
Expand Down
Loading