Search in sources :

Example 1 with ActivityFormResults

use of org.activityinfo.legacy.shared.command.result.ActivityFormResults in project activityinfo by bedatadriven.

the class GetActivityFormsHandler method execute.

@Override
public void execute(GetActivityForms command, final ExecutionContext context, final AsyncCallback<ActivityFormResults> callback) {
    composeQuery(command.getFilter()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, final SqlResultSet results) {
            context.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

                @Override
                public void onFailure(Throwable caught) {
                    callback.onFailure(caught);
                }

                @Override
                public void onSuccess(SchemaDTO schema) {
                    LOGGER.log(Level.INFO, "Forms matching filter: " + results.getRows().size());
                    final List<Promise<ActivityFormDTO>> pending = new ArrayList<>();
                    for (SqlResultSetRow row : results.getRows()) {
                        int activityId = row.getInt("activityId");
                        boolean visible = (schema.getActivityById(activityId) != null);
                        if (visible) {
                            pending.add(fetchForm(context, activityId));
                        }
                    }
                    LOGGER.log(Level.INFO, "Forms pending: " + pending.size());
                    Promise.waitAll(pending).then(new Function<Void, ActivityFormResults>() {

                        @Nullable
                        @Override
                        public ActivityFormResults apply(@Nullable Void aVoid) {
                            LOGGER.log(Level.INFO, "Form loading completed.");
                            List<ActivityFormDTO> forms = new ArrayList<>();
                            for (Promise<ActivityFormDTO> pendingForm : pending) {
                                forms.add(pendingForm.get());
                            }
                            return new ActivityFormResults(forms);
                        }
                    }).then(callback);
                }
            });
        }
    });
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) ActivityFormResults(org.activityinfo.legacy.shared.command.result.ActivityFormResults) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Promise(org.activityinfo.promise.Promise) Function(com.google.common.base.Function) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) Nullable(javax.annotation.Nullable)

Example 2 with ActivityFormResults

use of org.activityinfo.legacy.shared.command.result.ActivityFormResults in project activityinfo by bedatadriven.

the class AttributeGroupFilterWidgets method draw.

public void draw(final Filter filter) {
    final Filter value = new Filter(filter);
    value.clearRestrictions(DIMENSION_TYPE);
    // prevents executing the same command needlessly
    if (prevFilter == null || !prevFilter.equals(filter)) {
        prevFilter = filter;
        Log.debug("AttributeGroupFilterWidgets called for filter " + filter);
        service.execute(new GetActivityForms(filter), new AsyncCallback<ActivityFormResults>() {

            @Override
            public void onFailure(Throwable caught) {
                GWT.log("Failed to load schema", caught);
            }

            @Override
            public void onSuccess(final ActivityFormResults forms) {
                // clean up old widgets
                for (AttributeGroupFilterWidget widget : widgets) {
                    panel.remove(widget);
                }
                // create new widgets, one for each attributegroup.
                // remember the old selection
                Set<Integer> selection = getSelectedIds();
                widgets = new ArrayList<AttributeGroupFilterWidget>();
                Set<String> attributesByName = Sets.newHashSet();
                for (ActivityFormDTO form : forms.getData()) {
                    for (AttributeGroupDTO group : form.getAttributeGroups()) {
                        String key = group.getName().toLowerCase();
                        if (!attributesByName.contains(key)) {
                            AttributeGroupFilterWidget widget = new AttributeGroupFilterWidget(group);
                            widget.setSelection(selection);
                            if (valueChangeHandler != null) {
                                widget.addValueChangeHandler(valueChangeHandler);
                            }
                            panel.add(widget);
                            widgets.add(widget);
                            attributesByName.add(key);
                        }
                    }
                }
                if (drawCallback != null) {
                    drawCallback.onSuccess(null);
                }
            }
        });
    }
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) Filter(org.activityinfo.legacy.shared.command.Filter) GetActivityForms(org.activityinfo.legacy.shared.command.GetActivityForms) ActivityFormResults(org.activityinfo.legacy.shared.command.result.ActivityFormResults)

Aggregations

ActivityFormResults (org.activityinfo.legacy.shared.command.result.ActivityFormResults)2 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 Function (com.google.common.base.Function)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetActivityForms (org.activityinfo.legacy.shared.command.GetActivityForms)1 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 Promise (org.activityinfo.promise.Promise)1