Search in sources :

Example 6 with Validations

use of org.gluu.oxtrust.model.scim2.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 7 with Validations

use of org.gluu.oxtrust.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 8 with Validations

use of org.gluu.oxtrust.model.scim2.Validations in project atlasmap by atlasmap.

the class DefaultAtlasContextTest method testProcess.

@Test
public void testProcess() throws AtlasException {
    DefaultAtlasSession session = mock(DefaultAtlasSession.class);
    when(session.getAtlasContext()).thenReturn(context);
    Head head = mock(Head.class);
    when(session.head()).thenReturn(head);
    when(head.setMapping(any(Mapping.class))).thenReturn(head);
    when(head.setLookupTable(any(LookupTable.class))).thenReturn(head);
    Field headField = mock(ConstantField.class);
    when(head.getSourceField()).thenReturn(headField);
    Audits audits = mock(Audits.class);
    when(session.getAudits()).thenReturn(audits);
    Validations validations = mock(Validations.class);
    when(session.getValidations()).thenReturn(validations);
    AtlasMapping mapping = mock(AtlasMapping.class);
    when(session.getMapping()).thenReturn(mapping);
    when(session.hasErrors()).thenReturn(true);
    context.process(session);
    when(session.hasErrors()).thenReturn(false);
    Mappings mappings = mock(Mappings.class);
    when(mapping.getMappings()).thenReturn(mappings);
    List<BaseMapping> baseMappings = new ArrayList<>();
    Collection baseMapping = mock(Collection.class);
    when(baseMapping.getMappingType()).thenReturn(MappingType.COLLECTION);
    baseMappings.add(baseMapping);
    when(mappings.getMapping()).thenReturn(baseMappings);
    Mappings subMappings = mock(Mappings.class);
    when(baseMapping.getMappings()).thenReturn(subMappings);
    List<BaseMapping> baseMappingList = new ArrayList<>();
    Mapping mappingElement1 = mock(Mapping.class);
    List<Field> sourceFieldList = new ArrayList<>();
    ConstantField sourceField = mock(ConstantField.class);
    sourceFieldList.add(sourceField);
    when(sourceField.getPath()).thenReturn("contact.firstName");
    when(mappingElement1.getInputField()).thenReturn(sourceFieldList);
    List<Field> outputFieldList = new ArrayList<>();
    Field outputField = mock(Field.class);
    outputFieldList.add(outputField);
    when(outputField.getPath()).thenReturn("contact.firstName");
    when(mappingElement1.getOutputField()).thenReturn(outputFieldList);
    when(mappingElement1.getMappingType()).thenReturn(MappingType.ALL);
    baseMappingList.add(mappingElement1);
    when(subMappings.getMapping()).thenReturn(baseMappingList);
    Mapping mappingElement2 = mock(Mapping.class);
    when(mappingElement2.getMappingType()).thenReturn(MappingType.ALL);
    baseMappingList.add(mappingElement2);
    List<Field> sourceFieldList2 = new ArrayList<>();
    ConstantField sourceField2 = mock(ConstantField.class);
    sourceFieldList2.add(sourceField2);
    when(sourceField2.getPath()).thenReturn("contact[1]");
    when(mappingElement2.getInputField()).thenReturn(sourceFieldList2);
    ConstantModule mockConstantModule = mock(ConstantModule.class);
    when(mockConstantModule.getCollectionSize(any(AtlasInternalSession.class), any(Field.class))).thenReturn(1);
    ConstantField clonedField = mock(ConstantField.class);
    when(clonedField.getPath()).thenReturn("cloned[1]");
    when(mockConstantModule.cloneField(any(Field.class))).thenReturn(clonedField);
    List<Field> mockSourceFieldList = new ArrayList<>();
    ConstantField mockSourceField = mock(ConstantField.class);
    mockSourceFieldList.add(mockSourceField);
    when(mockSourceField.getPath()).thenReturn("source[1]");
    when(mappingElement2.getInputField()).thenReturn(mockSourceFieldList);
    List<Field> mockOutputFieldList = new ArrayList<>();
    ConstantField mockOutputField = mock(ConstantField.class);
    mockOutputFieldList.add(mockOutputField);
    when(mockOutputField.getPath()).thenReturn("output[1]");
    when(mappingElement2.getOutputField()).thenReturn(mockOutputFieldList);
    context.getSourceModules().put(DefaultAtlasContext.CONSTANTS_DOCUMENT_ID, mockConstantModule);
    context.process(session);
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) ConstantField(io.atlasmap.v2.ConstantField) ArrayList(java.util.ArrayList) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Field(io.atlasmap.v2.Field) ConstantField(io.atlasmap.v2.ConstantField) Validations(io.atlasmap.v2.Validations) Audits(io.atlasmap.v2.Audits) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTable(io.atlasmap.v2.LookupTable) Collection(io.atlasmap.v2.Collection) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 9 with Validations

use of org.gluu.oxtrust.model.scim2.Validations in project atlasmap by atlasmap.

the class JsonModule method processPreValidation.

@Override
public void processPreValidation(AtlasInternalSession atlasSession) throws AtlasException {
    if (atlasSession == null || atlasSession.getMapping() == null) {
        throw new AtlasValidationException("Invalid session: Session and AtlasMapping must be specified");
    }
    Validations validations = atlasSession.getValidations();
    JsonValidationService jsonValidationService = new JsonValidationService(getConversionService());
    jsonValidationService.setDocId(getDocId());
    List<Validation> jsonValidations = jsonValidationService.validateMapping(atlasSession.getMapping());
    if (jsonValidations != null && !jsonValidations.isEmpty()) {
        validations.getValidation().addAll(jsonValidations);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Detected " + jsonValidations.size() + " json validation notices");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreValidation completed", getDocId());
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) AtlasValidationException(io.atlasmap.api.AtlasValidationException)

Example 10 with Validations

use of org.gluu.oxtrust.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)

Aggregations

Validations (io.atlasmap.v2.Validations)15 Test (org.junit.Test)11 AtlasMappingBaseTest (io.atlasmap.validation.AtlasMappingBaseTest)8 Validation (io.atlasmap.v2.Validation)5 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)4 AtlasSession (io.atlasmap.api.AtlasSession)3 Audits (io.atlasmap.v2.Audits)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 AtlasContext (io.atlasmap.api.AtlasContext)2 File (java.io.File)2 URI (java.net.URI)2 Consumes (javax.ws.rs.Consumes)2 DefaultValue (javax.ws.rs.DefaultValue)2 HeaderParam (javax.ws.rs.HeaderParam)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)2 Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)2