Search in sources :

Example 1 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class DimensionTree method updateModelAfterCheckChange.

private void updateModelAfterCheckChange(TreePanelEvent<DimensionModel> event) {
    Dimension dim = event.getItem().getDimension();
    if (event.isChecked()) {
        if (!model.getRowDimensions().contains(dim) && !model.getColumnDimensions().contains(dim)) {
            if (model.getRowDimensions().size() > model.getColumnDimensions().size()) {
                model.addColDimension(dim);
            } else {
                model.addRowDimension(dim);
            }
        }
    } else {
        model.getRowDimensions().remove(dim);
        model.getColumnDimensions().remove(dim);
    }
    if (fireEvents) {
        reportEventBus.fireChange();
    }
}
Also used : Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)

Example 2 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class DimensionTree method isAttributeDimensionSelected.

private boolean isAttributeDimensionSelected(Dimensions schema, List<Dimension> dims, AttributeGroupDimension dim) {
    String name = schema.getAttributeGroupNameSafe(dim.getAttributeGroupId());
    for (Dimension selectedDim : dims) {
        if (selectedDim instanceof AttributeGroupDimension) {
            int selectedId = ((AttributeGroupDimension) selectedDim).getAttributeGroupId();
            String selectedName = schema.getAttributeGroupNameSafe(selectedId);
            if (selectedName.equalsIgnoreCase(name)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)

Example 3 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class PivotTableBinder method executeLoad.

@Override
protected void executeLoad(final AsyncCallback<PivotContent> callback) {
    final Filter filter = new Filter(getModel().getFilter());
    final Set<Dimension> dimensions = new HashSet<>(getModel().allDimensions());
    if (filter.equals(cachedFilter) && dimensions.equals(cachedDimensions)) {
        try {
            callback.onSuccess(generateElement());
        } catch (Exception e) {
            callback.onFailure(e);
        }
    } else {
        PivotSites query = new PivotSites(dimensions, filter);
        if (query.isTooBroad()) {
            callback.onSuccess(new PivotContent());
            return;
        }
        dispatcher.execute(query, new AsyncCallback<PivotSites.PivotResult>() {

            @Override
            public void onFailure(Throwable throwable) {
                callback.onFailure(throwable);
            }

            @Override
            public void onSuccess(PivotSites.PivotResult pivotResult) {
                cachedFilter = filter;
                cachedDimensions = dimensions;
                cachedResult = pivotResult;
                try {
                    callback.onSuccess(generateElement());
                } catch (Exception e) {
                    callback.onFailure(e);
                }
            }
        });
    }
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) Filter(org.activityinfo.legacy.shared.command.Filter) PivotContent(org.activityinfo.legacy.shared.reports.content.PivotContent) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) HashSet(java.util.HashSet)

Example 4 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension 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 5 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class Bucket method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("  { Value: ").append(doubleValue());
    for (Dimension dim : dimensions()) {
        DimensionCategory cat = getCategory(dim);
        sb.append("\n    ").append(dim.toString()).append(": ");
        sb.append(cat.toString());
    }
    sb.append("\n  }");
    return sb.toString();
}
Also used : DimensionCategory(org.activityinfo.legacy.shared.reports.content.DimensionCategory) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension)

Aggregations

Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)26 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)11 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)10 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)9 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)7 Test (org.junit.Test)7 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)6 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)5 ArrayList (java.util.ArrayList)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)3 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)3 PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 User (org.activityinfo.server.database.hibernate.entity.User)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 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2