use of io.atlasmap.v2.Mapping in project syndesis-qe by syndesisio.
the class AtlasMapperGenerator method generateCombineMapping.
private Mapping generateCombineMapping(DataMapperStepDefinition mappingDef, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
StepDefinition fromStep = precedingSteps.get(mappingDef.getFromStep() - 1);
Mapping generatedMapping = new Mapping();
generatedMapping.setId(UUID.randomUUID().toString());
generatedMapping.setMappingType(MappingType.COMBINE);
generatedMapping.setDelimiter(mappingDef.getStrategy().name());
List<Field> in = new ArrayList<>();
for (int i = 0; i < mappingDef.getInputFields().size(); i++) {
String def = mappingDef.getInputFields().get(i);
Field inField = fromStep.getInspectionResponseFields().get().stream().filter(f -> f.getPath().matches(def)).findFirst().get();
inField.setIndex(i);
in.add(inField);
}
Field out = followingStep.getInspectionResponseFields().get().stream().filter(f -> f.getPath().matches(mappingDef.getOutputFields().get(0))).findFirst().get();
in.forEach(f -> f.setDocId(fromStep.getStep().getId().get()));
out.setDocId(followingStep.getStep().getId().get());
generatedMapping.getInputField().addAll(in);
generatedMapping.getOutputField().add(out);
return generatedMapping;
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JavaModule method processPreTargetExecution.
@Override
public void processPreTargetExecution(AtlasInternalSession atlasSession) throws AtlasException {
if (atlasSession == null || atlasSession.getMapping() == null || atlasSession.getMapping().getMappings() == null || atlasSession.getMapping().getMappings().getMapping() == null) {
throw new AtlasException("AtlasSession not properly intialized with a mapping that contains field mappings");
}
if (javaInspectionService == null) {
javaInspectionService = new ClassInspectionService();
javaInspectionService.setConversionService(getConversionService());
}
List<BaseMapping> mapping = atlasSession.getMapping().getMappings().getMapping();
Object rootObject;
String targetClassName = AtlasUtil.getUriParameterValue(getUri(), "className");
JavaClass inspectClass = getJavaInspectionService().inspectClass(targetClassName);
merge(inspectClass, mapping);
List<String> targetPaths = AtlasModuleSupport.listTargetPaths(mapping);
try {
rootObject = getJavaConstructService().constructClass(inspectClass, targetPaths);
} catch (Exception e) {
throw new AtlasException(e);
}
DocumentJavaFieldWriter writer = new DocumentJavaFieldWriter(getConversionService());
writer.setRootObject(rootObject);
writer.setTargetValueConverter(targetValueConverter);
atlasSession.setFieldWriter(getDocId(), writer);
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processPreTargetExcution completed", getDocId());
}
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JavaModule method merge.
private void merge(JavaClass inspectionClass, List<BaseMapping> mappings) {
if (inspectionClass == null || inspectionClass.getJavaFields() == null || inspectionClass.getJavaFields().getJavaField() == null) {
return;
}
if (mappings == null || mappings.size() == 0) {
return;
}
for (BaseMapping fm : mappings) {
if (fm instanceof Mapping && (((Mapping) fm).getOutputField() != null)) {
Field f = ((Mapping) fm).getOutputField().get(0);
if (f.getPath() != null) {
Field inspectField = findFieldByPath(inspectionClass, f.getPath());
if (inspectField != null && f instanceof JavaField && inspectField instanceof JavaField) {
String overrideClassName = ((JavaField) f).getClassName();
JavaField javaInspectField = (JavaField) inspectField;
// Support mapping overrides className
if (overrideClassName != null && !overrideClassName.equals(javaInspectField.getClassName())) {
javaInspectField.setClassName(overrideClassName);
}
}
}
}
}
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JavaValidationServiceTest method testValidateMappingSourceToTargetCustomUsingClassNames.
@Test
public void testValidateMappingSourceToTargetCustomUsingClassNames() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
JavaField in = (JavaField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.DATE_TIME_TZ);
in.setClassName("java.util.Date");
JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.DATE_TIME_TZ);
out.setClassName("java.time.ZonedDateTime");
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
if (LOG.isDebugEnabled()) {
debugErrors(validations);
}
assertFalse(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertThat(validationHelper.getCount(), is(0));
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JavaValidationServiceTest method testValidateMappingInvalidSeparateSourceFieldType.
@Test
public void testValidateMappingInvalidSeparateSourceFieldType() {
AtlasMapping atlasMapping = getAtlasMappingFullValid();
Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
separateFieldMapping.setId("separate.firstName.lastName");
JavaField bIJavaField = javaModelFactory.createJavaField();
bIJavaField.setFieldType(FieldType.BOOLEAN);
bIJavaField.setValue(Boolean.TRUE);
bIJavaField.setPath("firstName");
separateFieldMapping.getInputField().add(bIJavaField);
JavaField sOJavaField = javaModelFactory.createJavaField();
sOJavaField.setFieldType(FieldType.STRING);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(0);
separateFieldMapping.getOutputField().add(sOJavaField);
atlasMapping.getMappings().getMapping().add(separateFieldMapping);
validations.addAll(sourceValidationService.validateMapping(atlasMapping));
validations.addAll(targetValidationService.validateMapping(atlasMapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
Validation validation = validations.get(0);
assertNotNull(validation);
assertEquals(ValidationScope.MAPPING, validation.getScope());
assertEquals("separate.firstName.lastName", validation.getId());
assertEquals("Input field 'firstName' must be of type 'STRING' for a Separate Mapping", validation.getMessage());
assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
Aggregations