use of org.activityinfo.legacy.shared.reports.content.EntityCategory 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);
}
});
}
use of org.activityinfo.legacy.shared.reports.content.EntityCategory in project activityinfo by bedatadriven.
the class DimensionAdapter method unmarshal.
@Override
public Dimension unmarshal(DimensionElement element) {
Dimension dim = createDim(element);
for (CategoryElement category : element.categories) {
CategoryProperties props = new CategoryProperties();
props.setLabel(category.label);
if (category.color != null) {
props.setColor(decodeColor(category.color));
}
EntityCategory entityCategory = new EntityCategory(Integer.parseInt(category.name));
dim.getCategories().put(entityCategory, props);
dim.getOrdering().add(entityCategory);
}
return dim;
}
use of org.activityinfo.legacy.shared.reports.content.EntityCategory in project activityinfo by bedatadriven.
the class Dimension method setCategoryColor.
public void setCategoryColor(int id, int color) {
EntityCategory cat = new EntityCategory(id);
CategoryProperties props = categories.get(cat);
if (props == null) {
props = new CategoryProperties();
categories.put(cat, props);
}
props.setColor(color);
}
use of org.activityinfo.legacy.shared.reports.content.EntityCategory in project activityinfo by bedatadriven.
the class AdminDimBinding method extractCategories.
@Override
public DimensionCategory[] extractCategories(Activity activity, ColumnSet columnSet) {
DimensionCategory[] c = new DimensionCategory[columnSet.getNumRows()];
if (columnSet.getColumns().containsKey(labelColumn)) {
ColumnView idView = columnSet.getColumnView(idColumn);
ColumnView labelView = columnSet.getColumnView(labelColumn);
for (int i = 0; i < columnSet.getNumRows(); i++) {
String id = idView.getString(i);
if (id != null) {
int entityId = getLegacyIdFromCuid(id);
String label = labelView.getString(i);
c[i] = new EntityCategory(entityId, label);
}
}
}
return c;
}
use of org.activityinfo.legacy.shared.reports.content.EntityCategory in project activityinfo by bedatadriven.
the class SiteDimBinding method extractCategories.
@Override
public DimensionCategory[] extractCategories(Activity activity, ColumnSet columnSet) {
ColumnView id = columnSet.getColumnView(ID_COLUMN);
ColumnView label = columnSet.getColumnView(LABEL_COLUMN);
int numRows = columnSet.getNumRows();
DimensionCategory[] categories = new DimensionCategory[numRows];
for (int i = 0; i < numRows; i++) {
String idString = id.getString(i);
String labelString = label.getString(i);
// Note that we try to gracefully handle an empty location label because not all forms
// will have a location in the new data model
// Legacy activities with "nullary" location types, when represented in the new data model,
// have *no* location field, so we just have to treat it as a blank.
categories[i] = new EntityCategory(CuidAdapter.getLegacyIdFromCuid(idString), Strings.nullToEmpty(labelString));
}
return categories;
}
Aggregations