Search in sources :

Example 76 with Mapping

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;
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) ArrayList(java.util.ArrayList) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasmapEndpoint(io.syndesis.qe.endpoints.AtlasmapEndpoint)

Example 77 with Mapping

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());
    }
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) DocumentJavaFieldWriter(io.atlasmap.java.core.DocumentJavaFieldWriter) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) AtlasException(io.atlasmap.api.AtlasException) BaseMapping(io.atlasmap.v2.BaseMapping) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException)

Example 78 with Mapping

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);
                    }
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 79 with Mapping

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));
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 80 with Mapping

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());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)120 Mapping (io.atlasmap.v2.Mapping)83 Test (org.junit.Test)65 BaseMapping (io.atlasmap.v2.BaseMapping)29 Field (io.atlasmap.v2.Field)28 Validation (io.atlasmap.v2.Validation)26 DataSource (io.atlasmap.v2.DataSource)21 JavaField (io.atlasmap.java.v2.JavaField)19 MockField (io.atlasmap.v2.MockField)17 Mappings (io.atlasmap.v2.Mappings)11 SimpleField (io.atlasmap.v2.SimpleField)11 MappingType (io.atlasmap.v2.MappingType)10 PropertyField (io.atlasmap.v2.PropertyField)9 File (java.io.File)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 AtlasContext (io.atlasmap.api.AtlasContext)8 AtlasSession (io.atlasmap.api.AtlasSession)8 Actions (io.atlasmap.v2.Actions)8 BaseValidatorTest (io.atlasmap.validators.BaseValidatorTest)8