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;
}
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;
}
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();
}
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));
});
}
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;
}
Aggregations