use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testScopedProperty.
@Test
public void testScopedProperty() throws Exception {
FieldGroup source = new FieldGroup();
PropertyField doc1Prop = new PropertyField();
doc1Prop.setDocId("DOC.Properties.85731");
doc1Prop.setScope("Doc1");
doc1Prop.setPath("/Doc1/testprop");
doc1Prop.setName("testprop");
doc1Prop.setValue("doc1prop");
source.getField().add(doc1Prop);
PropertyField doc2Prop = new PropertyField();
doc2Prop.setDocId("DOC.Properties.85731");
doc2Prop.setScope("Doc2");
doc2Prop.setPath("/Doc2/testprop");
doc2Prop.setName("testprop");
doc2Prop.setValue("doc2prop");
source.getField().add(doc2Prop);
PropertyField currentProp = new PropertyField();
currentProp.setDocId("DOC.Properties.85731");
currentProp.setPath("/testprop");
currentProp.setName("testprop");
currentProp.setValue("currentprop");
source.getField().add(currentProp);
String expression = "${DOC.Properties.85731:/Doc1/testprop} + ${DOC.Properties.85731:/Doc2/testprop}" + " + ${DOC.Properties.85731:/testprop}";
recreateSession();
context.getSourceModules().put(AtlasConstants.PROPERTIES_SOURCE_DOCUMENT_ID, new PropertyModule(new DefaultAtlasPropertyStrategy()));
session.head().setSourceField(source);
DefaultAtlasExpressionProcessor.processExpression(session, expression);
assertFalse(session.hasErrors(), printAudit(session));
assertEquals(SimpleField.class, session.head().getSourceField().getClass());
SimpleField field = (SimpleField) session.head().getSourceField();
assertEquals("$ATLASMAP", field.getPath());
assertEquals("doc1propdoc2propcurrentprop", field.getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class BaseDefaultAtlasContextTest method populateCollectionSourceField.
protected FieldGroup populateCollectionSourceField(Mapping mapping, String docId, String seed) {
String basePath = "/testPath" + seed;
FieldGroup fieldGroup = new FieldGroup();
fieldGroup.setFieldType(FieldType.STRING);
fieldGroup.setDocId(docId);
fieldGroup.setPath(basePath + "<>");
if (mapping != null) {
mapping.setInputFieldGroup(fieldGroup);
}
for (int i = 0; i < 10; i++) {
Field child = new SimpleField();
child.setFieldType(FieldType.STRING);
child.setDocId(docId);
child.setPath(basePath + "<" + i + ">");
child.setValue(seed + i);
child.setIndex(i);
fieldGroup.getField().add(child);
reader.sources.put(child.getPath(), child.getValue());
}
reader.sources.put(fieldGroup.getPath(), fieldGroup);
return fieldGroup;
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class XmlModule method writeTargetValue.
@Override
public void writeTargetValue(AtlasInternalSession session) throws AtlasException {
XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
if (session.head().getTargetField() instanceof FieldGroup) {
FieldGroup targetFieldGroup = (FieldGroup) session.head().getTargetField();
if (targetFieldGroup.getField().size() > 0) {
for (Field f : targetFieldGroup.getField()) {
session.head().setTargetField(f);
writer.write(session);
}
return;
}
}
writer.write(session);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasContext method processSourceFieldGroup.
private void processSourceFieldGroup(DefaultAtlasSession session, FieldGroup sourceFieldGroup) throws AtlasException {
processSourceFields(session, sourceFieldGroup.getField());
session.head().setSourceField(sourceFieldGroup);
Field processed = applyFieldActions(session, session.head().getSourceField());
session.head().setSourceField(processed);
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasContext method processSourceFields.
private void processSourceFields(DefaultAtlasSession session, List<Field> sourceFields) throws AtlasException {
for (int i = 0; i < sourceFields.size(); i++) {
Field sourceField = sourceFields.get(i);
session.head().setSourceField(sourceField);
if (sourceField instanceof FieldGroup) {
processSourceFields(session, ((FieldGroup) sourceField).getField());
Field processed = applyFieldActions(session, sourceField);
session.head().setSourceField(processed);
continue;
}
AtlasModule module = resolveModule(FieldDirection.SOURCE, sourceField);
if (module == null) {
AtlasUtil.addAudit(session, sourceField, String.format("Module not found for docId '%s'", sourceField.getDocId()), AuditStatus.ERROR, null);
return;
}
if (!module.isSupportedField(sourceField)) {
AtlasUtil.addAudit(session, sourceField, String.format("Unsupported source field type '%s' for DataSource '%s'", sourceField.getClass().getName(), module.getUri()), AuditStatus.ERROR, null);
return;
}
module.readSourceValue(session);
Field processed = applyFieldActions(session, session.head().getSourceField());
session.head().setSourceField(processed);
sourceFields.set(i, processed);
}
}
Aggregations