Search in sources :

Example 1 with LookupEntry

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

the class DefaultAtlasContextTest method testLookupTable.

@Test
public void testLookupTable() throws Exception {
    LookupTable table = new LookupTable();
    table.setName("table");
    LookupEntry e = new LookupEntry();
    e.setSourceValue("foo");
    e.setTargetValue("bar");
    table.getLookupEntry().add(e);
    context.getLookupTables().put(table.getName(), table);
    Mapping m = (Mapping) AtlasModelFactory.createMapping(MappingType.LOOKUP);
    mapping.getMappings().getMapping().add(m);
    m.setLookupTableName("table");
    populateSourceField(m, FieldType.STRING, "foo");
    prepareTargetField(m, "/target");
    context.process(session);
    Assert.assertFalse(printAudit(session), session.hasErrors());
    Assert.assertEquals("bar", writer.targets.get("/target"));
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) LookupTable(io.atlasmap.v2.LookupTable) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 2 with LookupEntry

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

the class BaseMarshallerTest method generateLookupTables.

private void generateLookupTables(AtlasMapping atlasMapping) {
    LookupTable table = new LookupTable();
    table.setName("lookupTable");
    table.setDescription("lookupTableDescription");
    LookupEntry l1 = new LookupEntry();
    l1.setSourceType(FieldType.STRING);
    l1.setSourceValue("Foo");
    l1.setTargetType(FieldType.STRING);
    l1.setTargetValue("Bar");
    table.getLookupEntry().add(l1);
    atlasMapping.getLookupTables().getLookupTable().add(table);
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) LookupTable(io.atlasmap.v2.LookupTable)

Example 3 with LookupEntry

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

the class BaseMarshallerTest method generateLookupTables.

private void generateLookupTables(AtlasMapping atlasMapping) {
    LookupTable table = new LookupTable();
    table.setName("lookupTable");
    table.setDescription("lookupTableDescription");
    LookupEntry l1 = new LookupEntry();
    l1.setSourceType(FieldType.STRING);
    l1.setSourceValue("Foo");
    l1.setTargetType(FieldType.STRING);
    l1.setTargetValue("Bar");
    table.getLookupEntry().add(l1);
    atlasMapping.getLookupTables().getLookupTable().add(table);
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) LookupTable(io.atlasmap.v2.LookupTable)

Example 4 with LookupEntry

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

the class BaseMarshallerTest method generateLookupTables.

private void generateLookupTables(AtlasMapping atlasMapping) {
    LookupTable table = new LookupTable();
    table.setName("lookupTable");
    table.setDescription("lookupTableDescription");
    LookupEntry l1 = new LookupEntry();
    l1.setSourceType(FieldType.STRING);
    l1.setSourceValue("Foo");
    l1.setTargetType(FieldType.STRING);
    l1.setTargetValue("Bar");
    table.getLookupEntry().add(l1);
    atlasMapping.getLookupTables().getLookupTable().add(table);
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) LookupTable(io.atlasmap.v2.LookupTable)

Example 5 with LookupEntry

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

the class BaseAtlasModule method processLookupField.

protected void processLookupField(AtlasInternalSession session, LookupTable lookupTable, Object sourceValue, Field targetField) throws AtlasException {
    String lookupValue = null;
    FieldType lookupType = null;
    for (LookupEntry lkp : lookupTable.getLookupEntry()) {
        if (lkp.getSourceValue().equals(sourceValue)) {
            lookupValue = lkp.getTargetValue();
            lookupType = lkp.getTargetType();
            break;
        }
    }
    Object targetValue = null;
    if (lookupType == null || FieldType.STRING.equals(lookupType)) {
        targetValue = lookupValue;
    } else {
        targetValue = atlasConversionService.convertType(lookupValue, FieldType.STRING, lookupType);
    }
    if (targetField.getFieldType() != null && !targetField.getFieldType().equals(lookupType)) {
        targetValue = atlasConversionService.convertType(targetValue, lookupType, targetField.getFieldType());
    }
    targetField.setValue(targetValue);
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) FieldType(io.atlasmap.v2.FieldType)

Aggregations

LookupEntry (io.atlasmap.v2.LookupEntry)6 LookupTable (io.atlasmap.v2.LookupTable)4 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasException (io.atlasmap.api.AtlasException)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 FieldType (io.atlasmap.v2.FieldType)1 Mapping (io.atlasmap.v2.Mapping)1 Test (org.junit.Test)1