Search in sources :

Example 1 with JavaField

use of io.atlasmap.java.v2.JavaField 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 JavaField

use of io.atlasmap.java.v2.JavaField in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method getJavaFields.

private List<JavaField> getJavaFields(JavaClass jClass) {
    List<JavaField> fields = jClass.getJavaFields().getJavaField();
    List<JavaField> javaField = new ArrayList<>();
    for (JavaField jf : fields) {
        if (jf instanceof JavaClass) {
            javaField.addAll(getJavaFields((JavaClass) jf));
        } else if (jf instanceof JavaField) {
            javaField.add(jf);
        }
    }
    return javaField;
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass) ArrayList(java.util.ArrayList)

Example 3 with JavaField

use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.

the class JavaValidationServiceTest method getAtlasMappingFullValid.

protected AtlasMapping getAtlasMappingFullValid() {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("thisis_a_valid.name");
    mapping.getDataSource().add(generateDataSource("atlas:java?className=io.atlasmap.java.module.MockJavaClass", DataSourceType.SOURCE, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID));
    mapping.getDataSource().add(generateDataSource("atlas:java?className=io.atlasmap.java.module.MockJavaClass", DataSourceType.TARGET, AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID));
    Mapping mapMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    Mapping combineMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
    // MappedField
    JavaField inputField = AtlasJavaModelFactory.createJavaField();
    inputField.setFieldType(FieldType.STRING);
    inputField.setPath("firstName");
    JavaField outputField = AtlasJavaModelFactory.createJavaField();
    outputField.setFieldType(FieldType.STRING);
    outputField.setPath("firstName");
    mapMapping.getInputField().add(inputField);
    mapMapping.getOutputField().add(outputField);
    JavaField sIJavaField = AtlasJavaModelFactory.createJavaField();
    sIJavaField.setFieldType(FieldType.STRING);
    sIJavaField.setPath("displayName");
    sepMapping.getInputField().add(sIJavaField);
    JavaField sOJavaField = AtlasJavaModelFactory.createJavaField();
    sOJavaField.setFieldType(FieldType.STRING);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(1);
    sepMapping.getOutputField().add(sOJavaField);
    JavaField cIJavaField = AtlasJavaModelFactory.createJavaField();
    cIJavaField.setFieldType(FieldType.STRING);
    cIJavaField.setPath("displayName");
    combineMapping.getInputField().add(cIJavaField);
    JavaField cOJavaField = AtlasJavaModelFactory.createJavaField();
    cOJavaField.setFieldType(FieldType.STRING);
    cOJavaField.setPath("lastName");
    cOJavaField.setIndex(1);
    combineMapping.getOutputField().add(cOJavaField);
    mapping.getMappings().getMapping().add(mapMapping);
    mapping.getMappings().getMapping().add(sepMapping);
    mapping.getMappings().getMapping().add(combineMapping);
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 4 with JavaField

use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.

the class JavaValidationServiceTest method testValidateAtlasMappingFileConversionRequired.

@Test
public void testValidateAtlasMappingFileConversionRequired() 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.COMPLEX);
    in.setClassName("io.atlasmap.java.module.MockJavaClass");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.STRING);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertThat(1, is(validationHelper.getCount()));
    Validation v = validations.get(0);
    assertEquals(ValidationScope.MAPPING, v.getScope());
    assertEquals("map.firstName.firstName", v.getId());
    assertEquals(ValidationStatus.WARN, v.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)

Example 5 with JavaField

use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.

the class JavaValidationServiceTest method testValidateMappingPathNull.

@Test
public void testValidateMappingPathNull() 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.setPath(null);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
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)

Aggregations

JavaField (io.atlasmap.java.v2.JavaField)53 Test (org.junit.Test)19 JavaClass (io.atlasmap.java.v2.JavaClass)16 Mapping (io.atlasmap.v2.Mapping)16 AtlasMapping (io.atlasmap.v2.AtlasMapping)15 Validation (io.atlasmap.v2.Validation)8 FieldType (io.atlasmap.v2.FieldType)7 Method (java.lang.reflect.Method)7 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)6 AtlasException (io.atlasmap.api.AtlasException)5 DataSource (io.atlasmap.v2.DataSource)5 Field (io.atlasmap.v2.Field)5 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)4 ValidationScope (io.atlasmap.v2.ValidationScope)4 ValidationStatus (io.atlasmap.v2.ValidationStatus)4 List (java.util.List)4 Logger (org.slf4j.Logger)4 AtlasConstants (io.atlasmap.api.AtlasConstants)3 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)3 AtlasPath (io.atlasmap.core.AtlasPath)3