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);
}
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);
}
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());
}
}
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;
}
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;
}
Aggregations