use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class MappingFieldPairValidator method doValidateFieldTypes.
/**
* Validates field types.
* @param validations a container to put the result {@link Validation}.
* @param mappingId mapping ID
* @param sourceField source field
* @param targetField target field
* @param sourceFieldType source field type
*/
protected void doValidateFieldTypes(List<Validation> validations, String mappingId, Field sourceField, Field targetField, FieldType sourceFieldType) {
if (sourceField == null && targetField == null || sourceField.getFieldType() == targetField.getFieldType()) {
return;
}
FieldType targetFieldType = targetField.getFieldType();
if (sourceFieldType == null || targetFieldType == null) {
return;
}
if (sourceFieldType == FieldType.ANY || targetFieldType == FieldType.ANY) {
return;
}
// skip converter check for COMPLEX source field (possible for conditional mapping)
if (sourceField.getFieldType() == FieldType.COMPLEX) {
return;
}
Optional<AtlasConverter<?>> atlasConverter = service.getConversionService().findMatchingConverter(sourceFieldType, targetFieldType);
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", sourceField.getFieldType(), targetField.getFieldType()));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
} else {
AtlasConversionInfo conversionInfo;
// find the method that does the conversion
FieldType sft = sourceFieldType;
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(sft) == 0 && atlasConversionInfo.targetType().compareTo(targetFieldType) == 0)).findFirst().orElse(null);
if (conversionInfo != null) {
populateConversionConcerns(validations, mappingId, conversionInfo, service.getFieldName(sourceField), service.getFieldName(targetField));
}
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class MappingFieldPairValidator method populateConversionConcerns.
/**
* Parses the {@link AtlasConversionInfo} annotation and add {@link Validation} for each concerns.
* @param validations a container to put the result {@link Validation}.
* @param mappingId mapping ID
* @param converterAnno annotation
* @param sourceFieldName source field name
* @param targetFieldName target field name
*/
public void populateConversionConcerns(List<Validation> validations, String mappingId, AtlasConversionInfo converterAnno, String sourceFieldName, String targetFieldName) {
if (converterAnno == null || converterAnno.concerns() == null) {
return;
}
for (AtlasConversionConcern atlasConversionConcern : converterAnno.concerns()) {
String message = atlasConversionConcern.getMessage(converterAnno);
if (AtlasConversionConcern.NONE.equals(atlasConversionConcern)) {
// just supported - even INFO is verbose
continue;
} else if (atlasConversionConcern.equals(AtlasConversionConcern.RANGE) || atlasConversionConcern.equals(AtlasConversionConcern.FORMAT) || atlasConversionConcern.equals(AtlasConversionConcern.FRACTIONAL_PART) || atlasConversionConcern.equals(AtlasConversionConcern.TIMEZONE)) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(message);
validation.setStatus(ValidationStatus.WARN);
validations.add(validation);
} else if (atlasConversionConcern.equals(AtlasConversionConcern.UNSUPPORTED)) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(message);
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class MappingFieldPairValidator method validateFieldTypes.
/**
* Validates field types by delegating to {@link #doValidateFieldTypes(List,String,Field,Field,FieldType)}.
* @param validations a container to put the result {@link Validation}
* @param mappingId mapping ID
* @param sourceFields source fields
* @param targetField target field
*/
public void validateFieldTypes(List<Validation> validations, String mappingId, List<Field> sourceFields, Field targetField) {
for (Field sourceField : sourceFields) {
if (!service.matchDocIdOrNull(sourceField.getDocId())) {
return;
}
FieldType actionOutputType = getActionOutputFieldType(validations, mappingId, sourceField);
doValidateFieldTypes(validations, mappingId, sourceField, targetField, actionOutputType != null ? actionOutputType : sourceField.getFieldType());
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class LookupTableNameValidator method validate.
@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
LookupTables lookupTables = (LookupTables) target;
List<LookupTable> tables = lookupTables.getLookupTable();
List<LookupTable> deduped = Collections.unmodifiableList(tables).stream().filter(distinctByKey(LookupTable::getName)).collect(Collectors.toList());
if (deduped.size() != tables.size()) {
String dupedName = findDuplicatedName(tables);
Validation validation = new Validation();
validation.setScope(ValidationScope.LOOKUP_TABLE);
validation.setId(id);
validation.setMessage(String.format(violationMessage, dupedName));
validation.setStatus(status);
validations.add(validation);
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class NotEmptyValidator method validate.
@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
if (!supports(target)) {
return;
}
if (((Collection<?>) target).isEmpty()) {
Validation validation = new Validation();
validation.setScope(scope);
validation.setId(id);
validation.setMessage(this.violationMessage);
validation.setStatus(status);
validations.add(validation);
}
}
Aggregations