Search in sources :

Example 1 with BaseMapping

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

the class DefaultAtlasContext method process.

/**
 * Process session lifecycle
 */
@Override
public void process(AtlasSession userSession) throws AtlasException {
    if (!(userSession instanceof DefaultAtlasSession)) {
        throw new AtlasException(String.format("Unsupported session class '%s'", userSession.getClass().getName()));
    }
    if (!this.equals(userSession.getAtlasContext())) {
        throw new AtlasException("Cannot execute AtlasSession created by the other AtlasContext");
    }
    DefaultAtlasSession session = (DefaultAtlasSession) userSession;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Begin process {}", (session == null ? null : session.toString()));
    }
    session.head().unset();
    session.getAudits().getAudit().clear();
    session.getValidations().getValidation().clear();
    processValidation(session);
    for (Validation v : session.getValidations().getValidation()) {
        AtlasUtil.addAudit(session, v);
    }
    if (session.hasErrors()) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Aborting due to {} errors in pre-validation", session.errorCount());
        }
        return;
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPreSourceExecution(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPreTargetExecution(session);
    }
    if (session.hasErrors()) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Aborting due to {} errors in pre-execution", session.errorCount());
        }
        return;
    }
    for (BaseMapping baseMapping : session.getMapping().getMappings().getMapping()) {
        for (Mapping mapping : extractCollectionMappings(session, baseMapping)) {
            session.head().setMapping(mapping).setLookupTable(lookupTables.get(mapping.getLookupTableName()));
            if (mapping.getOutputField() == null || mapping.getOutputField().isEmpty()) {
                AtlasUtil.addAudit(session, null, String.format("Mapping does not contain at least one output field: alias=%s desc=%s", mapping.getAlias(), mapping.getDescription()), null, AuditStatus.WARN, null);
                continue;
            }
            if (mapping.getInputField() == null || mapping.getInputField().isEmpty()) {
                AtlasUtil.addAudit(session, null, String.format("Mapping does not contain at least one source field: alias=%s desc=%s", mapping.getAlias(), mapping.getDescription()), null, AuditStatus.WARN, null);
            } else {
                processSourceFieldMappings(session, mapping.getInputField());
            }
            processTargetFieldMappings(session, mapping);
        }
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPostValidation(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPostValidation(session);
    }
    for (AtlasModule module : getSourceModules().values()) {
        module.processPostSourceExecution(session);
    }
    for (AtlasModule module : getTargetModules().values()) {
        module.processPostTargetExecution(session);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("End process {}", session == null ? null : session.toString());
    }
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasModule(io.atlasmap.spi.AtlasModule) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasException(io.atlasmap.api.AtlasException) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 2 with BaseMapping

use of io.atlasmap.v2.BaseMapping 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 3 with BaseMapping

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

the class AtlasMappingServiceTest method assertAtlasMapping.

private void assertAtlasMapping(AtlasMapping mapping) {
    Assert.assertNotNull(mapping);
    Assert.assertEquals("core-unit-test", mapping.getName());
    Assert.assertNotNull(mapping.getMappings());
    Assert.assertNotNull(mapping.getMappings().getMapping());
    Assert.assertNotNull(mapping.getMappings().getMapping().get(0));
    BaseMapping m = mapping.getMappings().getMapping().get(0);
    Assert.assertEquals(MappingType.MAP, m.getMappingType());
    Assert.assertEquals(Mapping.class, m.getClass());
    Assert.assertNotNull(((Mapping) m).getInputField());
    Field input = ((Mapping) m).getInputField().get(0);
    Assert.assertEquals("/orderId", input.getPath());
    Assert.assertNotNull(((Mapping) m).getOutputField());
    Field output = ((Mapping) m).getOutputField().get(0);
    Assert.assertEquals("/orderId", output.getPath());
}
Also used : Field(io.atlasmap.v2.Field) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 4 with BaseMapping

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

the class AtlasModuleSupportTest method testListTargetPathsListOfBaseMapping.

@Test
public void testListTargetPathsListOfBaseMapping() {
    List<BaseMapping> mappings = null;
    assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
    mappings = new ArrayList<>();
    assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
    Mapping mapping = new Mapping();
    Field field = new MockField();
    field.setPath("MockPath");
    mapping.getOutputField().add(field);
    mappings.add(mapping);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    Collection collection = null;
    mappings.add(collection);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    collection = new Collection();
    mappings.add(collection);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    Mappings mapings = new Mappings();
    collection.setMappings(mapings);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
}
Also used : MockField(io.atlasmap.v2.MockField) Field(io.atlasmap.v2.Field) MockField(io.atlasmap.v2.MockField) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 5 with BaseMapping

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

the class AtlasModuleSupportTest method testListTargetPathsAtlasMapping.

@Test
public void testListTargetPathsAtlasMapping() {
    AtlasMapping atlasMapping = null;
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    atlasMapping = new AtlasMapping();
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    Mappings mappings = new Mappings();
    atlasMapping.setMappings(mappings);
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    Mapping mapping = new Mapping();
    mappings.getMapping().add(mapping);
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    class MockMapping extends Mappings {

        private static final long serialVersionUID = 1L;

        @Override
        public List<BaseMapping> getMapping() {
            return null;
        }
    }
    Mappings mockMapping = new MockMapping();
    atlasMapping.setMappings(mockMapping);
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Aggregations

BaseMapping (io.atlasmap.v2.BaseMapping)16 Mapping (io.atlasmap.v2.Mapping)14 AtlasMapping (io.atlasmap.v2.AtlasMapping)13 Field (io.atlasmap.v2.Field)6 Mappings (io.atlasmap.v2.Mappings)4 Test (org.junit.Test)4 Collection (io.atlasmap.v2.Collection)3 AtlasException (io.atlasmap.api.AtlasException)2 JavaField (io.atlasmap.java.v2.JavaField)2 AtlasModule (io.atlasmap.spi.AtlasModule)2 ConstantField (io.atlasmap.v2.ConstantField)2 AtlasContext (io.atlasmap.api.AtlasContext)1 AtlasSession (io.atlasmap.api.AtlasSession)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 DefaultAtlasContextFactory (io.atlasmap.core.DefaultAtlasContextFactory)1 DocumentJavaFieldWriter (io.atlasmap.java.core.DocumentJavaFieldWriter)1 ClassInspectionService (io.atlasmap.java.inspect.ClassInspectionService)1 DateTimeClass (io.atlasmap.java.test.DateTimeClass)1 JavaClass (io.atlasmap.java.v2.JavaClass)1 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)1