Search in sources :

Example 1 with JsonInspectionRequest

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;
}
Also used : JsonInspectionRequest(io.atlasmap.json.v2.JsonInspectionRequest)

Example 2 with JsonInspectionRequest

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;
}
Also used : Invocation(javax.ws.rs.client.Invocation) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse)

Example 3 with JsonInspectionRequest

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();
}
Also used : JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) JsonInspectionRequest(io.atlasmap.json.v2.JsonInspectionRequest) JsonDocumentInspectionService(io.atlasmap.json.inspect.JsonDocumentInspectionService) JsonDocument(io.atlasmap.json.v2.JsonDocument) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with JsonInspectionRequest

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();
}
Also used : JsonInspectionService(io.atlasmap.json.inspect.JsonInspectionService) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) JsonInspectionRequest(io.atlasmap.json.v2.JsonInspectionRequest) JsonDocument(io.atlasmap.json.v2.JsonDocument) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody)

Aggregations

JsonInspectionRequest (io.atlasmap.json.v2.JsonInspectionRequest)3 JsonInspectionResponse (io.atlasmap.json.v2.JsonInspectionResponse)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonDocument (io.atlasmap.json.v2.JsonDocument)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 JsonDocumentInspectionService (io.atlasmap.json.inspect.JsonDocumentInspectionService)1 JsonInspectionService (io.atlasmap.json.inspect.JsonInspectionService)1 Operation (io.swagger.v3.oas.annotations.Operation)1 RequestBody (io.swagger.v3.oas.annotations.parameters.RequestBody)1 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)1 ApplicationPath (javax.ws.rs.ApplicationPath)1 Invocation (javax.ws.rs.client.Invocation)1