Commit 23bf8d73 authored by Sanjeev-SLB's avatar Sanjeev-SLB
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://community.opengroup.org/osdu/platform/system/storage into virtual_service
parents 8b1b8d9b 4b401cd6
This diff is collapsed.
......@@ -33,7 +33,7 @@
<azure.appservice.plan />
<azure.appservice.appname />
<azure.appservice.subscription />
<osdu.corelibazure.version>0.11.0-rc2</osdu.corelibazure.version>
<osdu.corelibazure.version>0.11.0</osdu.corelibazure.version>
<osdu.storage-core.version>0.12.0-SNAPSHOT</osdu.storage-core.version>
<junit.version>4.12</junit.version>
<mockito.version>1.10.19</mockito.version>
......
......@@ -42,6 +42,7 @@ public class CrsConversionService {
private static final String TO_CRS_GEO_JSON = "{\"authCode\":{\"auth\":\"EPSG\",\"code\":\"4326\"},\"name\":\"GCS_WGS_1984\",\"type\":\"LBC\",\"ver\":\"PE_10_3_1\",\"wkt\":\"GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137.0,298.257223563]],PRIMEM[\\\"Greenwich\\\",0.0],UNIT[\\\"Degree\\\",0.0174532925199433],AUTHORITY[\\\"EPSG\\\",4326]]\"}";
private static final String TO_UNIT_Z = "{\"baseMeasurement\":{\"ancestry\":\"Length\",\"type\":\"UM\"},\"scaleOffset\":{\"offset\":0.0,\"scale\":1.0},\"symbol\":\"m\",\"type\":\"USO\"}";
private static final String UNKNOWN_ERROR = "unknown error";
private static final String INVALID_COORDINATES = "CRS conversion: Invalid Coordinates values, no conversion applied. Error: %s";
private static final String BAD_REQUEST = "CRS conversion: bad request from crs converter, no conversion applied. Response From CRS Converter: %s.";
private static final String CONVERSION_FAILURE = "CRS Conversion Error: Point Converted failed(CRS Converter is returning null), no conversion applied. Affected property names: %s, %s";
......@@ -593,17 +594,17 @@ public class CrsConversionService {
private void setGeometry(String type, GeoJsonFeature feature, JsonObject coordinates, ConversionStatus.ConversionStatusBuilder statusBuilder) {
Gson gson = new Gson();
switch (type) {
case Constants.ANY_CRS_POINT: feature.setGeometry(this.getGeoJsonPoint(gson, coordinates));
case Constants.ANY_CRS_POINT: feature.setGeometry(this.getGeoJsonPoint(gson, coordinates, statusBuilder));
break;
case Constants.ANY_CRS_MULTIPOINT: feature.setGeometry(this.getGeoJsonMultiPoint(gson, coordinates));
case Constants.ANY_CRS_MULTIPOINT: feature.setGeometry(this.getGeoJsonMultiPoint(gson, coordinates, statusBuilder));
break;
case Constants.ANY_CRS_LINE_STRING: feature.setGeometry(this.getGeoJsonLineString(gson, coordinates));
case Constants.ANY_CRS_LINE_STRING: feature.setGeometry(this.getGeoJsonLineString(gson, coordinates, statusBuilder));
break;
case Constants.ANY_CRS_MULTILINE_STRING: feature.setGeometry(this.getGeoJsonMultiLineString(gson, coordinates));
case Constants.ANY_CRS_MULTILINE_STRING: feature.setGeometry(this.getGeoJsonMultiLineString(gson, coordinates, statusBuilder));
break;
case Constants.ANY_CRS_POLYGON: feature.setGeometry(this.getGeoJsonPolygon(gson, coordinates));
case Constants.ANY_CRS_POLYGON: feature.setGeometry(this.getGeoJsonPolygon(gson, coordinates, statusBuilder));
break;
case Constants.ANY_CRS_MULTIPOLYGON: feature.setGeometry(this.getGeoJsonMultiPolygon(gson, coordinates));
case Constants.ANY_CRS_MULTIPOLYGON: feature.setGeometry(this.getGeoJsonMultiPolygon(gson, coordinates, statusBuilder));
break;
default: statusBuilder.addError(String.format(CrsConversionServiceErrorMessages.INVALID_GEOMETRY, type));
break;
......@@ -634,17 +635,17 @@ public class CrsConversionService {
JsonObject gmCoordinatesObj = this.getCoordinates(coordinatesValues, statusBuilder);
Gson gson = new Gson();
switch (geometriesType) {
case Constants.POINT: geometries[k] = this.getGeoJsonPoint(gson, gmCoordinatesObj);
case Constants.POINT: geometries[k] = this.getGeoJsonPoint(gson, gmCoordinatesObj, statusBuilder);
break;
case Constants.MULTIPOINT: geometries[k] = this.getGeoJsonMultiPoint(gson, gmCoordinatesObj);
case Constants.MULTIPOINT: geometries[k] = this.getGeoJsonMultiPoint(gson, gmCoordinatesObj, statusBuilder);
break;
case Constants.LINE_STRING: geometries[k] = this.getGeoJsonLineString(gson, gmCoordinatesObj);
case Constants.LINE_STRING: geometries[k] = this.getGeoJsonLineString(gson, gmCoordinatesObj, statusBuilder);
break;
case Constants.MULTILINE_STRING: geometries[k] = this.getGeoJsonMultiLineString(gson, gmCoordinatesObj);
case Constants.MULTILINE_STRING: geometries[k] = this.getGeoJsonMultiLineString(gson, gmCoordinatesObj, statusBuilder);
break;
case Constants.POLYGON: geometries[k] = this.getGeoJsonPolygon(gson, gmCoordinatesObj);
case Constants.POLYGON: geometries[k] = this.getGeoJsonPolygon(gson, gmCoordinatesObj, statusBuilder);
break;
case Constants.MULTIPOLYGON: geometries[k] = this.getGeoJsonMultiPolygon(gson, gmCoordinatesObj);
case Constants.MULTIPOLYGON: geometries[k] = this.getGeoJsonMultiPolygon(gson, gmCoordinatesObj, statusBuilder);
break;
default: statusBuilder.addError(String.format(CrsConversionServiceErrorMessages.INVALID_GEOMETRIES, geometriesType));
break;
......@@ -665,28 +666,64 @@ public class CrsConversionService {
return feature;
}
private GeoJsonPoint getGeoJsonPoint(Gson gson, JsonObject coordinatesObj) {
return gson.fromJson(coordinatesObj, GeoJsonPoint.class);
private GeoJsonPoint getGeoJsonPoint(Gson gson, JsonObject coordinatesObj, ConversionStatus.ConversionStatusBuilder statusBuilder) {
GeoJsonPoint point = new GeoJsonPoint();
try {
point = gson.fromJson(coordinatesObj, GeoJsonPoint.class);
} catch (JsonSyntaxException jsonEx) {
statusBuilder.addError(String.format(INVALID_COORDINATES, jsonEx.getMessage()));
}
return point;
}
private GeoJsonMultiPoint getGeoJsonMultiPoint(Gson gson, JsonObject coordinatesObj) {
return gson.fromJson(coordinatesObj, GeoJsonMultiPoint.class);
private GeoJsonMultiPoint getGeoJsonMultiPoint(Gson gson, JsonObject coordinatesObj, ConversionStatus.ConversionStatusBuilder statusBuilder) {
GeoJsonMultiPoint multiPoint = new GeoJsonMultiPoint();
try {
multiPoint = gson.fromJson(coordinatesObj, GeoJsonMultiPoint.class);
} catch (JsonSyntaxException jsonEx) {
statusBuilder.addError(String.format(INVALID_COORDINATES, jsonEx.getMessage()));
}
return multiPoint;
}
private GeoJsonLineString getGeoJsonLineString(Gson gson, JsonObject coordinatesObj) {
return gson.fromJson(coordinatesObj, GeoJsonLineString.class);
private GeoJsonLineString getGeoJsonLineString(Gson gson, JsonObject coordinatesObj, ConversionStatus.ConversionStatusBuilder statusBuilder) {
GeoJsonLineString lintString = new GeoJsonLineString();
try {
lintString = gson.fromJson(coordinatesObj, GeoJsonLineString.class);
} catch (JsonSyntaxException jsonEx) {
statusBuilder.addError(String.format(INVALID_COORDINATES, jsonEx.getMessage()));
}
return lintString;
}
private GeoJsonMultiLineString getGeoJsonMultiLineString(Gson gson, JsonObject coordinatesObj) {
return gson.fromJson(coordinatesObj, GeoJsonMultiLineString.class);
private GeoJsonMultiLineString getGeoJsonMultiLineString(Gson gson, JsonObject coordinatesObj, ConversionStatus.ConversionStatusBuilder statusBuilder) {
GeoJsonMultiLineString multiLintString = new GeoJsonMultiLineString();
try {
multiLintString = gson.fromJson(coordinatesObj, GeoJsonMultiLineString.class);
} catch (JsonSyntaxException jsonEx) {
statusBuilder.addError(String.format(INVALID_COORDINATES, jsonEx.getMessage()));
}
return multiLintString;
}
private GeoJsonPolygon getGeoJsonPolygon(Gson gson, JsonObject coordinatesObj) {
return gson.fromJson(coordinatesObj, GeoJsonPolygon.class);
private GeoJsonPolygon getGeoJsonPolygon(Gson gson, JsonObject coordinatesObj, ConversionStatus.ConversionStatusBuilder statusBuilder) {
GeoJsonPolygon polygon = new GeoJsonPolygon();
try {
polygon = gson.fromJson(coordinatesObj, GeoJsonPolygon.class);
} catch (JsonSyntaxException jsonEx) {
statusBuilder.addError(String.format(INVALID_COORDINATES, jsonEx.getMessage()));
}
return polygon;
}
private GeoJsonMultiPolygon getGeoJsonMultiPolygon(Gson gson, JsonObject coordinatesObj) {
return gson.fromJson(coordinatesObj, GeoJsonMultiPolygon.class);
private GeoJsonMultiPolygon getGeoJsonMultiPolygon(Gson gson, JsonObject coordinatesObj, ConversionStatus.ConversionStatusBuilder statusBuilder) {
GeoJsonMultiPolygon multiPolygon = new GeoJsonMultiPolygon();
try {
multiPolygon = gson.fromJson(coordinatesObj, GeoJsonMultiPolygon.class);
} catch (JsonSyntaxException jsonEx) {
statusBuilder.addError(String.format(INVALID_COORDINATES, jsonEx.getMessage()));
}
return multiPolygon;
}
private JsonObject getCoordinates(JsonArray coordinates, ConversionStatus.ConversionStatusBuilder statusBuilder) {
......
......@@ -50,6 +50,7 @@ public class ConversionServiceTest {
private JsonParser jsonParser = new JsonParser();
private List<JsonObject> originalRecords = new ArrayList<>();
private static final String INVALID_COORDINATES = "CRS conversion: Invalid Coordinates values, no conversion applied.";
private static final String RECORD_1 = "{\"id\":\"unit-test-1\",\"kind\":\"unit:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"msg\":\"testing record 1\",\"X\":16.00,\"Y\":10.00,\"Z\":0},\"meta\":[{\"path\":\"\",\"kind\":\"CRS\",\"persistableReference\":\"reference\",\"propertyNames\":[\"X\",\"Y\",\"Z\"],\"name\":\"GCS_WGS_1984\"}]}";
private static final String RECORD_2 = "{\"id\":\"unit-test-2\",\"kind\":\"unit:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"msg\":\"testing record 2\",\"X\":16.00,\"Y\":10.00,\"Z\":0}}";
private static final String RECORD_3 = "{\"id\":\"unit-test-3\",\"kind\":\"unit:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"msg\":\"testing record 1\",\"X\":16.00,\"Y\":10.00,\"Z\":0},\"meta\":[{\"path\":\"\",\"kind\":\"CRS\",\"persistableReference\":\"reference\",\"propertyNames\":[\"X\",\"Y\",\"Z\"],\"name\":\"GCS_WGS_1984\"}]}";
......@@ -73,7 +74,7 @@ public class ConversionServiceTest {
private static final String ANY_CRS_MULTI_LINE_STRING_CONVERTED_RECORD = "{\"id\":\"geo-json-multi-line-string-test\",\"kind\":\"geo-json-multi-line-string:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"SpatialLocation\":{\"AsIngestedCoordinates\":{\"features\":[{\"geometry\":{\"coordinates\":[[[501000.0,7001000.0],[502000.0,7002000.0]]],\"bbox\":null,\"type\":\"AnyCrsMultiLineString\"},\"bbox\":null,\"properties\":{},\"type\":\"AnyCrsFeature\"}],\"bbox\":null,\"properties\":{},\"persistableReferenceCrs\":\"reference\",\"persistableReferenceUnitZ\":\"reference\",\"type\":\"AnyCrsFeatureCollection\"},\"Wgs84Coordinates\":{\"type\":\"FeatureCollection\",\"bbox\":null,\"features\":[{\"type\":\"Feature\",\"bbox\":null,\"geometry\":{\"type\":\"MultiLineString\",\"bbox\":null,\"coordinates\":[[[9.018268130018686,63.136450807807265],[9.0381148358597,63.145421923557194]]]},\"properties\":{}}],\"properties\":{},\"persistableReferenceCrs\":null,\"persistableReferenceUnitZ\":\"reference\"},\"msg\":\"testing record 2\",\"X\":16.00,\"Y\":10.00,\"Z\":0}}}";
private static final String ANY_CRS_GEOMETRY_COLLECTION_RECORD = "{\"id\":\"geo-json-geometry-collection-test\",\"kind\":\"geo-json-geometry-collection:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"SpatialLocation\":{\"AsIngestedCoordinates\":{\"features\":[{\"geometry\":{\"type\":\"AnyCrsGeometryCollection\",\"bbox\":null,\"geometries\":[{\"type\":\"Point\",\"bbox\":null,\"coordinates\":[500000.0,7000000.0]},{\"type\":\"LineString\",\"bbox\":null,\"coordinates\":[[501000.0,7001000.0],[502000.0,7002000.0]]}]},\"bbox\":null,\"properties\":{},\"type\":\"AnyCrsFeature\"}],\"bbox\":null,\"properties\":{},\"persistableReferenceCrs\":\"reference\",\"persistableReferenceUnitZ\":\"reference\",\"type\":\"AnyCrsFeatureCollection\"},\"msg\":\"testing record 2\",\"X\":16.00,\"Y\":10.00,\"Z\":0}}}";
private static final String ANY_CRS_GEOMETRY_COLLECTION_CONVERTED_RECORD = "{\"id\":\"geo-json-geometry-collection-test\",\"kind\":\"geo-json-geometry-collection:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"SpatialLocation\":{\"AsIngestedCoordinates\":{\"features\":[{\"geometry\":{\"type\":\"AnyCrsGeometryCollection\",\"bbox\":null,\"geometries\":[{\"type\":\"Point\",\"bbox\":null,\"coordinates\":[500000.0,7000000.0]},{\"type\":\"LineString\",\"bbox\":null,\"coordinates\":[[501000.0,7001000.0],[502000.0,7002000.0]]}]},\"bbox\":null,\"properties\":{},\"type\":\"AnyCrsFeature\"}],\"bbox\":null,\"properties\":{},\"persistableReferenceCrs\":\"reference\",\"persistableReferenceUnitZ\":\"reference\",\"type\":\"AnyCrsFeatureCollection\"},\"Wgs84Coordinates\":{\"type\":\"FeatureCollection\",\"bbox\":null,\"features\":[{\"type\":\"Feature\",\"bbox\":null,\"geometry\":{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[8.998433675254244,63.1274769068748]},{\"type\":\"LineString\",\"coordinates\":[[9.018268130018686,63.136450807807265],[9.0381148358597,63.145421923557194]]}]},\"properties\":{}}],\"properties\":{},\"persistableReferenceCrs\":null,\"persistableReferenceUnitZ\":\"reference\"},\"msg\":\"testing record 2\",\"X\":16.00,\"Y\":10.00,\"Z\":0}}}";
private static final String INVALID_COORDINATES_ANY_CRS_RECORD = "{\"id\":\"geo-json-multi-polygon-test\",\"kind\":\"geo-json-multi-polygon:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"SpatialLocation\":{\"AsIngestedCoordinates\":{\"features\":[{\"geometry\":{\"coordinates\":[[[[30,20],[45,40],[10,40],[30,20]]],[[15,5],[40,10],[10,20],[5,10],[15,5]]],\"bbox\":null,\"type\":\"AnyCrsMultiPolygon\"},\"bbox\":null,\"properties\":{},\"type\":\"AnyCrsFeature\"}],\"bbox\":null,\"properties\":{},\"persistableReferenceCrs\":\"reference\",\"persistableReferenceUnitZ\":\"reference\",\"type\":\"AnyCrsFeatureCollection\"},\"msg\":\"testing record 2\",\"X\":16.00,\"Y\":10.00,\"Z\":0}}}";
private static final String ERRONEOUS_ANY_CRS_RECORD_1 = "{\"id\":\"geo-json-point-test\",\"kind\":\"geo-json-point:test:1.0.0\",\"acl\":{\"viewers\":[\"viewers@unittest.com\"],\"owners\":[\"owners@unittest.com\"]},\"legal\":{\"legaltags\":[\"unit-test-legal\"],\"otherRelevantDataCountries\":[\"AA\"]},\"data\":{\"SpatialLocation\":{\"AsIngestedCoordinates\":{\"Type\":\"AnyCrsFeatureCollection\",\"CoordinateReferenceSystemID\":\"NAD27\",\"VerticalCoordinateReferenceSystemID\":null,\"PersistableReferenceCrs\":null,\"PersistableReferenceVerticalCrs\":null,\"PersistableReferenceUnitZ\":null,\"Features\":[{\"Type\":\"AnyCrsFeature\",\"Properties\":null,\"Geometry\":{\"Coordinates\":[30.8793048,-87.7801454],\"Type\":\"AnyCrsPoint\",\"Bbox\":null}}],\"Bbox\":null},\"Wgs84Coordinates\":null}}}";
@Test
......@@ -489,4 +490,28 @@ public class ConversionServiceTest {
Assert.assertTrue(result.getRecords().get(0).toString().equalsIgnoreCase(ERRONEOUS_ANY_CRS_RECORD_1));
Assert.assertEquals(String.format(CrsConversionServiceErrorMessages.MISSING_AS_INGESTED_TYPE, ""), result.getConversionStatuses().get(0).getErrors().get(0));
}
@Test
public void should_applyNoCrsConversion_whenProvidedRecordWithAsIngestedCoordinatesBlockWithInvalidCoordinates() {
this.originalRecords.add(this.jsonParser.parse(INVALID_COORDINATES_ANY_CRS_RECORD).getAsJsonObject());
List<ConversionStatus> conversionStatuses = new ArrayList<>();
List<String> errors = new ArrayList<>();
ConversionStatus conversionStatus1 = new ConversionStatus();
conversionStatus1.setStatus(ConvertStatus.ERROR.toString());
conversionStatus1.setId("geo-json-multi-polygon-test");
errors.add(INVALID_COORDINATES);
conversionStatus1.setErrors(errors);
conversionStatuses.add(conversionStatus1);
RecordsAndStatuses crsConversionResult = new RecordsAndStatuses();
crsConversionResult.setConversionStatuses(conversionStatuses);
crsConversionResult.setRecords(this.originalRecords);
when(this.crsConversionService.doCrsGeoJsonConversion(any(), any())).thenReturn(crsConversionResult);
RecordsAndStatuses result = this.sut.doConversion(this.originalRecords);
Assert.assertEquals(1, result.getConversionStatuses().size());
Assert.assertEquals(1, result.getConversionStatuses().get(0).getErrors().size());
Assert.assertEquals(ConvertStatus.ERROR.toString(), result.getConversionStatuses().get(0).getStatus());
Assert.assertEquals(1, result.getRecords().size());
Assert.assertEquals(INVALID_COORDINATES, result.getConversionStatuses().get(0).getErrors().get(0));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment