use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldWriter method write.
/**
* Write is not performed until after the whole target document is ready and toCsv is called.
*
* @param session {@link AtlasInternalSession}
* @throws AtlasException unexpected error
*/
@Override
public void write(AtlasInternalSession session) throws AtlasException {
Field targetField = session.head().getTargetField();
Field sourceField = session.head().getSourceField();
if (sourceField instanceof FieldGroup) {
FieldGroup targetFieldGroup = AtlasModelFactory.createFieldGroupFrom(targetField, true);
for (Field sourceSubField : ((FieldGroup) sourceField).getField()) {
CsvField targetCsvField = (CsvField) targetField;
CsvField targetCsvSubField = new CsvField();
AtlasModelFactory.copyField(targetField, targetCsvSubField, false);
targetCsvSubField.setColumn(targetCsvField.getColumn());
targetCsvSubField.setValue(sourceSubField.getValue());
targetFieldGroup.getField().add(targetCsvSubField);
}
targetField = targetFieldGroup;
session.head().setTargetField(targetFieldGroup);
} else {
targetField.setValue(sourceField.getValue());
}
document.getFields().getField().add(targetField);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithSimpleDocumentWithoutHeader.
@Test
public void testWithSimpleDocumentWithoutHeader() throws Exception {
CsvConfig csvConfig = new CsvConfig();
csvConfig.setSkipHeaderRecord(true);
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("Bob\r\nAndrew\r\n", csv);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithHeaderAndIgnoreHeaderCase.
@Test
public void testWithHeaderAndIgnoreHeaderCase() throws Exception {
CsvConfig csvConfig = new CsvConfig();
csvConfig.setHeaders("FAMILYNAME,GIVENNAME");
csvConfig.setIgnoreHeaderCase(true);
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("FAMILYNAME,GIVENNAME\r\n,Bob\r\n,Andrew\r\n", csv);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithNoMatchingHeader.
@Test
public void testWithNoMatchingHeader() throws Exception {
CsvConfig csvConfig = new CsvConfig();
csvConfig.setHeaders("FAMILYNAME,GIVENNAME");
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("FAMILYNAME,GIVENNAME\r\n,\r\n,\r\n", csv);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldWriterTest method testWithSimpleDocumentWithHeaderSpecified.
@Test
public void testWithSimpleDocumentWithHeaderSpecified() throws Exception {
CsvConfig csvConfig = new CsvConfig();
csvConfig.setHeaders("givenName");
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);
}
Aggregations