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