use of io.atlasmap.expression.Expression in project atlasmap by atlasmap.
the class FILTER method create.
@Override
public Expression create(List<Expression> args) throws ParseException {
if (args.size() != 2) {
throw new ParseException("FILTER expects 2 arguments.");
}
Expression parentExpression = args.get(0);
BooleanExpression filterExpression = BooleanExpression.asBooleanExpression(args.get(1));
return (ctx) -> {
Field parent = (Field) parentExpression.evaluate(ctx);
List<Field> collection = parent instanceof FieldGroup ? ((FieldGroup) parent).getField() : Arrays.asList(parent);
FieldGroup filtered = AtlasModelFactory.createFieldGroupFrom(parent, true);
int index = 0;
for (Field f : collection) {
if (filterExpression.matches((subCtx) -> {
return AtlasPath.extractChildren(f, subCtx);
})) {
adjustRootCollectionIndex(f, index);
index++;
filtered.getField().add(f);
}
}
return filtered;
};
}
use of io.atlasmap.expression.Expression in project atlasmap by atlasmap.
the class SELECT method create.
@Override
public Expression create(List<Expression> args) throws ParseException {
if (args.size() != 2) {
throw new ParseException("SELECT expects 2 arguments.");
}
Expression parentExpression = args.get(0);
Expression selectExpression = args.get(1);
return (ctx) -> {
Field parent = parentExpression.evaluate(ctx);
List<Field> collection = parent instanceof FieldGroup ? ((FieldGroup) parent).getField() : Arrays.asList(parent);
List<Field> selected = new ArrayList<>();
final FieldGroup answer = AtlasModelFactory.createFieldGroupFrom(parent, true);
answer.setPath(AtlasModelFactory.GENERATED_PATH);
for (Field f : collection) {
Field fs = (Field) selectExpression.evaluate((subCtx) -> {
if (subCtx != null && AtlasModelFactory.GENERATED_PATH.equals(answer.getPath())) {
answer.setPath(parent.getPath() + (subCtx.startsWith(AtlasPath.PATH_SEPARATOR) ? subCtx : (AtlasPath.PATH_SEPARATOR + subCtx)));
}
return AtlasPath.extractChildren(f, subCtx);
});
selected.add(fs);
}
if (selected.size() == 1) {
return selected.get(0);
}
answer.getField().addAll(selected);
return answer;
};
}
Aggregations