use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateCustomMapping.
/**
* Validates the custom mapping.
* @param mapping custom mapping
* @param validations a container to put the result validations
*/
protected void validateCustomMapping(CustomMapping mapping, List<Validation> validations) {
if (mapping.getClassName() == null || mapping.getClassName().isEmpty()) {
Validation v = new Validation();
v.setScope(ValidationScope.MAPPING);
v.setMessage("Class name must be specified for custom mapping");
v.setStatus(ValidationStatus.ERROR);
validations.add(v);
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateCombineMapping.
/*
* vvv Remove in 2.0 vvv
*/
/**
* Validates combine mapping.
* @deprecated
* @param mapping mapping
* @param validations a container to put the result validations
*/
@Deprecated
protected void validateCombineMapping(Mapping mapping, List<Validation> validations) {
if (mapping == null) {
return;
}
List<Field> sourceFields = mapping.getInputField();
final List<Field> targetFields = mapping.getOutputField();
final Field targetField = (targetFields != null && !targetFields.isEmpty()) ? targetFields.get(0) : null;
if (targetField == null) {
return;
}
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) {
mappingFieldPairValidator.validateFieldTypes(validations, mappingId, sourceField, targetField);
}
}
// check that the output field is of type String else error
if (targetField.getFieldType() != null && targetField.getFieldType() != FieldType.STRING) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("Target field '%s' must be of type '%s' for a Combine Mapping", getFieldName(targetField), FieldType.STRING));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
validateField(mappingId, null, targetField, FieldDirection.TARGET, validations);
} else if (sourceFields != null) {
// SOURCE
for (Field sourceField : sourceFields) {
if (matchDocIdOrNull(sourceField.getDocId())) {
validateField(mappingId, null, sourceField, FieldDirection.SOURCE, validations);
}
}
}
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateMapping.
@Override
public List<Validation> validateMapping(AtlasMapping mapping) {
List<Validation> validations = new ArrayList<>();
if (getMode() == AtlasModuleMode.UNSET) {
Validation validation = new Validation();
validation.setMessage(String.format("No mode specified for %s/%s, skipping module validations", this.getModuleDetail().name(), this.getClass().getSimpleName()));
}
if (mapping != null && mapping.getMappings() != null && mapping.getMappings().getMapping() != null && !mapping.getMappings().getMapping().isEmpty()) {
validateMappingEntries(mapping.getMappings().getMapping(), validations);
}
boolean found = false;
for (DataSource ds : mapping.getDataSource()) {
if (ds.getUri() != null && ds.getUri().startsWith(getModuleDetail().uri())) {
found = true;
break;
}
}
if (!found) {
Validation validation = new Validation();
validation.setScope(ValidationScope.DATA_SOURCE);
validation.setMessage(String.format("No DataSource with '%s' uri specified", getModuleDetail().uri()));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
return validations;
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class BaseModuleValidationService method validateField.
/**
* Validates the field.
* @param mappingId mapping ID
* @param sourceField source field
* @param targetField target field
* @param direction direction
* @param validations a container to put the result validations
*/
@SuppressWarnings("unchecked")
protected void validateField(String mappingId, Field sourceField, Field targetField, FieldDirection direction, List<Validation> validations) {
if (targetField == null) {
return;
}
if (direction == FieldDirection.TARGET) {
Integer sourceCollectionCount = null;
if (sourceField != null) {
sourceCollectionCount = collectionHelper.determineSourceCollectionCount(null, sourceField);
}
Integer targetCollectionCount = collectionHelper.determineTargetCollectionCount(targetField);
if (sourceCollectionCount != null) {
if (sourceCollectionCount > targetCollectionCount) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
String message = String.format("Target [%s] has %s collection(s) on the path, whereas source has %s. Values from the %s rightmost " + "source collections on the path will be added in depth-first order to the rightmost target " + "collection(s) unless transformed explicitly.", targetField.getPath(), targetCollectionCount, sourceCollectionCount, sourceCollectionCount - targetCollectionCount + 1);
validation.setMessage(message);
validation.setStatus(ValidationStatus.WARN);
validations.add(validation);
} else if (sourceCollectionCount < targetCollectionCount) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("The 0 index will be used for any extra parent collections in " + "target [%s], since target has %s collections on the path, whereas source has %s.", targetField.getPath(), targetCollectionCount, sourceCollectionCount));
validation.setStatus(ValidationStatus.WARN);
validations.add(validation);
}
}
}
if (getFieldType().isAssignableFrom(targetField.getClass()) && matchDocIdOrNull(targetField.getDocId())) {
validateModuleField(mappingId, (T) targetField, direction, validations);
}
}
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);
}
}
}
Aggregations