Search in sources :

Example 11 with LookupTable

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

the class DefaultAtlasValidationServiceTest method testValidateAtlasMappingFileNoLookupFieldMappingsWithTablesDefined.

@Test
public void testValidateAtlasMappingFileNoLookupFieldMappingsWithTablesDefined() {
    AtlasMapping mapping = getAtlasMappingFullValid();
    LookupTables lookupTables = new LookupTables();
    mapping.setLookupTables(lookupTables);
    LookupTable lookupTable = new LookupTable();
    lookupTable.setName("table1");
    lookupTable.setDescription("desc_table1");
    lookupTables.getLookupTable().add(lookupTable);
    validations.addAll(validationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) LookupTables(io.atlasmap.v2.LookupTables) LookupTable(io.atlasmap.v2.LookupTable) Test(org.junit.Test) BaseValidatorTest(io.atlasmap.validators.BaseValidatorTest)

Example 12 with LookupTable

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

the class XmlModule method processTargetFieldMapping.

@Override
public void processTargetFieldMapping(AtlasInternalSession session) throws AtlasException {
    Field sourceField = session.head().getSourceField();
    Field targetField = session.head().getTargetField();
    // Attempt to Auto-detect field type based on input value
    if (targetField.getFieldType() == null && sourceField.getValue() != null) {
        targetField.setFieldType(getConversionService().fieldTypeFromClass(sourceField.getValue().getClass()));
    }
    Object outputValue = null;
    // Do auto-conversion
    if (sourceField.getFieldType() != null && sourceField.getFieldType().equals(targetField.getFieldType())) {
        outputValue = sourceField.getValue();
    } else if (sourceField.getValue() != null) {
        try {
            outputValue = getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), targetField.getFieldType(), targetField.getFormat());
        } catch (AtlasConversionException e) {
            AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Unable to auto-convert for sT=%s tT=%s tF=%s msg=%s", sourceField.getFieldType(), targetField.getFieldType(), targetField.getPath(), e.getMessage()), targetField.getPath(), AuditStatus.ERROR, null);
            return;
        }
    }
    targetField.setValue(outputValue);
    LookupTable lookupTable = session.head().getLookupTable();
    if (lookupTable != null) {
        processLookupField(session, lookupTable, targetField.getValue(), targetField);
    }
    if (isAutomaticallyProcessOutputFieldActions() && targetField.getActions() != null && targetField.getActions().getActions() != null) {
        getFieldActionService().processActions(targetField.getActions(), targetField);
    }
    XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
    writer.write(session);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processTargetFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}], TargetField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue(), targetField.getDocId(), targetField.getPath(), targetField.getFieldType(), targetField.getValue());
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) LookupTable(io.atlasmap.v2.LookupTable) XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter)

Example 13 with LookupTable

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

the class BaseMarshallerTest method generateLookupTables.

private void generateLookupTables(AtlasMapping atlasMapping) {
    LookupTable table = new LookupTable();
    table.setName("lookupTable");
    table.setDescription("lookupTableDescription");
    LookupEntry l1 = new LookupEntry();
    l1.setSourceType(FieldType.STRING);
    l1.setSourceValue("Foo");
    l1.setTargetType(FieldType.STRING);
    l1.setTargetValue("Bar");
    table.getLookupEntry().add(l1);
    atlasMapping.getLookupTables().getLookupTable().add(table);
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) LookupTable(io.atlasmap.v2.LookupTable)

Example 14 with LookupTable

use of io.atlasmap.v2.LookupTable 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 15 with LookupTable

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

the class DefaultAtlasValidationService method validateLookupFieldMapping.

// mapping field validations
private void validateLookupFieldMapping(List<Mapping> fieldMappings, LookupTables lookupTables, List<Validation> validations, Set<String> usedIds) {
    Set<String> lookupFieldMappingTableNameRefs = fieldMappings.stream().map(Mapping::getLookupTableName).collect(Collectors.toSet());
    Set<String> tableNames = lookupTables.getLookupTable().stream().map(LookupTable::getName).collect(Collectors.toSet());
    if (!lookupFieldMappingTableNameRefs.isEmpty() && !tableNames.isEmpty()) {
        Set<String> disjoint = Stream.concat(lookupFieldMappingTableNameRefs.stream(), tableNames.stream()).collect(Collectors.toMap(Function.identity(), t -> true, (a, b) -> null)).keySet();
        if (!disjoint.isEmpty()) {
            boolean isInFieldList = !lookupFieldMappingTableNameRefs.stream().filter(disjoint::contains).collect(Collectors.toList()).isEmpty();
            boolean isInTableNameList = !tableNames.stream().filter(disjoint::contains).collect(Collectors.toList()).isEmpty();
            // which list has the disjoin.... if its the lookup fields then ERROR
            if (isInFieldList) {
                Validation validation = new Validation();
                validation.setScope(ValidationScope.LOOKUP_TABLE);
                validation.setMessage("One ore more LookupFieldMapping references a non existent LookupTable name in the mapping: " + disjoint.toString());
                validation.setStatus(ValidationStatus.ERROR);
                validations.add(validation);
            }
            // uses it, else WARN
            if (isInTableNameList) {
                Validation validation = new Validation();
                validation.setScope(ValidationScope.LOOKUP_TABLE);
                validation.setMessage("A LookupTable is defined but not used by any LookupField: " + disjoint.toString());
                validation.setStatus(ValidationStatus.WARN);
                validations.add(validation);
            }
        }
    }
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        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 : Validation(io.atlasmap.v2.Validation) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Aggregations

LookupTable (io.atlasmap.v2.LookupTable)16 Field (io.atlasmap.v2.Field)7 AtlasMapping (io.atlasmap.v2.AtlasMapping)6 LookupEntry (io.atlasmap.v2.LookupEntry)6 LookupTables (io.atlasmap.v2.LookupTables)6 AtlasException (io.atlasmap.api.AtlasException)5 Mapping (io.atlasmap.v2.Mapping)5 AtlasConversionException (io.atlasmap.api.AtlasConversionException)4 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)3 JavaField (io.atlasmap.java.v2.JavaField)3 FieldType (io.atlasmap.v2.FieldType)3 Test (org.junit.Test)3 BaseMapping (io.atlasmap.v2.BaseMapping)2 MockField (io.atlasmap.v2.MockField)2 Validation (io.atlasmap.v2.Validation)2 BaseValidatorTest (io.atlasmap.validators.BaseValidatorTest)2 AtlasFieldActionService (io.atlasmap.api.AtlasFieldActionService)1 AtlasPath (io.atlasmap.core.AtlasPath)1 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)1 TargetAddress (io.atlasmap.java.test.TargetAddress)1