Search in sources :

Example 1 with Validations

use of io.atlasmap.v2.Validations in project oxTrust by GluuFederation.

the class ResourceValidator method validateValidableAttributes.

/**
 * Inspects the resource passed in the constructor and applies validations for every attribute annotated with
 * {@link Validator}. Validations are of different nature as seen{@link Validations here}.
 * @throws SCIMException When a validation does not pass (the {@link Validations#apply(Validations, Object) apply}
 * method returns false)
 */
public void validateValidableAttributes() throws SCIMException {
    Map<String, List<Method>> map = IntrospectUtil.validableCoreAttrs.get(resourceClass);
    for (String attributePath : map.keySet()) {
        Field f = IntrospectUtil.findFieldFromPath(resourceClass, attributePath);
        Validations valToApply = f.getAnnotation(Validator.class).value();
        log.debug("Validating value(s) of attribute '{}'", attributePath);
        for (Object val : IntrospectUtil.getAttributeValues(resource, map.get(attributePath))) {
            if (val != null && !Validations.apply(valToApply, val)) {
                log.error("Error validating attribute '{}', wrong value supplied: '{}'", attributePath, val.toString());
                throw new SCIMException(String.format(ATTR_VALIDATION_FAILED, attributePath));
            }
        }
    }
}
Also used : ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) Field(java.lang.reflect.Field) Validations(org.gluu.oxtrust.model.scim2.Validations) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) Validator(org.gluu.oxtrust.model.scim2.annotations.Validator)

Example 2 with Validations

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

the class DefaultAtlasSession method initialize.

protected void initialize() {
    properties = new ConcurrentHashMap<String, Object>();
    validations = new Validations();
    audits = new Audits();
    head.unset();
}
Also used : Validations(io.atlasmap.v2.Validations) Audits(io.atlasmap.v2.Audits)

Example 3 with Validations

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

the class DefaultAtlasContext method doCreateSession.

private AtlasSession doCreateSession() {
    AtlasSession session = new DefaultAtlasSession(mappingDefinition);
    session.setAtlasContext(this);
    session.setAudits(new Audits());
    session.setValidations(new Validations());
    setDefaultSessionProperties(session);
    return session;
}
Also used : Validations(io.atlasmap.v2.Validations) Audits(io.atlasmap.v2.Audits) AtlasSession(io.atlasmap.api.AtlasSession)

Example 4 with Validations

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

the class DefaultAtlasValidationService method validateMapMapping.

private void validateMapMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        Validators.MAP_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId);
        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);
        }
    }
}
Also used : BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 5 with Validations

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

the class DefaultAtlasValidationService method validateCombineMapping.

private void validateCombineMapping(List<Mapping> fieldMappings, List<Validation> validations, Set<String> usedIds) {
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        Validators.COMBINE_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId);
        if (fieldMapping.getOutputField() != null) {
            Validators.COMBINE_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId);
        // source must be a String type
        }
        Validators.COMBINE_INPUT_NOT_NULL.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
        Validators.COMBINE_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId, ValidationStatus.WARN);
        if (fieldMapping.getInputField() != null) {
            for (Field field : fieldMapping.getInputField()) {
                Validators.COMBINE_INPUT_FIELD_NOT_NULL.get().validate(field, validations, mappingId);
                if (field.getIndex() == null || field.getIndex() < 0) {
                    Validators.COMBINE_INPUT_FIELD_FIELD_ACTION_INDEX_POSITIVE.get().validate(field.getIndex(), validations, mappingId);
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Aggregations

Validation (io.atlasmap.v2.Validation)36 Test (org.junit.Test)26 AtlasMapping (io.atlasmap.v2.AtlasMapping)17 Mapping (io.atlasmap.v2.Mapping)17 Validations (io.atlasmap.v2.Validations)15 DataSource (io.atlasmap.v2.DataSource)10 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)9 FieldType (io.atlasmap.v2.FieldType)9 ValidationScope (io.atlasmap.v2.ValidationScope)9 ValidationStatus (io.atlasmap.v2.ValidationStatus)9 List (java.util.List)9 Before (org.junit.Before)9 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)8 Field (io.atlasmap.v2.Field)8 MappingType (io.atlasmap.v2.MappingType)8 AtlasMappingBaseTest (io.atlasmap.validation.AtlasMappingBaseTest)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)7 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)7