Search in sources :

Example 1 with Validations

use of io.jans.scim.model.scim2.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.jans.scim.model.scim2.Validations in project atlasmap by atlasmap.

the class AtlasService method validateMapping.

protected Response validateMapping(AtlasMapping mapping, UriInfo uriInfo) throws IOException, AtlasException {
    File temporaryMappingFile = File.createTempFile("atlas-mapping", "xml");
    temporaryMappingFile.deleteOnExit();
    atlasContextFactory.getMappingService().saveMappingAsFile(mapping, temporaryMappingFile);
    AtlasContext context = atlasContextFactory.createContext(temporaryMappingFile.toURI());
    AtlasSession session = context.createSession();
    context.processValidation(session);
    Validations validations = session.getValidations();
    if (session.getValidations() == null) {
        validations = new Validations();
    }
    if (temporaryMappingFile.exists() && !temporaryMappingFile.delete()) {
        LOG.warn("Failed to deleting temporary file: " + (temporaryMappingFile != null ? temporaryMappingFile.toString() : null));
    }
    return Response.ok().entity(toJson(validations)).build();
}
Also used : Validations(io.atlasmap.v2.Validations) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession)

Example 3 with Validations

use of io.jans.scim.model.scim2.Validations in project atlasmap by atlasmap.

the class JavaJavaFlatMappingTest method testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues.

@Test
public void testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-flatprimitive.xml").toURI());
    AtlasSession session = context.createSession();
    BaseFlatPrimitiveClass sourceClass = generateFlatPrimitiveClassPrimitiveFieldsBoxedValues(SourceFlatPrimitiveClass.class);
    session.setDefaultSourceDocument(sourceClass);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof TargetFlatPrimitiveClass);
    validateFlatPrimitiveClassPrimitiveFields((TargetFlatPrimitiveClass) object);
    Validations validations = session.getValidations();
    for (Validation v : validations.getValidation()) {
        printValidation(v);
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) BaseFlatPrimitiveClass(io.atlasmap.java.test.BaseFlatPrimitiveClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest) Test(org.junit.Test)

Example 4 with Validations

use of io.jans.scim.model.scim2.Validations in project atlasmap by atlasmap.

the class AtlasCoreValidationTest method testJavaToJson.

@Test
public void testJavaToJson() throws AtlasException {
    assertNotNull(context);
    assertNotNull(session);
    context.processValidation(session);
    Validations validations = session.getValidations();
    assertNotNull(validations);
    assertNotNull(validations.getValidation());
    assertTrue(validations.getValidation().isEmpty());
}
Also used : Validations(io.atlasmap.v2.Validations) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.validation.AtlasMappingBaseTest)

Example 5 with Validations

use of io.jans.scim.model.scim2.Validations in project atlasmap by atlasmap.

the class AtlasCoreValidationTest method testMappingNameEmpty.

@Test
public void testMappingNameEmpty() 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());
        }
    }
    assertTrue(found);
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.validation.AtlasMappingBaseTest)

Aggregations

Validations (io.atlasmap.v2.Validations)26 Test (org.junit.jupiter.api.Test)11 Validation (io.atlasmap.v2.Validation)9 Test (org.junit.Test)9 AtlasMappingBaseTest (io.atlasmap.itests.validation.AtlasMappingBaseTest)8 AtlasMappingBaseTest (io.atlasmap.validation.AtlasMappingBaseTest)8 AtlasSession (io.atlasmap.api.AtlasSession)5 AtlasContext (io.atlasmap.api.AtlasContext)4 SCIMException (io.jans.scim.model.exception.SCIMException)4 Audits (io.atlasmap.v2.Audits)3 File (java.io.File)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 AtlasValidationException (io.atlasmap.api.AtlasValidationException)2 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)2 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)1 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)1 Head (io.atlasmap.spi.AtlasInternalSession.Head)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1