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;
}
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());
}
}
}
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());
}
}
}
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;
}
};
}
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;
}
Aggregations