use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class PositiveIntegerValidator method validate.
@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
Integer value = (Integer) target;
if (value == null || value < 0) {
Validation validation = new Validation();
validation.setScope(scope);
validation.setId(id);
validation.setMessage(String.format(violationMessage, target != null ? target.toString() : null));
validation.setStatus(status);
validations.add(validation);
}
}
use of io.atlasmap.v2.Validation 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