Search in sources :

Example 76 with Field

use of io.atlasmap.v2.Field 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 77 with Field

use of io.atlasmap.v2.Field 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 78 with Field

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

the class BaseModuleValidationService method validateCombineMapping.

protected void validateCombineMapping(Mapping mapping, List<Validation> validations) {
    if (mapping == null) {
        return;
    }
    List<Field> sourceFields = mapping.getInputField();
    Field targetField = mapping.getOutputField() != null ? mapping.getOutputField().get(0) : null;
    String mappingId = mapping.getId();
    if (getMode() == AtlasModuleMode.TARGET && matchDocIdOrNull(targetField.getDocId())) {
        if (sourceFields != null) {
            // we should convert per module validations to plugin style
            for (Field sourceField : sourceFields) {
                validateSourceAndTargetTypes(mappingId, sourceField, targetField, validations);
            }
        }
        // check that the output field is of type String else error
        if (targetField.getFieldType() != FieldType.STRING) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.MAPPING);
            validation.setId(mappingId);
            validation.setMessage(String.format("Output field '%s' must be of type '%s' for a Combine Mapping", getFieldName(targetField), FieldType.STRING));
            validation.setStatus(ValidationStatus.ERROR);
            validations.add(validation);
        }
        validateField(mappingId, targetField, FieldDirection.TARGET, validations);
    } else if (sourceFields != null) {
        // SOURCE
        for (Field sourceField : sourceFields) {
            if (matchDocIdOrNull(sourceField.getDocId())) {
                validateField(mappingId, sourceField, FieldDirection.SOURCE, validations);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field)

Example 79 with Field

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

the class BaseModuleValidationService method validateSeparateMapping.

protected void validateSeparateMapping(Mapping mapping, List<Validation> validations) {
    if (mapping == null) {
        return;
    }
    final Field sourceField = mapping.getInputField() != null ? mapping.getInputField().get(0) : null;
    List<Field> targetFields = mapping.getOutputField();
    String mappingId = mapping.getId();
    if (getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
        // check that the input field is of type String else error
        if (sourceField.getFieldType() != FieldType.STRING) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.MAPPING);
            validation.setId(mapping.getId());
            validation.setMessage(String.format("Input field '%s' must be of type '%s' for a Separate Mapping", getFieldName(sourceField), FieldType.STRING));
            validation.setStatus(ValidationStatus.ERROR);
            validations.add(validation);
        }
        validateField(mappingId, sourceField, FieldDirection.SOURCE, validations);
        if (targetFields != null) {
            // we should convert per module validations to plugin style
            for (Field targetField : targetFields) {
                validateSourceAndTargetTypes(mappingId, sourceField, targetField, validations);
            }
        }
    } else if (targetFields != null) {
        // TARGET
        for (Field targetField : targetFields) {
            if (matchDocIdOrNull(targetField.getDocId())) {
                validateField(mappingId, targetField, FieldDirection.TARGET, validations);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field)

Example 80 with Field

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

the class BaseModuleValidationService method validateMapMapping.

protected void validateMapMapping(Mapping mapping, List<Validation> validations) {
    Field sourceField = null;
    Field targetField = null;
    String mappingId = mapping.getId();
    if (mapping != null && mapping.getInputField() != null && mapping.getInputField().size() > 0) {
        sourceField = mapping.getInputField().get(0);
        if (getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
            validateField(mappingId, sourceField, FieldDirection.SOURCE, validations);
        }
    }
    if (mapping != null && mapping.getOutputField() != null && mapping.getOutputField().size() > 0) {
        targetField = mapping.getOutputField().get(0);
        if (getMode() == AtlasModuleMode.TARGET && matchDocIdOrNull(targetField.getDocId())) {
            validateField(mappingId, targetField, FieldDirection.TARGET, validations);
        }
    }
    if (sourceField != null && targetField != null && getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
        // FIXME Run only for SOURCE to avoid duplicate validation...
        // we should convert per module validations to plugin style
        validateSourceAndTargetTypes(mappingId, sourceField, targetField, validations);
    }
}
Also used : Field(io.atlasmap.v2.Field)

Aggregations

Field (io.atlasmap.v2.Field)66 Test (org.junit.Test)27 JavaField (io.atlasmap.java.v2.JavaField)26 AtlasMapping (io.atlasmap.v2.AtlasMapping)26 Mapping (io.atlasmap.v2.Mapping)25 BaseMapping (io.atlasmap.v2.BaseMapping)17 SimpleField (io.atlasmap.v2.SimpleField)17 Validation (io.atlasmap.v2.Validation)14 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)13 AtlasException (io.atlasmap.api.AtlasException)12 FieldType (io.atlasmap.v2.FieldType)12 JsonField (io.atlasmap.json.v2.JsonField)10 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)10 XmlField (io.atlasmap.xml.v2.XmlField)9 LookupTable (io.atlasmap.v2.LookupTable)8 ArrayList (java.util.ArrayList)8 AtlasConversionException (io.atlasmap.api.AtlasConversionException)7 ConstantField (io.atlasmap.v2.ConstantField)7 JavaClass (io.atlasmap.java.v2.JavaClass)6 Head (io.atlasmap.spi.AtlasInternalSession.Head)6