Search in sources :

Example 16 with AtlasPath

use of io.atlasmap.core.AtlasPath in project atlasmap by atlasmap.

the class KafkaConnectFieldReaderTest method testReadIndexedCollectionRootComplex.

@Test
public void testReadIndexedCollectionRootComplex() throws Exception {
    reader.setDocument(createTestDoc(3));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    FieldGroup field = createIndexedCollectionRootField(1);
    when(session.head().getSourceField()).thenReturn(field);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    FieldGroup answer = (FieldGroup) reader.read(session);
    assertEquals(4, answer.getField().size());
    assertRoot(answer, "/<" + 1 + ">", 1);
    Field f0 = createF0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(f0);
    assertf0(reader.read(session), "/<1>");
    Field fl0 = createFl0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(fl0);
    assertfl0((FieldGroup) reader.read(session), "/<1>", 1);
    Field fc0 = createFc0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(fc0);
    assertfc0((FieldGroup) reader.read(session), "/<1>");
    Field fcl0 = createFcl0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(fcl0);
    assertfcl0((FieldGroup) reader.read(session), "/<1>", 1);
}
Also used : KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) Field(io.atlasmap.v2.Field) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) Test(org.junit.jupiter.api.Test)

Example 17 with AtlasPath

use of io.atlasmap.core.AtlasPath in project atlasmap by atlasmap.

the class KafkaConnectFieldReaderTest method testReadCollectionRootComplex.

@Test
public void testReadCollectionRootComplex() throws Exception {
    reader.setDocument(createTestDoc(3));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    FieldGroup field = createCollectionRootField();
    when(session.head().getSourceField()).thenReturn(field);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    FieldGroup answer = (FieldGroup) reader.read(session);
    assertEquals(3, answer.getField().size());
    for (int i = 0; i < answer.getField().size(); i++) {
        assertRoot((FieldGroup) answer.getField().get(i), "/<" + i + ">", i);
    }
    Field f0 = createF0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(f0);
    FieldGroup f0answer = (FieldGroup) reader.read(session);
    assertEquals(3, f0answer.getField().size());
    for (int i = 0; i < f0answer.getField().size(); i++) {
        Field f = f0answer.getField().get(i);
        assertf0(f, "/<" + i + ">");
    }
    Field fl0 = createFl0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(fl0);
    FieldGroup fl0answer = (FieldGroup) reader.read(session);
    assertEquals(9, fl0answer.getField().size());
    assertfl0(Arrays.asList(fl0answer.getField().get(0), fl0answer.getField().get(1), fl0answer.getField().get(2)), "/<0>", 0);
    assertfl0(Arrays.asList(fl0answer.getField().get(3), fl0answer.getField().get(4), fl0answer.getField().get(5)), "/<1>", 1);
    assertfl0(Arrays.asList(fl0answer.getField().get(6), fl0answer.getField().get(7), fl0answer.getField().get(8)), "/<2>", 2);
    Field fc0 = createFc0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(fc0);
    FieldGroup fc0answer = (FieldGroup) reader.read(session);
    assertEquals(3, fc0answer.getField().size());
    for (int i = 0; i < fc0answer.getField().size(); i++) {
        FieldGroup f = (FieldGroup) fc0answer.getField().get(i);
        assertfc0(f, "/<" + i + ">");
    }
    Field fcl0 = createFcl0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(fcl0);
    FieldGroup fcl0answer = (FieldGroup) reader.read(session);
    assertEquals(9, fcl0answer.getField().size());
    assertfcl0(Arrays.asList(fcl0answer.getField().get(0), fcl0answer.getField().get(1), fcl0answer.getField().get(2)), "/<0>", 0);
    assertfcl0(Arrays.asList(fcl0answer.getField().get(3), fcl0answer.getField().get(4), fcl0answer.getField().get(5)), "/<1>", 1);
    assertfcl0(Arrays.asList(fcl0answer.getField().get(6), fcl0answer.getField().get(7), fcl0answer.getField().get(8)), "/<2>", 2);
}
Also used : KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) Field(io.atlasmap.v2.Field) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) Test(org.junit.jupiter.api.Test)

Example 18 with AtlasPath

use of io.atlasmap.core.AtlasPath in project atlasmap by atlasmap.

the class KafkaConnectModule method populateTargetField.

@Override
public void populateTargetField(AtlasInternalSession session) throws AtlasException {
    Field sourceField = session.head().getSourceField();
    Field targetField = session.head().getTargetField();
    AtlasPath path = new AtlasPath(targetField.getPath());
    FieldGroup targetFieldGroup = null;
    if (path.hasCollection() && !path.isIndexedCollection()) {
        targetFieldGroup = AtlasModelFactory.createFieldGroupFrom(targetField, true);
        session.head().setTargetField(targetFieldGroup);
    }
    // Attempt to Auto-detect field type based on input value
    if (targetField.getFieldType() == null && sourceField.getValue() != null) {
        targetField.setFieldType(getConversionService().fieldTypeFromClass(sourceField.getValue().getClass()));
    }
    if (targetFieldGroup == null) {
        if (sourceField instanceof FieldGroup) {
            List<Field> subFields = ((FieldGroup) sourceField).getField();
            if (subFields != null && subFields.size() > 0) {
                Integer index = targetField.getIndex();
                if (index != null) {
                    if (subFields.size() > index) {
                        sourceField = subFields.get(index);
                    } else {
                        AtlasUtil.addAudit(session, getDocId(), String.format("The number of source fields (%s) is smaller than target index (%s) - ignoring", subFields.size(), index), AuditStatus.WARN, null);
                        return;
                    }
                } else {
                    // The last one wins for compatibility
                    sourceField = subFields.get(subFields.size() - 1);
                }
                session.head().setSourceField(sourceField);
            }
        }
        super.populateTargetField(session);
    } else if (sourceField instanceof FieldGroup) {
        Field previousTargetSubField = null;
        for (int i = 0; i < ((FieldGroup) sourceField).getField().size(); i++) {
            Field sourceSubField = ((FieldGroup) sourceField).getField().get(i);
            KafkaConnectField targetSubField = AtlasKafkaConnectModelFactory.createKafkaConnectField();
            AtlasKafkaConnectModelFactory.copyField(targetField, targetSubField, false);
            getCollectionHelper().copyCollectionIndexes(sourceField, sourceSubField, targetSubField, previousTargetSubField);
            previousTargetSubField = targetSubField;
            targetFieldGroup.getField().add(targetSubField);
            session.head().setSourceField(sourceSubField);
            session.head().setTargetField(targetSubField);
            super.populateTargetField(session);
        }
        session.head().setSourceField(sourceField);
        session.head().setTargetField(targetFieldGroup);
    } else {
        KafkaConnectField targetSubField = new KafkaConnectField();
        AtlasKafkaConnectModelFactory.copyField(targetField, targetSubField, false);
        path.setVacantCollectionIndex(0);
        targetSubField.setPath(path.toString());
        targetFieldGroup.getField().add(targetSubField);
        session.head().setTargetField(targetSubField);
        super.populateTargetField(session);
        session.head().setTargetField(targetFieldGroup);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processTargetFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}], TargetField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue(), targetField.getDocId(), targetField.getPath(), targetField.getFieldType(), targetField.getValue());
    }
}
Also used : Field(io.atlasmap.v2.Field) KafkaConnectEnumField(io.atlasmap.kafkaconnect.v2.KafkaConnectEnumField) KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField)

Example 19 with AtlasPath

use of io.atlasmap.core.AtlasPath in project atlasmap by atlasmap.

the class KafkaConnectFieldReaderTest method createFcl0Field.

private FieldGroup createFcl0Field(AtlasPath parentPath) {
    FieldGroup fcl0Field = new FieldGroup();
    AtlasPath path = parentPath.clone().appendField("fcl0<>");
    fcl0Field.setPath(path.toString());
    fcl0Field.setFieldType(FieldType.COMPLEX);
    fcl0Field.setCollectionType(CollectionType.LIST);
    fcl0Field.getField().add(createF0Field(path));
    return fcl0Field;
}
Also used : FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath)

Example 20 with AtlasPath

use of io.atlasmap.core.AtlasPath in project atlasmap by atlasmap.

the class KafkaConnectFieldReaderTest method doCreateRootField.

private FieldGroup doCreateRootField(String rootPath) {
    AtlasPath path = new AtlasPath(rootPath);
    FieldGroup field = new FieldGroup();
    field.setPath(path.toString());
    field.setFieldType(FieldType.COMPLEX);
    if (rootPath.contains("<")) {
        field.setCollectionType(CollectionType.LIST);
    }
    field.getField().add(createF0Field(path));
    field.getField().add(createFl0Field(path));
    field.getField().add(createFc0Field(path));
    field.getField().add(createFcl0Field(path));
    return field;
}
Also used : FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath)

Aggregations

AtlasPath (io.atlasmap.core.AtlasPath)49 Field (io.atlasmap.v2.Field)27 FieldGroup (io.atlasmap.v2.FieldGroup)26 AtlasException (io.atlasmap.api.AtlasException)17 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)14 JavaField (io.atlasmap.java.v2.JavaField)12 ArrayList (java.util.ArrayList)12 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)11 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)11 JsonField (io.atlasmap.json.v2.JsonField)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 JsonEnumField (io.atlasmap.json.v2.JsonEnumField)4 Method (java.lang.reflect.Method)4 List (java.util.List)4 Test (org.junit.Test)4 SourceAddress (io.atlasmap.java.test.SourceAddress)3 SourceOrder (io.atlasmap.java.test.SourceOrder)3 KafkaConnectEnumField (io.atlasmap.kafkaconnect.v2.KafkaConnectEnumField)3 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)3 Head (io.atlasmap.spi.AtlasInternalSession.Head)3