use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class GetSitesHandler method addToQueryMap.
private void addToQueryMap(Map.Entry<ResourceId, FormTree> formTreeEntry, ActivityLink activityLink) {
QueryModel query = buildQuery(formTreeEntry.getValue(), activityLink);
query.setFilter(determineQueryFilter(command.getFilter(), formTreeEntry.getValue()));
queryMap.put(formTreeEntry.getKey(), query);
LOGGER.info(query.toString());
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class ResourceLocatorSyncImpl method getReferenceChoices.
@Override
public List<ReferenceChoice> getReferenceChoices(Collection<ResourceId> range) {
ResourceId formId = Iterables.getOnlyElement(range);
QueryModel queryModel = new QueryModel(formId);
queryModel.selectResourceId().as("id");
queryModel.selectExpr("label").as("label");
ColumnSetBuilder builder = new ColumnSetBuilder(catalog.get(), new NullFormSupervisor());
ColumnSet columnSet = builder.build(queryModel);
ColumnView id = columnSet.getColumnView("id");
ColumnView label = columnSet.getColumnView("label");
List<ReferenceChoice> choices = Lists.newArrayList();
for (int i = 0; i < columnSet.getNumRows(); i++) {
ResourceId choiceId = ResourceId.valueOf(id.getString(i));
String choiceLabel = label.getString(i);
choices.add(new ReferenceChoice(new RecordRef(formId, choiceId), choiceLabel));
}
return choices;
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class DefaultQueryBuilder method build.
public QueryModel build() {
LOGGER.info("No query fields provided, querying all.");
addFields("", new FieldPath(), tree.getRootFields());
this.queryModel = new QueryModel(tree.getRootFormId());
this.queryModel.selectResourceId().as("@id");
for (ColumnModel columnModel : columns.values()) {
this.queryModel.addColumn(columnModel);
}
return queryModel;
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class FormResource method computeVisibilityPredicate.
/**
* Computes a record-level visibility predicate.
*/
private java.util.function.Predicate<ResourceId> computeVisibilityPredicate() {
FormPermissions formPermissions = backend.getFormSupervisor().getFormPermissions(formId);
if (!formPermissions.hasVisibilityFilter()) {
return resourceId -> true;
}
QueryModel queryModel = new QueryModel(formId);
queryModel.selectResourceId().as("id");
ColumnSet columnSet = executeQuery(queryModel);
ColumnView id = columnSet.getColumnView("id");
final Set<String> idSet = new HashSet<>();
for (int i = 0; i < id.numRows(); i++) {
idSet.add(id.getString(i));
}
return resourceId -> idSet.contains(resourceId.asString());
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class FormResource method query.
private ColumnSet query(final UriInfo uriInfo) {
assertVisible(formId);
QueryModel queryModel;
if (uriInfo.getQueryParameters().isEmpty()) {
queryModel = buildDefaultQueryModel();
} else {
queryModel = new QueryModel(formId);
for (String columnId : uriInfo.getQueryParameters().keySet()) {
queryModel.selectExpr(uriInfo.getQueryParameters().getFirst(columnId)).as(columnId);
}
}
LOGGER.info(queryModel.toString());
return executeQuery(queryModel);
}
Aggregations