Search in sources :

Example 21 with FieldGroup

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());
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) FieldGroup(io.atlasmap.v2.FieldGroup) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 22 with FieldGroup

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;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) FieldGroup(io.atlasmap.v2.FieldGroup) SimpleField(io.atlasmap.v2.SimpleField)

Example 23 with 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);
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlEnumField(io.atlasmap.xml.v2.XmlEnumField) FieldGroup(io.atlasmap.v2.FieldGroup) XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter)

Example 24 with FieldGroup

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);
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) PropertyField(io.atlasmap.v2.PropertyField) ConstantField(io.atlasmap.v2.ConstantField)

Example 25 with FieldGroup

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);
    }
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) PropertyField(io.atlasmap.v2.PropertyField) ConstantField(io.atlasmap.v2.ConstantField) AtlasModule(io.atlasmap.spi.AtlasModule) FieldGroup(io.atlasmap.v2.FieldGroup)

Aggregations

FieldGroup (io.atlasmap.v2.FieldGroup)110 Field (io.atlasmap.v2.Field)89 Test (org.junit.jupiter.api.Test)48 SimpleField (io.atlasmap.v2.SimpleField)32 AtlasPath (io.atlasmap.core.AtlasPath)28 ArrayList (java.util.ArrayList)24 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)17 CsvField (io.atlasmap.csv.v2.CsvField)16 AtlasException (io.atlasmap.api.AtlasException)15 Audits (io.atlasmap.v2.Audits)14 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)13 ConstantField (io.atlasmap.v2.ConstantField)13 Head (io.atlasmap.spi.AtlasInternalSession.Head)12 JsonField (io.atlasmap.json.v2.JsonField)11 Mapping (io.atlasmap.v2.Mapping)11 PropertyField (io.atlasmap.v2.PropertyField)11 JavaField (io.atlasmap.java.v2.JavaField)10 XmlField (io.atlasmap.xml.v2.XmlField)9 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)8 LinkedList (java.util.LinkedList)8