Search in sources :

Example 1 with GetPartnersDimension

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;
        }
    });
// }
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) Filter(org.activityinfo.legacy.shared.command.Filter) ArrayList(java.util.ArrayList) List(java.util.List) PartnerResult(org.activityinfo.legacy.shared.command.result.PartnerResult) GetPartnersDimension(org.activityinfo.legacy.shared.command.GetPartnersDimension)

Example 2 with GetPartnersDimension

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);
                }
            }
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) Filter(org.activityinfo.legacy.shared.command.Filter) PartnerResult(org.activityinfo.legacy.shared.command.result.PartnerResult) GetPartnersDimension(org.activityinfo.legacy.shared.command.GetPartnersDimension)

Example 3 with GetPartnersDimension

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);
        }
    });
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) GetPartnersDimension(org.activityinfo.legacy.shared.command.GetPartnersDimension) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) PivotSites(org.activityinfo.legacy.shared.command.PivotSites) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory) PartnerResult(org.activityinfo.legacy.shared.command.result.PartnerResult)

Aggregations

GetPartnersDimension (org.activityinfo.legacy.shared.command.GetPartnersDimension)3 PartnerResult (org.activityinfo.legacy.shared.command.result.PartnerResult)3 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)3 Filter (org.activityinfo.legacy.shared.command.Filter)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)1 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)1 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)1 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)1