use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class SchemaInspectorTest method doInspectJsonSchemaCalendar.
private void doInspectJsonSchemaCalendar(String instance) throws Exception {
JsonDocument document = inspectionService.inspectJsonSchema(instance);
List<Field> fields = document.getFields().getField();
JsonField f = (JsonField) fields.get(0);
assertEquals("dtstart", f.getName());
assertEquals("/dtstart", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(1);
assertEquals("dtend", f.getName());
assertEquals("/dtend", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(2);
assertEquals("summary", f.getName());
assertEquals("/summary", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(3);
assertEquals("location", f.getName());
assertEquals("/location", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(4);
assertEquals("url", f.getName());
assertEquals("/url", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(5);
assertEquals("duration", f.getName());
assertEquals("/duration", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(6);
assertEquals("rdate", f.getName());
assertEquals("/rdate", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(7);
assertEquals("rrule", f.getName());
assertEquals("/rrule", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(8);
assertEquals("category", f.getName());
assertEquals("/category", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(9);
assertEquals("description", f.getName());
assertEquals("/description", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonComplexType) fields.get(10);
assertEquals("geo", f.getName());
assertEquals("/geo", f.getPath());
assertEquals(FieldType.COMPLEX, f.getFieldType());
List<JsonField> geofields = ((JsonComplexType) f).getJsonFields().getJsonField();
f = geofields.get(0);
assertEquals("latitude", f.getName());
assertEquals("/geo/latitude", f.getPath());
assertEquals(FieldType.NUMBER, f.getFieldType());
f = geofields.get(1);
assertEquals("longitude", f.getName());
assertEquals("/geo/longitude", f.getPath());
assertEquals(FieldType.NUMBER, f.getFieldType());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectJsonSchemaAddress.
@Test
public void inspectJsonSchemaAddress() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/address.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
List<Field> fields = document.getFields().getField();
JsonField f = (JsonField) fields.get(0);
assertEquals("post-office-box", f.getName());
assertEquals("/post-office-box", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(1);
assertEquals("extended-address", f.getName());
assertEquals("/extended-address", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(2);
assertEquals("street-address", f.getName());
assertEquals("/street-address", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(3);
assertEquals("locality", f.getName());
assertEquals("/locality", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(4);
assertEquals("region", f.getName());
assertEquals("/region", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(5);
assertEquals("postal-code", f.getName());
assertEquals("/postal-code", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(6);
assertEquals("country-name", f.getName());
assertEquals("/country-name", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonService method inspect.
/**
* Inspect a JSON schema or instance and return a Document object.
* @param requestIn request
* @return {@link JsonInspectionResponse}
*/
@POST
@Path("/inspect")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Inspect JSON", description = "Inspect a JSON schema or instance and return a Document object")
@RequestBody(description = "JsonInspectionRequest object", content = @Content(schema = @Schema(implementation = JsonInspectionRequest.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JsonInspectionResponse.class)), description = "Return a Document object represented by JsonDocument"))
public Response inspect(InputStream requestIn) {
JsonInspectionRequest request = fromJson(requestIn, JsonInspectionRequest.class);
long startTime = System.currentTimeMillis();
JsonInspectionResponse response = new JsonInspectionResponse();
JsonDocument d = null;
try {
if (request.getType() == null || request.getJsonData() == null) {
response.setErrorMessage("Json data and Instance or Schema inspection type must be specified in request");
} else {
JsonInspectionService s = new JsonInspectionService();
String jsonData = cleanJsonData(request.getJsonData());
if (!validJsonData(jsonData)) {
response.setErrorMessage("Invalid json payload specified");
} else {
switch(request.getType()) {
case INSTANCE:
d = s.inspectJsonDocument(jsonData);
break;
case SCHEMA:
d = s.inspectJsonSchema(jsonData);
break;
default:
response.setErrorMessage("Unsupported inspection type: " + request.getType());
break;
}
}
}
} catch (Exception e) {
LOG.error("Error inspecting json: " + e.getMessage(), e);
response.setErrorMessage(e.getMessage());
} finally {
response.setExecutionTime(System.currentTimeMillis() - startTime);
}
AtlasUtil.excludeNotRequestedFields(d, request.getInspectPaths());
response.setJsonDocument(d);
return Response.ok().entity(toJson(response)).build();
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonSchemaInspectorTest method inspectComplexObjectWithRoot.
@Test
public void inspectComplexObjectWithRoot() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/complex-object-rooted.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
assertNotNull(document);
assertEquals(1, document.getFields().getField().size());
JsonComplexType root = (JsonComplexType) document.getFields().getField().get(0);
assertEquals(3, root.getJsonFields().getJsonField().size());
JsonComplexType address = (JsonComplexType) root.getJsonFields().getJsonField().get(0);
assertNotNull(address);
assertEquals(5, address.getJsonFields().getJsonField().size());
JsonField address1 = address.getJsonFields().getJsonField().get(0);
assertNotNull(address1);
assertEquals("addressLine1", address1.getName());
assertEquals("/order/address/addressLine1", address1.getPath());
assertEquals(FieldType.STRING, address1.getFieldType());
assertEquals(FieldStatus.SUPPORTED, address1.getStatus());
JsonField address2 = address.getJsonFields().getJsonField().get(1);
assertNotNull(address2);
assertEquals("addressLine2", address2.getName());
assertEquals("/order/address/addressLine2", address2.getPath());
assertEquals(FieldType.STRING, address2.getFieldType());
assertEquals(FieldStatus.SUPPORTED, address2.getStatus());
JsonField city = address.getJsonFields().getJsonField().get(2);
assertNotNull(city);
assertEquals("city", city.getName());
assertEquals("/order/address/city", city.getPath());
assertEquals(FieldType.STRING, city.getFieldType());
assertEquals(FieldStatus.SUPPORTED, city.getStatus());
JsonField state = address.getJsonFields().getJsonField().get(3);
assertNotNull(state);
assertEquals("state", state.getName());
assertEquals("/order/address/state", state.getPath());
assertEquals(FieldType.STRING, state.getFieldType());
assertEquals(FieldStatus.SUPPORTED, state.getStatus());
JsonField postalCode = address.getJsonFields().getJsonField().get(4);
assertNotNull(postalCode);
assertEquals("zipCode", postalCode.getName());
assertEquals("/order/address/zipCode", postalCode.getPath());
assertEquals(FieldType.STRING, postalCode.getFieldType());
assertEquals(FieldStatus.SUPPORTED, postalCode.getStatus());
JsonComplexType contact = (JsonComplexType) root.getJsonFields().getJsonField().get(1);
assertNotNull(contact);
assertEquals(4, contact.getJsonFields().getJsonField().size());
JsonField firstName = contact.getJsonFields().getJsonField().get(0);
assertNotNull(firstName);
assertEquals("firstName", firstName.getName());
assertEquals("/order/contact/firstName", firstName.getPath());
assertEquals(FieldType.STRING, firstName.getFieldType());
assertEquals(FieldStatus.SUPPORTED, firstName.getStatus());
JsonField lastName = contact.getJsonFields().getJsonField().get(1);
assertNotNull(lastName);
assertEquals("lastName", lastName.getName());
assertEquals("/order/contact/lastName", lastName.getPath());
assertEquals(FieldType.STRING, lastName.getFieldType());
assertEquals(FieldStatus.SUPPORTED, lastName.getStatus());
JsonField phoneNumber = contact.getJsonFields().getJsonField().get(2);
assertNotNull(phoneNumber);
assertEquals("phoneNumber", phoneNumber.getName());
assertEquals("/order/contact/phoneNumber", phoneNumber.getPath());
assertEquals(FieldType.STRING, phoneNumber.getFieldType());
assertEquals(FieldStatus.SUPPORTED, phoneNumber.getStatus());
JsonField zipCode = contact.getJsonFields().getJsonField().get(3);
assertNotNull(zipCode);
assertEquals("zipCode", zipCode.getName());
assertEquals("/order/contact/zipCode", zipCode.getPath());
assertEquals(FieldType.STRING, zipCode.getFieldType());
assertEquals(FieldStatus.SUPPORTED, zipCode.getStatus());
JsonField orderId = root.getJsonFields().getJsonField().get(2);
assertNotNull(orderId);
assertEquals("orderId", orderId.getName());
assertEquals("/order/orderId", orderId.getPath());
assertEquals(FieldType.BIG_INTEGER, orderId.getFieldType());
assertEquals(FieldStatus.SUPPORTED, orderId.getStatus());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonSchemaInspectorTest method inspectJsonSchemaRecursiveObject.
@Test
public void inspectJsonSchemaRecursiveObject() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/recursive.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
List<Field> fields = document.getFields().getField();
}
Aggregations