Search in sources :

Example 86 with Field

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

the class DefaultAtlasFieldActionService method packExpressionActionOutcomeIntoField.

private Field packExpressionActionOutcomeIntoField(Object values, Field field) {
    if (values instanceof List) {
        // n -> n and 1 -> n - create new FieldGroup
        FieldGroup fieldGroup = new FieldGroup();
        // Make sure fieldGroup is of a collection type
        AtlasPath groupPath = new AtlasPath(AtlasModelFactory.GENERATED_PATH);
        fieldGroup.setCollectionType(CollectionType.LIST);
        groupPath = new AtlasPath(groupPath.toString() + AtlasPath.PATH_LIST_SUFFIX);
        fieldGroup.setPath(groupPath.toString());
        List<?> tmpSourceList = (List<?>) values;
        while (tmpSourceList.size() == 1 && (tmpSourceList.get(0) instanceof List)) {
            tmpSourceList = (List<Object>) tmpSourceList.get(0);
        }
        FieldType type = null;
        for (int i = 0; i < tmpSourceList.size(); i++) {
            Object subValue = tmpSourceList.get(i);
            if (type == null && subValue != null) {
                type = getConversionService().fieldTypeFromClass(subValue.getClass());
            }
            Field subField = new SimpleField();
            AtlasPath subPath = groupPath.clone();
            subPath.setVacantCollectionIndex(i);
            AtlasModelFactory.copyField(fieldGroup, subField, false);
            subField.setPath(subPath.toString());
            subField.setIndex(null);
            subField.setValue(subValue);
            subField.setFieldType(type);
            subField.setCollectionType(CollectionType.NONE);
            fieldGroup.getField().add(subField);
        }
        return fieldGroup;
    }
    if (values != null) {
        field = new SimpleField();
        field.setPath(AtlasModelFactory.GENERATED_PATH);
        field.setValue(values);
        field.setFieldType(getConversionService().fieldTypeFromClass(values.getClass()));
    }
    return field;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) FieldGroup(io.atlasmap.v2.FieldGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SimpleField(io.atlasmap.v2.SimpleField) FieldType(io.atlasmap.v2.FieldType)

Example 87 with Field

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

the class PropertyModule method writeTargetValue.

@Override
public void writeTargetValue(AtlasInternalSession session) throws AtlasException {
    AtlasPropertyStrategy strategy = session.getAtlasPropertyStrategy() != null ? session.getAtlasPropertyStrategy() : this.defaultStrategy;
    Field targetField = session.head().getTargetField();
    if (targetField instanceof PropertyField) {
        PropertyField targetPropertyField = (PropertyField) targetField;
        strategy.writeProperty(session, targetPropertyField);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Processed target PropertyField: Name={} Value={} Strategy={}", targetPropertyField.getName(), targetPropertyField.getValue(), strategy.getClass().getName());
        }
    }
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) AtlasPropertyStrategy(io.atlasmap.spi.AtlasPropertyStrategy) PropertyField(io.atlasmap.v2.PropertyField)

Example 88 with Field

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

the class PropertyModule method readSourceValue.

@Override
public void readSourceValue(AtlasInternalSession session) throws AtlasException {
    AtlasPropertyStrategy strategy = session.getAtlasPropertyStrategy() != null ? session.getAtlasPropertyStrategy() : this.defaultStrategy;
    Field sourceField = session.head().getSourceField();
    if (sourceField instanceof PropertyField) {
        PropertyField sourcePropertyField = (PropertyField) sourceField;
        strategy.readProperty(session, sourcePropertyField);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Processed source PropertyField: Name={} Scope={} Value={} Strategy={}", sourcePropertyField.getName(), sourcePropertyField.getScope(), sourceField.getValue(), strategy.getClass().getName());
        }
    }
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) AtlasPropertyStrategy(io.atlasmap.spi.AtlasPropertyStrategy) PropertyField(io.atlasmap.v2.PropertyField)

Example 89 with Field

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

the class ISEMPTY method create.

@Override
public Expression create(List<Expression> args) throws ParseException {
    if (args.size() != 1) {
        throw new ParseException("ISEMPTY expects 1 argument.");
    }
    final Expression arg = args.get(0);
    return new BooleanExpression() {

        public Field evaluate(ExpressionContext ctx) throws ExpressionException {
            Field f = arg.evaluate(ctx);
            Object value = f == null ? null : f.getValue();
            if (value == null || value.toString().isEmpty()) {
                return wrapWithField(Boolean.TRUE);
            }
            return wrapWithField(Boolean.FALSE);
        }

        public boolean matches(ExpressionContext ctx) throws ExpressionException {
            Object answer = evaluate(ctx).getValue();
            return answer != null && answer == Boolean.TRUE;
        }
    };
}
Also used : Field(io.atlasmap.v2.Field) AtlasModelFactory.wrapWithField(io.atlasmap.v2.AtlasModelFactory.wrapWithField) BooleanExpression(io.atlasmap.expression.internal.BooleanExpression) Expression(io.atlasmap.expression.Expression) BooleanExpression(io.atlasmap.expression.internal.BooleanExpression) ExpressionContext(io.atlasmap.expression.ExpressionContext) ParseException(io.atlasmap.expression.parser.ParseException)

Example 90 with Field

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

the class AtlasPath method extractChildren.

/**
 * Extract child fields by feeding relative path.
 *
 * @param f Parent field to extract from
 * @param path Relative path string
 * @return extracted field(s)
 */
public static Field extractChildren(Field f, String path) {
    if (f == null || path == null || path.isEmpty()) {
        return null;
    }
    if (path.equals(PATH_SEPARATOR)) {
        return f;
    }
    if (!(f instanceof FieldGroup)) {
        return null;
    }
    List<Field> extracted = new ArrayList<>();
    FieldGroup entryField = (FieldGroup) f;
    extracted.add(entryField);
    List<SegmentContext> entrySegments = new AtlasPath(entryField.getPath()).getSegments(true);
    SegmentContext entrySegment = entrySegments.get(entrySegments.size() - 1);
    List<SegmentContext> extractedSegments = new ArrayList<>(entrySegments);
    List<SegmentContext> relativeSegments = new AtlasPath(path).getSegments(true);
    SegmentContext relativeRootSegment = relativeSegments.get(0);
    List<Field> selected = new ArrayList<>();
    if (relativeRootSegment.getCollectionType() == null || relativeRootSegment.getCollectionType() == CollectionType.NONE) {
        if (entrySegment.getCollectionType() != null && entrySegment.getCollectionType() != CollectionType.NONE && entrySegment.getCollectionIndex() == null) {
            selected.addAll(entryField.getField());
        } else {
            selected.add(entryField);
        }
    } else if (relativeRootSegment.getCollectionIndex() != null) {
        if (entrySegment.getCollectionIndex() != null) {
            if (entrySegment.getCollectionIndex() == relativeRootSegment.getCollectionIndex()) {
                selected.add(entryField);
            }
        } else {
            selected.add(entryField.getField().get(relativeRootSegment.getCollectionIndex()));
            entrySegment.collectionIndex = relativeRootSegment.getCollectionIndex();
            extractedSegments.set(entrySegments.size() - 1, entrySegment.rebuild());
        }
    } else {
        selected.addAll(entryField.getField());
    }
    extracted = selected;
    for (int i = 1; i < relativeSegments.size(); i++) {
        SegmentContext segment = relativeSegments.get(i);
        extractedSegments.add(segment);
        selected = new ArrayList<>();
        for (Field f1 : extracted) {
            FieldGroup f1Group = (FieldGroup) f1;
            for (Field f2 : f1Group.getField()) {
                AtlasPath f2Path = new AtlasPath(f2.getPath());
                if (!segment.getName().equals(f2Path.getLastSegment().getName())) {
                    continue;
                }
                if (segment.getCollectionType() == CollectionType.NONE) {
                    selected.add(f2);
                } else {
                    FieldGroup f2Group = (FieldGroup) f2;
                    if (segment.getCollectionIndex() != null) {
                        selected.add((f2Group.getField().get(segment.getCollectionIndex())));
                    } else {
                        selected.addAll(f2Group.getField());
                    }
                }
                break;
            }
        }
        extracted = selected;
    }
    if (extracted.size() == 1) {
        return extracted.get(0);
    }
    FieldGroup answer = AtlasModelFactory.createFieldGroupFrom(f, true);
    answer.setPath(new AtlasPath(extractedSegments).toString());
    answer.getField().addAll(extracted);
    return answer;
}
Also used : Field(io.atlasmap.v2.Field) FieldGroup(io.atlasmap.v2.FieldGroup) ArrayList(java.util.ArrayList)

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