Search in sources :

Example 11 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testXmlFieldDoubleMinRangeOut.

@Test
public void testXmlFieldDoubleMinRangeOut() throws Exception {
    String fieldPath = "/primitive/value";
    FieldType fieldType = FieldType.DOUBLE;
    Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-double-min-range-out.xml");
    AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
    assertEquals(0.0, session.head().getSourceField().getValue());
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldType(io.atlasmap.v2.FieldType) Test(org.junit.Test)

Example 12 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testXmlFieldFloatMinRangeOut.

@Test
public void testXmlFieldFloatMinRangeOut() throws Exception {
    String fieldPath = "/primitive/value";
    FieldType fieldType = FieldType.FLOAT;
    Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-float-min-range-out.xml");
    AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
    assertEquals(0.0f, session.head().getSourceField().getValue());
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldType(io.atlasmap.v2.FieldType) Test(org.junit.Test)

Example 13 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class BaseAtlasModule method processLookupField.

protected void processLookupField(AtlasInternalSession session, LookupTable lookupTable, Object sourceValue, Field targetField) throws AtlasException {
    String lookupValue = null;
    FieldType lookupType = null;
    for (LookupEntry lkp : lookupTable.getLookupEntry()) {
        if (lkp.getSourceValue().equals(sourceValue)) {
            lookupValue = lkp.getTargetValue();
            lookupType = lkp.getTargetType();
            break;
        }
    }
    Object targetValue = null;
    if (lookupType == null || FieldType.STRING.equals(lookupType)) {
        targetValue = lookupValue;
    } else {
        targetValue = atlasConversionService.convertType(lookupValue, FieldType.STRING, lookupType);
    }
    if (targetField.getFieldType() != null && !targetField.getFieldType().equals(lookupType)) {
        targetValue = atlasConversionService.convertType(targetValue, lookupType, targetField.getFieldType());
    }
    targetField.setValue(targetValue);
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) FieldType(io.atlasmap.v2.FieldType)

Example 14 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class BaseModuleValidationService method validateFieldTypeConversion.

protected void validateFieldTypeConversion(String mappingId, Field inputField, Field outField, List<Validation> validations) {
    FieldType inFieldType = inputField.getFieldType();
    FieldType outFieldType = outField.getFieldType();
    Optional<AtlasConverter<?>> atlasConverter = conversionService.findMatchingConverter(inFieldType, outFieldType);
    if (!atlasConverter.isPresent()) {
        Validation validation = new Validation();
        validation.setScope(ValidationScope.MAPPING);
        validation.setId(mappingId);
        validation.setMessage(String.format("Conversion from '%s' to '%s' is required but no converter is available", inputField.getFieldType(), outField.getFieldType()));
        validation.setStatus(ValidationStatus.ERROR);
        validations.add(validation);
    } else {
        AtlasConversionInfo conversionInfo;
        // find the method that does the conversion
        Method[] methods = atlasConverter.get().getClass().getMethods();
        conversionInfo = Arrays.stream(methods).map(method -> method.getAnnotation(AtlasConversionInfo.class)).filter(atlasConversionInfo -> atlasConversionInfo != null).filter(atlasConversionInfo -> (atlasConversionInfo.sourceType().compareTo(inFieldType) == 0 && atlasConversionInfo.targetType().compareTo(outFieldType) == 0)).findFirst().orElse(null);
        if (conversionInfo != null) {
            populateConversionConcerns(mappingId, conversionInfo, getFieldName(inputField), getFieldName(outField), validations);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Arrays(java.util.Arrays) FieldDirection(io.atlasmap.spi.FieldDirection) ValidationScope(io.atlasmap.v2.ValidationScope) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo) ValidationStatus(io.atlasmap.v2.ValidationStatus) AtlasConversionConcern(io.atlasmap.spi.AtlasConversionConcern) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) Field(io.atlasmap.v2.Field) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Optional(java.util.Optional) AtlasConversionService(io.atlasmap.api.AtlasConversionService) Method(java.lang.reflect.Method) BaseMapping(io.atlasmap.v2.BaseMapping) AtlasConverter(io.atlasmap.api.AtlasConverter) AtlasValidationService(io.atlasmap.api.AtlasValidationService) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo) AtlasConverter(io.atlasmap.api.AtlasConverter) Method(java.lang.reflect.Method) FieldType(io.atlasmap.v2.FieldType)

Example 15 with FieldType

use of io.atlasmap.v2.FieldType in project atlasmap by atlasmap.

the class SchemaInspector method printAttributes.

private void printAttributes(XSComplexType xsComplexType, String rootName, XmlComplexType xmlComplexType) {
    Collection<? extends XSAttributeUse> c = xsComplexType.getDeclaredAttributeUses();
    for (XSAttributeUse aC : c) {
        XmlField xmlField = AtlasXmlModelFactory.createXmlField();
        XSAttributeDecl attributeDecl = aC.getDecl();
        xmlField.setName(getNameNS(attributeDecl));
        if (attributeDecl.getDefaultValue() != null) {
            xmlField.setValue(attributeDecl.getDefaultValue().value);
        } else if (attributeDecl.getFixedValue() != null) {
            xmlField.setValue(attributeDecl.getFixedValue().value);
        }
        xmlField.setPath(rootName + "/" + "@" + getNameNS(attributeDecl));
        FieldType attrType = getFieldType(attributeDecl.getType().getName());
        xmlField.setFieldType(attrType);
        if (xmlField.getFieldType() == null) {
            // check the simple types in the schema....
            XSSimpleType simpleType = xsComplexType.getRoot().getSimpleType(xsComplexType.getTargetNamespace(), attributeDecl.getType().getName());
            if (simpleType != null) {
                FieldType fieldType = getFieldType(simpleType.getBaseType().getName());
                xmlField.setFieldType(fieldType);
                xmlField.setTypeName(attributeDecl.getType().getName());
                if (simpleType.asRestriction() != null) {
                    mapRestrictions(xmlField, simpleType.asRestriction());
                }
            } else {
                // cannot figure it out....
                xmlField.setFieldType(FieldType.UNSUPPORTED);
            }
        }
        xmlComplexType.getXmlFields().getXmlField().add(xmlField);
    }
}
Also used : XSSimpleType(com.sun.xml.xsom.XSSimpleType) XmlField(io.atlasmap.xml.v2.XmlField) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) XSAttributeUse(com.sun.xml.xsom.XSAttributeUse) FieldType(io.atlasmap.v2.FieldType)

Aggregations

FieldType (io.atlasmap.v2.FieldType)13 Field (io.atlasmap.v2.Field)8 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)6 SimpleField (io.atlasmap.v2.SimpleField)6 Test (org.junit.Test)4 Head (io.atlasmap.spi.AtlasInternalSession.Head)3 Audits (io.atlasmap.v2.Audits)3 XmlField (io.atlasmap.xml.v2.XmlField)3 Path (java.nio.file.Path)3 AtlasConverter (io.atlasmap.api.AtlasConverter)2 AtlasException (io.atlasmap.api.AtlasException)2 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)2 JavaField (io.atlasmap.java.v2.JavaField)2 Method (java.lang.reflect.Method)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)1 XSAttributeUse (com.sun.xml.xsom.XSAttributeUse)1 XSSimpleType (com.sun.xml.xsom.XSSimpleType)1 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasConversionService (io.atlasmap.api.AtlasConversionService)1