Search in sources :

Example 1 with ValidationStatus

use of io.atlasmap.v2.ValidationStatus in project atlasmap by atlasmap.

the class StringLengthValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    String value = (String) target;
    if (value.isEmpty() || value.length() > maxLength || value.length() < minLength) {
        Validation validation = new Validation();
        validation.setScope(scope);
        validation.setId(id);
        validation.setMessage(String.format(violationMessage, target.toString()));
        validation.setStatus(status);
        validations.add(validation);
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 2 with ValidationStatus

use of io.atlasmap.v2.ValidationStatus in project atlasmap by atlasmap.

the class StringPatternValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    Pattern regEx = Pattern.compile(pattern);
    if (target != null && supports(target.getClass())) {
        String value = (String) target;
        Matcher m = regEx.matcher(value);
        if (useMatch) {
            if (!m.matches()) {
                Validation validation = new Validation();
                validation.setScope(scope);
                validation.setId(id);
                validation.setMessage(String.format(violationMessage, target.toString()));
                validation.setStatus(status);
                validations.add(validation);
            }
        } else {
            if (m.find()) {
                Validation validation = new Validation();
                validation.setScope(scope);
                validation.setId(id);
                validation.setMessage(String.format(violationMessage, target.toString()));
                validation.setStatus(status);
                validations.add(validation);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 3 with ValidationStatus

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

Example 4 with ValidationStatus

use of io.atlasmap.v2.ValidationStatus 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)

Example 5 with ValidationStatus

use of io.atlasmap.v2.ValidationStatus 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);
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Collection(java.util.Collection)

Aggregations

Validation (io.atlasmap.v2.Validation)6 LookupTable (io.atlasmap.v2.LookupTable)1 LookupTables (io.atlasmap.v2.LookupTables)1 Collection (java.util.Collection)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1