Search in sources :

Example 46 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class AtlasModuleSupportTest method testListTargetPathsListOfBaseMapping.

@Test
public void testListTargetPathsListOfBaseMapping() {
    List<BaseMapping> mappings = null;
    assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
    mappings = new ArrayList<>();
    assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
    Mapping mapping = new Mapping();
    Field field = new MockField();
    field.setPath("MockPath");
    mapping.getOutputField().add(field);
    mappings.add(mapping);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    Collection collection = null;
    mappings.add(collection);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    collection = new Collection();
    mappings.add(collection);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    Mappings mapings = new Mappings();
    collection.setMappings(mapings);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
}
Also used : MockField(io.atlasmap.v2.MockField) Field(io.atlasmap.v2.Field) MockField(io.atlasmap.v2.MockField) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 47 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class DocumentJavaFieldReader method read.

@Override
public void read(AtlasInternalSession session) throws AtlasException {
    try {
        Field sourceField = session.head().getSourceField();
        Method getter = null;
        if (sourceField.getFieldType() == null && (sourceField instanceof JavaField || sourceField instanceof JavaEnumField)) {
            getter = resolveGetMethod(sourceDocument, sourceField);
            if (getter == null) {
                AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Unable to auto-detect sourceField type path=%s docId=%s", sourceField.getPath(), sourceField.getDocId()), sourceField.getPath(), AuditStatus.WARN, null);
                return;
            }
            Class<?> returnType = getter.getReturnType();
            sourceField.setFieldType(conversionService.fieldTypeFromClass(returnType));
            if (LOG.isTraceEnabled()) {
                LOG.trace("Auto-detected sourceField type p=" + sourceField.getPath() + " t=" + sourceField.getFieldType());
            }
        }
        populateSourceFieldValue(session, sourceField, sourceDocument, getter);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Processed input field sPath=" + sourceField.getPath() + " sV=" + sourceField.getValue() + " sT=" + sourceField.getFieldType() + " docId: " + sourceField.getDocId());
        }
    } catch (Exception e) {
        throw new AtlasException(e);
    }
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField) Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) Method(java.lang.reflect.Method) AtlasException(io.atlasmap.api.AtlasException) AtlasException(io.atlasmap.api.AtlasException)

Example 48 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class BaseDocumentWriterTest method write.

protected void write(String path, StateEnumClassLong targetValue) throws AtlasException {
    Field field = createEnumField(path, targetValue);
    setTargetValue(targetValue);
    write(field);
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField)

Example 49 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class JavaFieldReader method read.

@Override
public Field read(AtlasInternalSession session) throws AtlasException {
    try {
        Field field = session.head().getSourceField();
        if (sourceDocument == null) {
            AtlasUtil.addAudit(session, field, String.format("Unable to read sourceField (path=%s),  document (docId=%s) is null", field.getPath(), field.getDocId()), AuditStatus.ERROR, null);
        }
        AtlasPath path = new AtlasPath(field.getPath());
        List<Field> fields = getFieldsForPath(session, sourceDocument, field, path, 0);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Processed input field sPath=" + field.getPath() + " sV=" + field.getValue() + " sT=" + field.getFieldType() + " docId: " + field.getDocId());
        }
        if (path.hasCollection() && !path.isIndexedCollection()) {
            FieldGroup fieldGroup = AtlasModelFactory.createFieldGroupFrom(field, true);
            fieldGroup.getField().addAll(fields);
            session.head().setSourceField(fieldGroup);
            return fieldGroup;
        } else if (fields.size() == 1) {
            field.setValue(fields.get(0).getValue());
            return field;
        } else {
            return field;
        }
    } catch (Exception e) {
        throw new AtlasException(e);
    }
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField) Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) AtlasException(io.atlasmap.api.AtlasException) AtlasException(io.atlasmap.api.AtlasException)

Example 50 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class JavaFieldReader method populateCollectionItems.

private FieldGroup populateCollectionItems(JavaChildAccessor accessor, Field field) throws AtlasException {
    if (accessor == null || accessor.getCollectionType() == CollectionType.NONE) {
        throw new AtlasException(String.format("Couldn't find a collection object for field %s:%s", field.getDocId(), field.getPath()));
    }
    FieldGroup group = field instanceof FieldGroup ? (FieldGroup) field : AtlasModelFactory.createFieldGroupFrom(field, true);
    for (int i = 0; i < accessor.getCollectionValues().size(); i++) {
        AtlasPath itemPath = new AtlasPath(group.getPath());
        List<SegmentContext> segments = itemPath.getSegments(true);
        itemPath.setCollectionIndex(segments.size() - 1, i);
        if (field instanceof FieldGroup) {
            FieldGroup itemGroup = AtlasJavaModelFactory.cloneFieldGroup((FieldGroup) field);
            AtlasPath.setCollectionIndexRecursively(itemGroup, segments.size(), i);
            populateChildFields(accessor.getValueAt(i), itemGroup, itemPath);
            group.getField().add(itemGroup);
        } else {
            Field itemField = AtlasJavaModelFactory.cloneJavaField(field, false);
            itemField.setPath(itemPath.toString());
            itemField.setValue(accessor.getValueAt(i));
            group.getField().add(itemField);
        }
    }
    return group;
}
Also used : SegmentContext(io.atlasmap.core.AtlasPath.SegmentContext) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) AtlasException(io.atlasmap.api.AtlasException)

Aggregations

Field (io.atlasmap.v2.Field)221 FieldGroup (io.atlasmap.v2.FieldGroup)86 Test (org.junit.jupiter.api.Test)67 SimpleField (io.atlasmap.v2.SimpleField)62 Field (org.apache.tapestry5.Field)46 JavaField (io.atlasmap.java.v2.JavaField)45 ArrayList (java.util.ArrayList)42 Mapping (io.atlasmap.v2.Mapping)39 Test (org.testng.annotations.Test)39 AtlasPath (io.atlasmap.core.AtlasPath)29 ConstantField (io.atlasmap.v2.ConstantField)29 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)26 AtlasException (io.atlasmap.api.AtlasException)25 JsonField (io.atlasmap.json.v2.JsonField)25 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)25 PropertyField (io.atlasmap.v2.PropertyField)22 AtlasMapping (io.atlasmap.v2.AtlasMapping)21 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)19 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)19 Head (io.atlasmap.spi.AtlasInternalSession.Head)18