use of io.atlasmap.json.v2.JsonInspectionRequest in project syndesis-qe by syndesisio.
the class AtlasMapperGenerator method generateJsonInspectionRequest.
/**
* Creates JsonInspectionRequest object out of specified datashape specification.
*
* @param specification
* @return
*/
private JsonInspectionRequest generateJsonInspectionRequest(String specification) {
log.debug(specification);
JsonInspectionRequest jsonInspectReq = new JsonInspectionRequest();
jsonInspectReq.setJsonData(specification);
jsonInspectReq.setType(InspectionType.SCHEMA);
return jsonInspectReq;
}
use of io.atlasmap.json.v2.JsonInspectionRequest in project syndesis-qe by syndesisio.
the class AtlasmapEndpoint method inspectJson.
public JsonInspectionResponse inspectJson(JsonInspectionRequest body) {
log.debug("POST: {}", getEndpointUrl(Optional.of("json/inspect")));
final Invocation.Builder invocation = this.createInvocation("json/inspect");
JsonInspectionResponse response = invocation.post(Entity.entity(body, MediaType.APPLICATION_JSON_TYPE), JsonInspectionResponse.class);
return response;
}
use of io.atlasmap.json.v2.JsonInspectionRequest in project atlasmap by atlasmap.
the class JsonService method inspectClass.
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("/inspect")
public Response inspectClass(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 {
JsonDocumentInspectionService s = new JsonDocumentInspectionService();
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);
}
response.setJsonDocument(d);
return Response.ok().entity(toJson(response)).build();
}
use of io.atlasmap.json.v2.JsonInspectionRequest 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();
}
Aggregations