use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class AtlasCoreValidationTest method testMappingNameNull.
@Test
public void testMappingNameNull() throws AtlasException {
assertNotNull(context);
assertNotNull(session);
context.processValidation(session);
Validations validations = session.getValidations();
assertNotNull(validations);
assertNotNull(validations.getValidation());
assertFalse(validations.getValidation().isEmpty());
boolean found = false;
for (Validation v : validations.getValidation()) {
if ("Mapping name must not be null nor empty".equals(v.getMessage())) {
found = true;
assertEquals(ValidationStatus.ERROR, v.getStatus());
assertEquals(ValidationScope.ALL, v.getScope());
}
System.out.println(AtlasValidationTestHelper.validationToString(v));
}
assertTrue(found);
}
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);
}
}
}
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 NonNullValidator method validate.
@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
if (target == null) {
Validation validation = new Validation();
validation.setScope(scope);
validation.setId(id);
validation.setMessage(violationMessage);
validation.setStatus(status);
validations.add(validation);
} else if (target.getClass().isAssignableFrom(String.class)) {
String value = (String) target;
if (value.trim().isEmpty()) {
// TODO: Add support for target value
Validation validation = new Validation();
validation.setScope(scope);
validation.setId(id);
validation.setMessage(violationMessage);
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