use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithSimpleDocumentWithTargetColumnsDefined.
@Test
public void testWithSimpleDocumentWithTargetColumnsDefined() throws Exception {
CsvConfig csvConfig = new CsvConfig();
CsvFieldWriter writer = new CsvFieldWriter(csvConfig);
FieldGroup sourceField = new FieldGroup();
sourceField.setName("name");
sourceField.setPath("/<>/name");
CsvField sourceSubField0 = new CsvField();
sourceSubField0.setName("name");
sourceSubField0.setPath("/<0>/name");
sourceSubField0.setValue("Bob");
sourceField.getField().add(sourceSubField0);
CsvField sourceSubField1 = new CsvField();
sourceSubField1.setName("name");
sourceSubField1.setPath("/<1>/name");
sourceSubField1.setValue("Andrew");
sourceField.getField().add(sourceSubField1);
CsvField targetField = new CsvField();
targetField.setName("givenName");
targetField.setPath("/<>/givenName");
targetField.setColumn(1);
write(writer, sourceField, targetField);
FieldGroup secondSourceField = new FieldGroup();
CsvField secondSourceSubField = new CsvField();
secondSourceSubField.setName("familyName");
secondSourceSubField.setPath("/<0>/familyName");
secondSourceSubField.setValue("Smith");
secondSourceField.getField().add(secondSourceSubField);
CsvField secondSourceSubField1 = new CsvField();
secondSourceSubField1.setName("familyName");
secondSourceSubField1.setPath("/<1>/familyName");
secondSourceSubField1.setValue("Johnson");
secondSourceField.getField().add(secondSourceSubField1);
CsvField secondTargetField = new CsvField();
secondTargetField.setName("familyName");
secondTargetField.setPath("/<>/familyName");
secondTargetField.setColumn(0);
write(writer, secondSourceField, secondTargetField);
String csv = writer.toCsv();
assertEquals("familyName,givenName\r\nSmith,Bob\r\nJohnson,Andrew\r\n", csv);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithSimpleDocumentWithHeader.
@Test
public void testWithSimpleDocumentWithHeader() throws Exception {
CsvConfig csvConfig = new CsvConfig();
CsvFieldWriter writer = new CsvFieldWriter(csvConfig);
FieldGroup sourceField = new FieldGroup();
sourceField.setName("name");
sourceField.setPath("/<>/name");
CsvField sourceSubField0 = new CsvField();
sourceSubField0.setName("name");
sourceSubField0.setPath("/<0>/name");
sourceSubField0.setValue("Bob");
sourceField.getField().add(sourceSubField0);
CsvField sourceSubField1 = new CsvField();
sourceSubField1.setName("name");
sourceSubField1.setPath("/<1>/name");
sourceSubField1.setValue("Andrew");
sourceField.getField().add(sourceSubField1);
CsvField targetField = new CsvField();
targetField.setName("givenName");
targetField.setPath("/<>/givenName");
write(writer, sourceField, targetField);
String csv = writer.toCsv();
assertEquals("givenName\r\nBob\r\nAndrew\r\n", csv);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class JavaFieldReaderTest method testReadTopmostArrayComplex.
@Test
public void testReadTopmostArrayComplex() throws Exception {
TargetTestClass[] complexArray = new TargetTestClass[] { new TargetTestClass(), new TargetTestClass(), new TargetTestClass() };
complexArray[0].setAddress(new TargetAddress());
complexArray[0].getAddress().setAddressLine1("123 any street");
complexArray[2].setAddress(new TargetAddress());
complexArray[2].getAddress().setAddressLine1("1234 any street");
reader.setDocument(complexArray);
read("/[0]/address/addressLine1", FieldType.STRING);
assertEquals(0, audits.size());
assertEquals("123 any street", field.getValue());
assertEquals(0, audits.size());
readGroup("/[]/address/addressLine1", FieldType.STRING);
assertEquals(0, audits.size());
assertNotNull(fieldGroup);
assertEquals(2, fieldGroup.getField().size());
Field f = fieldGroup.getField().get(0);
assertEquals("/[0]/address/addressLine1", f.getPath());
assertEquals("123 any street", f.getValue());
f = fieldGroup.getField().get(1);
assertEquals("/[2]/address/addressLine1", f.getPath());
assertEquals("1234 any street", f.getValue());
assertEquals(0, audits.size());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class JavaFieldReaderTest method testReadParent.
@Test
public void testReadParent() throws Exception {
TargetTestClass source = new TargetTestClass();
LinkedList<TargetContact> contactList = new LinkedList<>();
for (int i = 0; i < 5; i++) {
TargetContact c = new TargetContact();
c.setFirstName("f" + i);
c.setLastName("l" + i);
c.setPhoneNumber("p" + i);
c.setZipCode("z" + i);
contactList.add(c);
}
source.setContactList(contactList);
reader.setDocument(source);
FieldGroup contactListGroup = new FieldGroup();
contactListGroup.setDocId("TargetTestClass");
contactListGroup.setPath("/contactList<>");
contactListGroup.setFieldType(FieldType.COMPLEX);
contactListGroup.setCollectionType(CollectionType.LIST);
Field firstNameField = new JavaField();
firstNameField.setDocId("TargetTestClass");
firstNameField.setPath("/contactList<>/firstName");
firstNameField.setFieldType(FieldType.STRING);
contactListGroup.getField().add(firstNameField);
fieldGroup = (FieldGroup) read(contactListGroup);
assertEquals(0, audits.size());
assertEquals("/contactList<>", fieldGroup.getPath());
assertEquals(FieldType.COMPLEX, fieldGroup.getFieldType());
assertEquals(CollectionType.LIST, fieldGroup.getCollectionType());
assertEquals(5, fieldGroup.getField().size());
Field contact0 = fieldGroup.getField().get(0);
assertEquals(FieldGroup.class, contact0.getClass());
FieldGroup contact0Group = (FieldGroup) contact0;
assertEquals(1, contact0Group.getField().size());
assertEquals("/contactList<0>", contact0Group.getPath());
assertEquals(FieldType.COMPLEX, contact0Group.getFieldType());
Field firstName0 = contact0Group.getField().get(0);
assertEquals("/contactList<0>/firstName", firstName0.getPath());
assertEquals(FieldType.STRING, firstName0.getFieldType());
assertEquals("f0", firstName0.getValue());
contactListGroup.setPath("/contactList<1>");
firstNameField.setPath("/contactList<1>/firstName");
fieldGroup = (FieldGroup) read(contactListGroup);
assertEquals(0, audits.size());
assertEquals(1, fieldGroup.getField().size());
Field firstName1 = fieldGroup.getField().get(0);
assertEquals("/contactList<1>/firstName", firstName1.getPath());
assertEquals(FieldType.STRING, firstName1.getFieldType());
assertEquals("f1", firstName1.getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class JavaFieldWriter method commitWriting.
/**
* Commits queued write tasks.
* @param session session
* @throws AtlasException unexpected error
*/
public void commitWriting(AtlasInternalSession session) throws AtlasException {
Field targetField = session.head().getTargetField();
try {
if (targetField instanceof FieldGroup) {
FieldGroup targetFieldGroup = (FieldGroup) targetField;
if (targetFieldGroup.getField().size() > 0) {
for (Field f : targetFieldGroup.getField()) {
session.head().setTargetField(f);
doCommitWriting(session);
}
} else {
AtlasPath path = new AtlasPath(targetField.getPath());
if (path.getLastSegment().getCollectionType() != CollectionType.NONE) {
// create an empty collection
doCommitWriting(session);
}
}
return;
}
doCommitWriting(session);
} finally {
if (!this.pathParentQueue.isEmpty()) {
LOG.warn("Discarding uncommitted entry in the queue: {}", this.pathParentQueue);
this.pathParentQueue.clear();
}
}
}
Aggregations