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