Search in sources :

Example 6 with Mapping

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

the class DefaultAtlasContext method process.

/**
 * Process session lifecycle
 */
@Override
public void process(AtlasSession userSession) throws AtlasException {
    if (!(userSession instanceof DefaultAtlasSession)) {
        throw new AtlasException(String.format("Unsupported session class '%s'", userSession.getClass().getName()));
    }
    if (!this.equals(userSession.getAtlasContext())) {
        throw new AtlasException("Cannot execute AtlasSession created by the other AtlasContext");
    }
    DefaultAtlasSession session = (DefaultAtlasSession) userSession;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Begin process {}", (session == null ? null : session.toString()));
    }
    session.head().unset();
    session.getAudits().getAudit().clear();
    session.getValidations().getValidation().clear();
    processValidation(session);
    for (Validation v : session.getValidations().getValidation()) {
        AtlasUtil.addAudit(session, v);
    }
    if (session.hasErrors()) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Aborting due to {} errors in pre-validation", session.errorCount());
        }
        return;
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPreSourceExecution(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPreTargetExecution(session);
    }
    if (session.hasErrors()) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Aborting due to {} errors in pre-execution", session.errorCount());
        }
        return;
    }
    for (BaseMapping baseMapping : session.getMapping().getMappings().getMapping()) {
        for (Mapping mapping : extractCollectionMappings(session, baseMapping)) {
            session.head().setMapping(mapping).setLookupTable(lookupTables.get(mapping.getLookupTableName()));
            if (mapping.getOutputField() == null || mapping.getOutputField().isEmpty()) {
                AtlasUtil.addAudit(session, null, String.format("Mapping does not contain at least one output field: alias=%s desc=%s", mapping.getAlias(), mapping.getDescription()), null, AuditStatus.WARN, null);
                continue;
            }
            if (mapping.getInputField() == null || mapping.getInputField().isEmpty()) {
                AtlasUtil.addAudit(session, null, String.format("Mapping does not contain at least one source field: alias=%s desc=%s", mapping.getAlias(), mapping.getDescription()), null, AuditStatus.WARN, null);
            } else {
                processSourceFieldMappings(session, mapping.getInputField());
            }
            processTargetFieldMappings(session, mapping);
        }
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPostValidation(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPostValidation(session);
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPostSourceExecution(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPostTargetExecution(session);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("End process {}", session == null ? null : session.toString());
    }
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasModule(io.atlasmap.spi.AtlasModule) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasException(io.atlasmap.api.AtlasException) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 7 with Mapping

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

the class DefaultAtlasContext method processCombineField.

private Field processCombineField(DefaultAtlasSession session, Mapping mapping, List<Field> sourceFields, Field targetField) throws AtlasException {
    Map<Integer, String> combineValues = null;
    for (Field sourceField : sourceFields) {
        if (sourceField.getIndex() == null || sourceField.getIndex() < 0) {
            AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Combine requires zero or positive Index value to be set on all sourceFields sourceField.path=%s", sourceField.getPath()), targetField.getPath(), AuditStatus.WARN, null);
            continue;
        }
        if (combineValues == null) {
            // We need to support a sorted map w/ null values
            combineValues = new HashMap<>();
        }
        if ((sourceField.getFieldType() != null) || (sourceField.getValue() != null)) {
            String sourceValue;
            try {
                sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
            } catch (AtlasConversionException e) {
                AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), targetField.getPath(), AuditStatus.WARN, null);
                sourceValue = sourceField.getValue() != null ? sourceField.getValue().toString() : null;
            }
            combineValues.put(sourceField.getIndex(), sourceValue);
            continue;
        }
    }
    String combinedValue = null;
    StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
    if (delimiter != null) {
        combinedValue = session.getAtlasContext().getContextFactory().getCombineStrategy().combineValues(combineValues, delimiter);
    } else {
        combinedValue = session.getAtlasContext().getContextFactory().getCombineStrategy().combineValues(combineValues);
    }
    Field answer = AtlasModelFactory.cloneFieldToSimpleField(sourceFields.get(0));
    if (combinedValue == null || combinedValue.trim().isEmpty()) {
        LOG.debug(String.format("Empty combined string for Combine mapping targetField.path=%s", targetField.getPath()));
    } else {
        answer.setValue(combinedValue);
    }
    return answer;
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) StringDelimiter(io.atlasmap.spi.StringDelimiter)

Example 8 with Mapping

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

the class DefaultAtlasContext method processSeparateField.

private List<Field> processSeparateField(DefaultAtlasSession session, Mapping mapping, Field sourceField) throws AtlasException {
    List<Field> answer = new ArrayList<>();
    String sourceValue;
    try {
        sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
    } catch (AtlasConversionException e) {
        AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), sourceField.getPath(), AuditStatus.WARN, null);
        sourceValue = sourceField.getValue().toString();
    }
    List<String> separatedValues = null;
    StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
    if (mapping.getDelimiter() != null) {
        separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue, delimiter);
    } else {
        separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue);
    }
    if (separatedValues == null || separatedValues.isEmpty()) {
        LOG.debug(String.format("Empty string for Separate mapping sourceField.path=%s", sourceField.getPath()));
    } else {
        for (String separatedValue : separatedValues) {
            SimpleField simpleField = AtlasModelFactory.cloneFieldToSimpleField(sourceField);
            simpleField.setValue(separatedValue);
            simpleField.setFieldType(FieldType.STRING);
            answer.add(simpleField);
        }
    }
    return answer;
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) ArrayList(java.util.ArrayList) SimpleField(io.atlasmap.v2.SimpleField) StringDelimiter(io.atlasmap.spi.StringDelimiter)

Example 9 with Mapping

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

the class DefaultAtlasValidationService method validateMapMapping.

private void validateMapMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        Validators.MAP_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId);
        if (fieldMapping.getInputField() != null) {
            Validators.MAP_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId);
        }
        Validators.MAP_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        if (fieldMapping.getOutputField() != null) {
            Validators.MAP_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        }
    }
}
Also used : BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 10 with Mapping

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

the class DefaultAtlasValidationService method validateCombineMapping.

private void validateCombineMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        Validators.COMBINE_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId);
        if (fieldMapping.getOutputField() != null) {
            Validators.COMBINE_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId);
        // source must be a String type
        }
        Validators.COMBINE_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
        Validators.COMBINE_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
        if (fieldMapping.getInputField() != null) {
            for (Field field : fieldMapping.getInputField()) {
                Validators.COMBINE_INPUT_FIELD_NOT_NULL.get().validate(field, validations, mappingId);
                if (field.getIndex() == null || field.getIndex() < 0) {
                    Validators.COMBINE_INPUT_FIELD_FIELD_ACTION_INDEX_POSITIVE.get().validate(field.getIndex(), validations, mappingId);
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

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