use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class AtlasMappingServiceTest method testLoadMappingFileAtlasMappingFormatAtlasValidationException.
@Test(expected = AtlasValidationException.class)
public void testLoadMappingFileAtlasMappingFormatAtlasValidationException() throws AtlasValidationException {
File file = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "atlasmapping2.json").toFile();
AtlasMapping atlasMapping = atlasMappingService.loadMapping(file, AtlasMappingFormat.JSON);
assertNotNull(atlasMapping);
}
use of io.atlasmap.v2.Json in project syndesis-qe by syndesisio.
the class AtlasMapperGenerator method getField.
/**
* Gets the field with the path corresponding to the search string. It recursively goes through child fields if the field is a complex type.
*
* @param fields list of fields
* @param searchString path search string
* @return field
*/
private Field getField(List<Field> fields, String searchString) {
Field f = null;
for (Field field : fields) {
if (field instanceof JsonComplexType || field instanceof XmlComplexType) {
// Search child elements of the complex element, just create a new list because Json/XmlField is a child class of Field
final List<Field> fieldList;
if (field instanceof JsonComplexType) {
fieldList = new ArrayList<>(((JsonComplexType) field).getJsonFields().getJsonField());
} else {
fieldList = new ArrayList<>(((XmlComplexType) field).getXmlFields().getXmlField());
}
f = getField(fieldList, searchString);
} else {
if (field.getPath().equals(searchString)) {
return field;
} else {
continue;
}
}
if (f != null) {
break;
}
}
return f;
}
use of io.atlasmap.v2.Json 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;
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class JsonMarshallerTest method testJsonMapXMLField.
@Test
public void testJsonMapXMLField() throws Exception {
AtlasMapping atlasMapping = generateAtlasMapping();
// Object to JSON in file
mapper.writerWithDefaultPrettyPrinter().writeValue(new File("target" + File.separator + "junit" + File.separator + testMethodName + File.separator + "atlasmapping.json"), atlasMapping);
AtlasMapping uMapping = mapper.readValue(new File("target" + File.separator + "junit" + File.separator + testMethodName + File.separator + "atlasmapping.json"), AtlasMapping.class);
assertNotNull(uMapping);
validateAtlasMapping(uMapping);
}
use of io.atlasmap.v2.Json in project atlasmap by atlasmap.
the class JsonModule method processPreValidation.
@Override
public void processPreValidation(AtlasInternalSession atlasSession) throws AtlasException {
if (atlasSession == null || atlasSession.getMapping() == null) {
throw new AtlasValidationException("Invalid session: Session and AtlasMapping must be specified");
}
Validations validations = atlasSession.getValidations();
JsonValidationService jsonValidationService = new JsonValidationService(getConversionService(), getFieldActionService());
jsonValidationService.setMode(getMode());
jsonValidationService.setDocId(getDocId());
List<Validation> jsonValidations = jsonValidationService.validateMapping(atlasSession.getMapping());
if (jsonValidations != null && !jsonValidations.isEmpty()) {
validations.getValidation().addAll(jsonValidations);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Detected " + jsonValidations.size() + " json validation notices");
}
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processPreValidation completed", getDocId());
}
}
Aggregations