use of io.atlasmap.expression.parser.ParseException 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