use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class PivotSitesHandlerTest method execute.
private void execute() {
setUser(OWNER_USER_ID);
try {
PivotSites pivot = new PivotSites(dimensions, filter);
pivot.setValueType(valueType);
pivot.setPointRequested(pointsRequested);
buckets = execute(pivot).getBuckets();
} catch (CommandException e) {
throw new RuntimeException(e);
}
System.out.println("Buckets = [");
for (Bucket bucket : buckets) {
System.out.print(" { Value: " + bucket.doubleValue());
for (Dimension dim : bucket.dimensions()) {
DimensionCategory cat = bucket.getCategory(dim);
System.out.print("\n " + dim.toString() + ": ");
System.out.print(cat.toString());
}
System.out.println("\n }");
}
System.out.print("]\n");
}
use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class PivotSitesHandlerLocalTest method execute.
private void execute() {
setUser(OWNER_USER_ID);
try {
PivotSites pivot = new PivotSites(dimensions, filter);
pivot.setValueType(valueType);
buckets = executeLocally(pivot).getBuckets();
} catch (CommandException e) {
throw new RuntimeException(e);
}
System.out.println("Buckets = [");
for (Bucket bucket : buckets) {
System.out.print(bucket.toString());
}
System.out.print("]\n");
}
use of org.activityinfo.shared.command.result.Bucket 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);
}
});
}
use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class PivotSitesHandler method execute.
@Override
public void execute(PivotSites command, ExecutionContext context, final AsyncCallback<PivotResult> callback) {
LOGGER.fine("Pivoting: " + command);
if (command.getValueType() == ValueType.INDICATOR) {
if (command.getFilter() == null || command.getFilter().getRestrictions(DimensionType.Indicator).isEmpty()) {
Log.error("No indicator filter provided to pivot query");
}
}
final PivotQueryContext queryContext = new PivotQueryContext(command, context, dialect);
final List<PivotQuery> queries = Lists.newArrayList();
for (BaseTable baseTable : baseTables) {
if (baseTable.accept(command)) {
queries.add(new PivotQuery(queryContext, baseTable));
}
}
final List<Bucket> buckets = Lists.newArrayList();
if (queries.isEmpty()) {
callback.onSuccess(new PivotResult(buckets));
}
final Set<PivotQuery> remaining = Sets.newHashSet(queries);
final List<Throwable> errors = Lists.newArrayList();
for (final PivotQuery query : queries) {
query.execute(new AsyncCallback<Void>() {
@Override
public void onSuccess(Void voidResult) {
if (errors.isEmpty()) {
remaining.remove(query);
if (remaining.isEmpty()) {
callback.onSuccess(new PivotResult(queryContext.getBuckets()));
}
}
}
@Override
public void onFailure(Throwable caught) {
if (errors.isEmpty()) {
callback.onFailure(caught);
}
errors.add(caught);
}
});
}
}
use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class PivotTableDataBuilder method build.
public PivotTableData build(PivotReportElement<?> element, List<Dimension> rowDims, List<Dimension> colDims, List<Bucket> buckets) {
PivotTableData table = new PivotTableData();
Map<Dimension, Comparator<PivotTableData.Axis>> comparators = createComparators(element.allDimensions());
for (Bucket bucket : buckets) {
PivotTableData.Axis column = colDims.isEmpty() ? table.getRootColumn() : find(table.getRootColumn(), colDims.iterator(), comparators, bucket);
PivotTableData.Axis row = rowDims.isEmpty() ? table.getRootRow() : find(table.getRootRow(), rowDims.iterator(), comparators, bucket);
row.setValue(column, bucket.doubleValue());
}
return table;
}
Aggregations