use of org.activityinfo.legacy.shared.command.GetPartnersDimension in project activityinfo by bedatadriven.
the class PartnerFilterPanel method applyBaseFilter.
@Override
public void applyBaseFilter(Filter rawFilter) {
// we need to remove any partner filter from this base filter
// so the user has the full selection
final Filter filter = new Filter(rawFilter);
filter.clearRestrictions(DimensionType.Partner);
// force to refresh on site crud
// if (baseFilter == null || !baseFilter.equals(filter)) {
service.execute(new GetPartnersDimension(filter), new AsyncCallback<PartnerResult>() {
@Override
public void onFailure(Throwable caught) {
Log.error(caught.getMessage(), caught);
}
@Override
public void onSuccess(PartnerResult result) {
List<Integer> ids = getSelectedIds();
store.removeAll();
store.add(result.getData());
applyInternalValue();
for (PartnerDTO partner : store.getModels()) {
if (ids.contains(partner.getId())) {
listView.setChecked(partner, true);
}
}
baseFilter = filter;
}
});
// }
}
use of org.activityinfo.legacy.shared.command.GetPartnersDimension in project activityinfo by bedatadriven.
the class PartnerFilterDialog method show.
public void show(Filter rawFilter, final Filter currentFilter, SelectionCallback<Set<Integer>> callback) {
show();
this.callback = callback;
Filter baseFilter = new Filter(rawFilter);
baseFilter.clearRestrictions(DimensionType.Partner);
service.execute(new GetPartnersDimension(baseFilter), new AsyncCallback<PartnerResult>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(PartnerResult result) {
Set<Integer> ids = currentFilter.getRestrictions(DimensionType.Partner);
store.removeAll();
store.add(result.getData());
for (PartnerDTO partner : store.getModels()) {
if (ids.contains(partner.getId())) {
listView.setChecked(partner, true);
}
}
}
});
}
use of org.activityinfo.legacy.shared.command.GetPartnersDimension in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandler method execute.
@Override
public void execute(GetPartnersDimension cmd, ExecutionContext context, final AsyncCallback<PartnerResult> callback) {
final Dimension dimension = new Dimension(DimensionType.Partner);
PivotSites query = new PivotSites();
query.setFilter(cmd.getFilter());
query.setDimensions(dimension);
query.setValueType(ValueType.TOTAL_SITES);
if (query.isTooBroad()) {
callback.onSuccess(new PartnerResult());
return;
}
context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {
@Override
public void onSuccess(PivotSites.PivotResult result) {
Set<PartnerDTO> partners = new HashSet<PartnerDTO>();
for (Bucket bucket : result.getBuckets()) {
EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
if (category == null) {
Log.debug("Partner is null: " + bucket.toString());
} else {
PartnerDTO partner = new PartnerDTO();
partner.setId(category.getId());
partner.setName(category.getLabel());
partners.add(partner);
}
}
// sort partners by name (fallback on id)
List<PartnerDTO> list = new ArrayList<PartnerDTO>(partners);
Collections.sort(list, new Comparator<PartnerDTO>() {
@Override
public int compare(PartnerDTO p1, PartnerDTO p2) {
int result = p1.getName().compareToIgnoreCase(p2.getName());
if (result != 0) {
return result;
} else {
return ((Integer) p1.getId()).compareTo(p2.getId());
}
}
});
callback.onSuccess(new PartnerResult(list));
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
});
}
Aggregations