Search in sources :

Example 1 with PartnerResult

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

the class GetPartnersDimensionHandlerTest method testIndicatorEmpty.

// report filter population query
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testIndicatorEmpty() throws CommandException {
    // empty
    PartnerResult result = execute(DimensionType.Indicator, 103, 675);
    assertThat(result.getData().size(), equalTo(0));
}
Also used : PartnerResult(org.activityinfo.shared.command.result.PartnerResult) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 2 with PartnerResult

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

the class GetPartnersDimensionHandlerTest method testIndicatorLinked12100.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testIndicatorLinked12100() throws CommandException {
    // NRC, NRC2
    PartnerResult result = execute(DimensionType.Indicator, 1, 2, 100);
    assertThat(result.getData().size(), equalTo(2));
    assertThat(result.getData().get(0).getName(), equalTo("NRC"));
    assertThat(result.getData().get(1).getName(), equalTo("NRC2"));
}
Also used : PartnerResult(org.activityinfo.shared.command.result.PartnerResult) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 3 with PartnerResult

use of org.activityinfo.shared.command.result.PartnerResult 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 4 with PartnerResult

use of org.activityinfo.shared.command.result.PartnerResult 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 5 with PartnerResult

use of org.activityinfo.shared.command.result.PartnerResult 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

PartnerResult (org.activityinfo.shared.command.result.PartnerResult)11 OnDataSet (org.activityinfo.server.database.OnDataSet)8 Test (org.junit.Test)8 GetPartnersDimension (org.activityinfo.shared.command.GetPartnersDimension)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