Search in sources :

Example 1 with EntityCategory

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);
        }
    });
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) GetPartnersDimension(org.activityinfo.legacy.shared.command.GetPartnersDimension) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) PivotSites(org.activityinfo.legacy.shared.command.PivotSites) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory) PartnerResult(org.activityinfo.legacy.shared.command.result.PartnerResult)

Example 2 with EntityCategory

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;
}
Also used : EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Example 3 with EntityCategory

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);
}
Also used : EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Example 4 with EntityCategory

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;
}
Also used : DimensionCategory(org.activityinfo.legacy.shared.reports.content.DimensionCategory) ColumnView(org.activityinfo.model.query.ColumnView) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Example 5 with EntityCategory

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;
}
Also used : DimensionCategory(org.activityinfo.legacy.shared.reports.content.DimensionCategory) ColumnView(org.activityinfo.model.query.ColumnView) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Aggregations

EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)10 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)4 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)3 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)3 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)2 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)2 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)2 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)2 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)2 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)2 ColumnView (org.activityinfo.model.query.ColumnView)2 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 ArrayList (java.util.ArrayList)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetPartnersDimension (org.activityinfo.legacy.shared.command.GetPartnersDimension)1 PivotResult (org.activityinfo.legacy.shared.command.PivotSites.PivotResult)1 PartnerResult (org.activityinfo.legacy.shared.command.result.PartnerResult)1 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)1