Search in sources :

Example 1 with GetPartnersDimension

use of org.activityinfo.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);
    if (baseFilter == null || !baseFilter.equals(filter)) {
        service.execute(new GetPartnersDimension(filter), new AsyncCallback<PartnerResult>() {

            @Override
            public void onFailure(Throwable 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.shared.dto.PartnerDTO) Filter(org.activityinfo.shared.command.Filter) ArrayList(java.util.ArrayList) List(java.util.List) PartnerResult(org.activityinfo.shared.command.result.PartnerResult) GetPartnersDimension(org.activityinfo.shared.command.GetPartnersDimension)

Example 2 with GetPartnersDimension

use of org.activityinfo.shared.command.GetPartnersDimension in project activityinfo by bedatadriven.

the class PartnerFilterDialog method show.

public void show(Filter baseFilter, final Filter currentFilter, SelectionCallback<Set<Integer>> callback) {
    show();
    this.callback = callback;
    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.shared.dto.PartnerDTO) PartnerResult(org.activityinfo.shared.command.result.PartnerResult) GetPartnersDimension(org.activityinfo.shared.command.GetPartnersDimension)

Example 3 with GetPartnersDimension

use of org.activityinfo.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) {
    // if the filter doesn't contain any activity, database or indicator values, just return an empty list
    if (!cmd.getFilter().isRestricted(DimensionType.Database) && !cmd.getFilter().isRestricted(DimensionType.Activity) && !cmd.getFilter().isRestricted(DimensionType.Indicator)) {
        callback.onSuccess(new PartnerResult());
        return;
    }
    final Dimension dimension = new Dimension(DimensionType.Partner);
    PivotSites query = new PivotSites();
    query.setFilter(cmd.getFilter());
    query.setDimensions(dimension);
    query.setValueType(ValueType.DIMENSION);
    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 : Set(java.util.Set) HashSet(java.util.HashSet) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) Dimension(org.activityinfo.shared.report.model.Dimension) GetPartnersDimension(org.activityinfo.shared.command.GetPartnersDimension) Comparator(java.util.Comparator) PivotSites(org.activityinfo.shared.command.PivotSites) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) List(java.util.List) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PartnerResult(org.activityinfo.shared.command.result.PartnerResult)

Aggregations

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