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());
}
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());
}
}
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);
}
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);
}
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);
}
}
}
Aggregations