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);
}
});
}
});
}
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);
}
}
});
}
}
Aggregations