Search in sources :

Example 51 with QueryModel

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);
}
Also used : QueryModel(org.activityinfo.model.query.QueryModel)

Example 52 with 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);
}
Also used : Promise(org.activityinfo.promise.Promise) Function(com.google.common.base.Function) ResourceId(org.activityinfo.model.resource.ResourceId) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel)

Example 53 with QueryModel

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;
        }
    });
}
Also used : FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Nullable(javax.annotation.Nullable)

Example 54 with QueryModel

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;
}
Also used : ProjectDimBinding(org.activityinfo.server.command.handler.binding.dim.ProjectDimBinding) PartnerDimBinding(org.activityinfo.server.command.handler.binding.dim.PartnerDimBinding) SiteDimBinding(org.activityinfo.server.command.handler.binding.dim.SiteDimBinding) QueryModel(org.activityinfo.model.query.QueryModel)

Example 55 with QueryModel

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;
}
Also used : ProjectDimBinding(org.activityinfo.server.command.handler.binding.dim.ProjectDimBinding) PartnerDimBinding(org.activityinfo.server.command.handler.binding.dim.PartnerDimBinding) SiteDimBinding(org.activityinfo.server.command.handler.binding.dim.SiteDimBinding) QueryModel(org.activityinfo.model.query.QueryModel)

Aggregations

QueryModel (org.activityinfo.model.query.QueryModel)59 ColumnSet (org.activityinfo.model.query.ColumnSet)40 Test (org.junit.Test)30 ColumnView (org.activityinfo.model.query.ColumnView)21 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)13 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)11 FormTree (org.activityinfo.model.formTree.FormTree)9 ResourceId (org.activityinfo.model.resource.ResourceId)9 FormClass (org.activityinfo.model.form.FormClass)7 Nullable (javax.annotation.Nullable)6 FormField (org.activityinfo.model.form.FormField)6 ColumnModel (org.activityinfo.model.query.ColumnModel)6 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)6 QuantityType (org.activityinfo.model.type.number.QuantityType)5 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)4 RowBasedJsonWriter (org.activityinfo.store.query.output.RowBasedJsonWriter)4 Charsets (com.google.common.base.Charsets)3 Operation (io.swagger.v3.oas.annotations.Operation)3 FieldPath (org.activityinfo.model.formTree.FieldPath)3 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)3