use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class AbstractMySqlTest method query.
protected final void query(ResourceId formClassId, String... fields) {
QueryModel queryModel = new QueryModel(formClassId);
queryModel.selectResourceId().as("_id");
for (String field : fields) {
queryModel.selectExpr(field).setId(field);
}
query(queryModel);
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class HierarchyClassImporter method prepare.
@Override
public Promise<Void> prepare(ResourceLocator locator, List<? extends SourceRow> batch) {
final List<Promise<Void>> promises = Lists.newArrayList();
for (final ResourceId formId : rootField.getRange()) {
if (isMatchableAtLevel(formId, referenceFields.keySet())) {
QueryModel queryModel = new QueryModel(formId);
queryModel.selectResourceId().as("_id");
for (FieldPath referenceFieldPath : referenceFields.keySet()) {
queryModel.selectField(referenceFieldPath).as(referenceFieldPath.toString());
}
promises.add(locator.queryTable(queryModel).then(new Function<ColumnSet, Void>() {
@Override
public Void apply(ColumnSet columnSet) {
scoreSources.put(formId, new InstanceScoreSourceBuilder(formId, referenceFields, sourceColumns).build(columnSet));
return null;
}
}));
}
}
return Promise.waitAll(promises);
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class SingleClassImporter method prepare.
@Override
public Promise<Void> prepare(ResourceLocator locator, List<? extends SourceRow> batch) {
QueryModel queryModel = new QueryModel(rangeFormId);
queryModel.selectResourceId().as("_id");
for (FieldPath fieldPath : referenceFields.keySet()) {
queryModel.selectField(fieldPath).as(fieldPath.toString());
}
return locator.queryTable(queryModel).then(new Function<ColumnSet, Void>() {
@Nullable
@Override
public Void apply(@Nullable ColumnSet input) {
scoreSource = new InstanceScoreSourceBuilder(rangeFormId, referenceFields, sources).build(input);
instanceScorer = new InstanceScorer(scoreSource);
return null;
}
});
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class GetSitesHandler method buildLinkedQuery.
private QueryModel buildLinkedQuery(FormTree formTree, FormClass form, ActivityLink activityLink) {
QueryModel query = new QueryModel(form.getId());
fieldBindingMap.put(form.getId(), Lists.<FieldBinding>newLinkedList());
addBinding(new SiteDimBinding(), query, formTree);
addBinding(new ConstantActivityIdFieldBinding(activityLink.getActivityId()), query, formTree);
addBinding(new ProjectDimBinding(), query, formTree);
if (command.isFetchDates()) {
addBinding(new StartEndDateFieldBinding(), query, formTree);
}
if (command.isFetchPartner()) {
addBinding(new PartnerDimBinding(), query, formTree);
}
if (command.isFetchLocation()) {
query = buildLocationQuery(query, formTree, form);
}
if (command.fetchAnyIndicators()) {
query = buildLinkedIndicatorQuery(activityLink.getLinkedIndicators(), query, formTree, form);
}
if (command.isFetchAttributes()) {
// query = buildLinkedAttributeQuery(activityLink.getLinkedAttributes(), query, formTree, form);
query = buildAttributeQuery(query, formTree, form);
}
if (command.isFetchComments()) {
addBinding(new CommentFieldBinding(), query, formTree);
}
return query;
}
use of org.activityinfo.model.query.QueryModel in project activityinfo by bedatadriven.
the class GetSitesHandler method buildQuery.
private QueryModel buildQuery(Activity activity, FormTree formTree, FormClass form) {
QueryModel query = new QueryModel(form.getId());
fieldBindingMap.put(form.getId(), Lists.<FieldBinding>newLinkedList());
addBinding(new SiteDimBinding(), query, formTree);
addBinding(new ActivityIdFieldBinding(), query, formTree);
addBinding(new ProjectDimBinding(), query, formTree);
if (command.isFetchDates() && activity != null && !activity.isMonthly()) {
addBinding(new StartEndDateFieldBinding(), query, formTree);
}
if (command.isFetchPartner()) {
addBinding(new PartnerDimBinding(), query, formTree);
}
if (command.isFetchLocation()) {
query = buildLocationQuery(query, formTree, form);
}
if (command.isFetchAttributes()) {
query = buildAttributeQuery(query, formTree, form);
}
if (command.fetchAnyIndicators()) {
query = buildIndicatorQuery(query, formTree, form);
}
if (command.isFetchComments()) {
addBinding(new CommentFieldBinding(), query, formTree);
}
return query;
}
Aggregations