Search in sources :

Example 6 with Field

use of org.batfish.z3.Field in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method processActions.

@Override
public void processActions(Actions actions, Field field) throws AtlasException {
    Field tmpField = internalProcessActions(actions, field.getValue(), field.getFieldType());
    field.setValue(tmpField.getValue());
    field.setFieldType(tmpField.getFieldType());
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField)

Example 7 with Field

use of org.batfish.z3.Field 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 Field

use of org.batfish.z3.Field 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 Field

use of org.batfish.z3.Field 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)

Example 10 with Field

use of org.batfish.z3.Field in project atlasmap by atlasmap.

the class DefaultAtlasValidationService method validateSeparateMapping.

private void validateSeparateMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        Validators.SEPARATE_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId);
        if (fieldMapping.getInputField() != null) {
            Validators.SEPARATE_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId);
        // source must be a String type
        }
        Validators.SEPARATE_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        Validators.SEPARATE_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        if (fieldMapping.getOutputField() != null) {
            for (Field field : fieldMapping.getOutputField()) {
                Validators.SEPARATE_OUTPUT_FIELD_NOT_NULL.get().validate(field, validations, mappingId);
                if (field.getIndex() == null || field.getIndex() < 0) {
                    Validators.SEPARATE_OUTPUT_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

Field (io.atlasmap.v2.Field)60 JavaField (io.atlasmap.java.v2.JavaField)15 Mapping (io.atlasmap.v2.Mapping)15 AtlasMapping (io.atlasmap.v2.AtlasMapping)14 SimpleField (io.atlasmap.v2.SimpleField)14 BaseMapping (io.atlasmap.v2.BaseMapping)12 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)11 Test (org.junit.Test)11 JsonField (io.atlasmap.json.v2.JsonField)8 LookupTable (io.atlasmap.v2.LookupTable)8 XmlField (io.atlasmap.xml.v2.XmlField)7 AtlasException (io.atlasmap.api.AtlasException)6 ConstantField (io.atlasmap.v2.ConstantField)6 AtlasConversionException (io.atlasmap.api.AtlasConversionException)5 JsonDocument (io.atlasmap.json.v2.JsonDocument)5 PropertyField (io.atlasmap.v2.PropertyField)5 ArrayList (java.util.ArrayList)5 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)4 AtlasModule (io.atlasmap.spi.AtlasModule)3 FieldType (io.atlasmap.v2.FieldType)3