Search in sources :

Example 1 with JsonInspectionResponse

use of io.atlasmap.json.v2.JsonInspectionResponse in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method processDataShapeIntoFields.

private List<Field> processDataShapeIntoFields(String stepSpecification, DataShapeKinds dsKind) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
    List<Field> fields = null;
    log.debug(stepSpecification);
    if (dsKind.equals(DataShapeKinds.JAVA)) {
        try {
            JavaClass jClass = mapper.readValue(stepSpecification, JavaClass.class);
            jClass = mapper.readValue(stepSpecification, JavaClass.class);
            List<JavaField> jfields = getJavaFields(jClass);
            fields = jfields.stream().map(f -> (Field) f).collect(Collectors.toList());
        } catch (IOException e) {
            log.error("error: {}" + e);
        }
    } else if (dsKind.equals(DataShapeKinds.JSON_SCHEMA) || dsKind.equals(DataShapeKinds.JSON_INSTANCE)) {
        JsonInspectionResponse inspectionResponse = atlasmapEndpoint.inspectJson(generateJsonInspectionRequest(stepSpecification));
        try {
            String mapperString = mapper.writeValueAsString(inspectionResponse);
            log.debug(mapperString);
            fields = inspectionResponse.getJsonDocument().getFields().getField();
        } catch (JsonProcessingException e) {
            log.error("error: {}" + e);
        }
    } else if (dsKind.equals(DataShapeKinds.XML_SCHEMA) || dsKind.equals(DataShapeKinds.XML_INSTANCE)) {
        // TODO(tplevko)
        throw new UnsupportedOperationException("XML support is not implemented yet");
    }
    return fields;
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with JsonInspectionResponse

use of io.atlasmap.json.v2.JsonInspectionResponse 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 JsonInspectionResponse

use of io.atlasmap.json.v2.JsonInspectionResponse 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 JsonInspectionResponse

use of io.atlasmap.json.v2.JsonInspectionResponse in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method processPrecedingSteps.

/**
 * Using output datashape, generates jsonInspectionResponse for steps preceding atlasMapping we want to generate. In
 * case, the specification is of JavaClass-type, is only transforms this scpecification into required Field listing.
 * The jsonInspectionResponse is stored in StepDefinition.
 */
private void processPrecedingSteps() {
    precedingSteps.stream().filter(s -> s.getStep().getAction().isPresent()).forEach(s -> {
        String stepSpecification = s.getStep().getAction().get().getOutputDataShape().get().getSpecification();
        DataShapeKinds dsKind = s.getStep().getAction().get().getOutputDataShape().get().getKind();
        s.setInspectionResponseFields(processDataShapeIntoFields(stepSpecification, dsKind));
    });
}
Also used : JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) Action(io.syndesis.common.model.action.Action) Step(io.syndesis.common.model.integration.Step) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) DataSource(io.atlasmap.v2.DataSource) Autowired(org.springframework.beans.factory.annotation.Autowired) MappingType(io.atlasmap.v2.MappingType) DataMapperStepDefinition(io.syndesis.qe.entities.DataMapperStepDefinition) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) StringUtils(org.apache.commons.lang3.StringUtils) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) StepDescriptor(io.syndesis.common.model.action.StepDescriptor) JsonUtils(io.syndesis.common.util.json.JsonUtils) Field(io.atlasmap.v2.Field) XmlInspectionResponse(io.atlasmap.xml.v2.XmlInspectionResponse) StepKind(io.syndesis.common.model.integration.StepKind) JavaClass(io.atlasmap.java.v2.JavaClass) StepDefinition(io.syndesis.qe.entities.StepDefinition) BaseMapping(io.atlasmap.v2.BaseMapping) LookupTables(io.atlasmap.v2.LookupTables) DataShape(io.syndesis.common.model.DataShape) StepAction(io.syndesis.common.model.action.StepAction) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AtlasmapEndpoint(io.syndesis.qe.endpoint.AtlasmapEndpoint) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) Properties(io.atlasmap.v2.Properties) DataSourceType(io.atlasmap.v2.DataSourceType) Mapping(io.atlasmap.v2.Mapping) Component(org.springframework.stereotype.Component) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) TestUtils(io.syndesis.qe.utils.TestUtils) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Mappings(io.atlasmap.v2.Mappings) Collections(java.util.Collections) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) JsonComplexType(io.atlasmap.json.v2.JsonComplexType) DataShapeKinds(io.syndesis.common.model.DataShapeKinds)

Example 5 with JsonInspectionResponse

use of io.atlasmap.json.v2.JsonInspectionResponse in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method processDataShapeIntoFields.

/**
 * The dataShapeSpecification needs to be separated into fields, which could then be used for generation of mapping
 * steps. This is different for the "Json", "Java" and also "Xml" data shape type. Java DS type is already the
 * specification of field types, Json needs to be send to be sent first to Json inspection endpoint, to generate the
 * fields.
 *
 * @return list of fields from given datashape
 */
private List<Field> processDataShapeIntoFields(String dataShapeSpecification, DataShapeKinds dsKind) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
    List<Field> fields = null;
    if (dsKind.equals(DataShapeKinds.JAVA)) {
        try {
            JavaClass jClass = mapper.readValue(dataShapeSpecification, JavaClass.class);
            fields = getJavaFields(jClass).stream().map(this::replacePrimitiveWithObject).collect(Collectors.toList());
        } catch (IOException e) {
            log.error("error: ", e);
        }
    } else if (dsKind.equals(DataShapeKinds.JSON_SCHEMA) || dsKind.equals(DataShapeKinds.JSON_INSTANCE)) {
        JsonInspectionResponse inspectionResponse = atlasmapEndpoint.inspectJson(dataShapeSpecification, dsKind);
        try {
            log.debug("Inspection API response: " + mapper.writeValueAsString(inspectionResponse));
            fields = inspectionResponse.getJsonDocument().getFields().getField();
        } catch (JsonProcessingException e) {
            log.error("Unable to write inspection API response as string", e);
        }
    } else if (dsKind.equals(DataShapeKinds.XML_SCHEMA) || dsKind.equals(DataShapeKinds.XML_INSTANCE)) {
        XmlInspectionResponse inspectionResponse = atlasmapEndpoint.inspectXml(dataShapeSpecification, dsKind);
        try {
            log.debug("Inspection API response: " + mapper.writeValueAsString(inspectionResponse));
            fields = inspectionResponse.getXmlDocument().getFields().getField();
        } catch (JsonProcessingException e) {
            log.error("Unable to write inspection API response as string", e);
        }
    }
    return fields;
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) JsonInspectionResponse(io.atlasmap.json.v2.JsonInspectionResponse) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlInspectionResponse(io.atlasmap.xml.v2.XmlInspectionResponse)

Aggregations

JsonInspectionResponse (io.atlasmap.json.v2.JsonInspectionResponse)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 IOException (java.io.IOException)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 JavaClass (io.atlasmap.java.v2.JavaClass)3 JavaField (io.atlasmap.java.v2.JavaField)3 Field (io.atlasmap.v2.Field)3 JsonDocument (io.atlasmap.json.v2.JsonDocument)2 JsonInspectionRequest (io.atlasmap.json.v2.JsonInspectionRequest)2 XmlInspectionResponse (io.atlasmap.xml.v2.XmlInspectionResponse)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 JsonDocumentInspectionService (io.atlasmap.json.inspect.JsonDocumentInspectionService)1 JsonInspectionService (io.atlasmap.json.inspect.JsonInspectionService)1 JsonComplexType (io.atlasmap.json.v2.JsonComplexType)1 JsonDataSource (io.atlasmap.json.v2.JsonDataSource)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 DataSource (io.atlasmap.v2.DataSource)1