Search in sources :

Example 21 with Promise

use of org.activityinfo.promise.Promise 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)

Aggregations

Promise (org.activityinfo.promise.Promise)21 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)10 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)10 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)10 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)6 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)4 ArrayList (java.util.ArrayList)4 Function (com.google.common.base.Function)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 UpdateMonthlyReports (org.activityinfo.legacy.shared.command.UpdateMonthlyReports)2 FormClass (org.activityinfo.model.form.FormClass)2 FormField (org.activityinfo.model.form.FormField)2 FormInstance (org.activityinfo.model.form.FormInstance)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2 ResourceId (org.activityinfo.model.resource.ResourceId)2 FieldValue (org.activityinfo.model.type.FieldValue)2 Record (com.extjs.gxt.ui.client.store.Record)1 Optional (com.google.common.base.Optional)1