use of org.activityinfo.store.query.shared.columns.FilteredSlot in project activityinfo by bedatadriven.
the class QueryEvaluator method evaluate.
public Slot<ColumnSet> evaluate(final QueryModel model) {
Slot<TableFilter> filter = filter(model.getFilter());
final HashMap<String, Slot<ColumnView>> columnViews = Maps.newHashMap();
for (ColumnModel column : model.getColumns()) {
Slot<ColumnView> view;
try {
view = evaluateExpression(column.getFormula());
} catch (FormulaException e) {
throw new QuerySyntaxException("Syntax error in column " + column.getId() + " '" + column.getFormula() + "' : " + e.getMessage(), e);
}
columnViews.put(column.getId(), new FilteredSlot(filter, view));
}
if (columnViews.isEmpty()) {
return new MemoizedSlot<>(batch.addRowCount(FilterLevel.PERMISSIONS, tree.getRootFormId()), new Function<Integer, ColumnSet>() {
@Override
public ColumnSet apply(Integer rowCount) {
return new ColumnSet(rowCount, Collections.<String, ColumnView>emptyMap());
}
});
} else {
return new Slot<ColumnSet>() {
private ColumnSet result = null;
@Override
public ColumnSet get() {
if (result == null) {
// result
Map<String, ColumnView> dataMap = Maps.newHashMap();
for (Map.Entry<String, Slot<ColumnView>> entry : columnViews.entrySet()) {
dataMap.put(entry.getKey(), entry.getValue().get());
}
ColumnSet dataset = new ColumnSet(commonLength(dataMap), dataMap);
if (model.getSortModels().isEmpty()) {
result = dataset;
} else {
result = sort(dataset, model.getSortModels());
}
}
return result;
}
};
}
}
Aggregations