Search in sources :

Example 61 with Validation

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);
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 62 with Validation

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);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field)

Example 63 with Validation

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;
}
Also used : Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource)

Example 64 with Validation

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);
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 65 with 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);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Aggregations

Validation (io.atlasmap.v2.Validation)55 AtlasMapping (io.atlasmap.v2.AtlasMapping)18 Field (io.atlasmap.v2.Field)16 Test (org.junit.jupiter.api.Test)16 Mapping (io.atlasmap.v2.Mapping)14 Validations (io.atlasmap.v2.Validations)10 JavaField (io.atlasmap.java.v2.JavaField)6 BaseMapping (io.atlasmap.v2.BaseMapping)6 FieldType (io.atlasmap.v2.FieldType)6 AtlasException (io.atlasmap.api.AtlasException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 AtlasConversionConcern (io.atlasmap.spi.AtlasConversionConcern)4 AtlasConversionInfo (io.atlasmap.spi.AtlasConversionInfo)4 FieldGroup (io.atlasmap.v2.FieldGroup)4 ValidationScope (io.atlasmap.v2.ValidationScope)4 ValidationStatus (io.atlasmap.v2.ValidationStatus)4 Method (java.lang.reflect.Method)4 Arrays (java.util.Arrays)4 Optional (java.util.Optional)4