Search in sources :

Example 6 with DimensionType

use of org.activityinfo.shared.report.model.DimensionType in project activityinfo by bedatadriven.

the class Filter method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    for (DimensionType type : getRestrictedDimensions()) {
        if (sb.length() != 0) {
            sb.append(", ");
        }
        sb.append(type.toString()).append("={");
        for (Integer id : getRestrictions(type)) {
            sb.append(' ').append(id);
        }
        sb.append(" }");
    }
    if (dateRange.getMinDate() != null || dateRange.getMaxDate() != null) {
        if (sb.length() != 0) {
            sb.append(", ");
        }
        sb.append("date=[");
        if (dateRange.getMinDate() != null) {
            sb.append(dateRange.getMinDate());
        }
        sb.append(",");
        if (dateRange.getMaxDate() != null) {
            sb.append(dateRange.getMaxDate()).append("]");
        }
    }
    if (sb.length() != 0) {
        sb.append(", ");
    }
    sb.append("lenient: ");
    sb.append(lenient);
    sb.insert(0, "[");
    sb.append("]");
    return sb.toString();
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType)

Example 7 with DimensionType

use of org.activityinfo.shared.report.model.DimensionType in project activityinfo by bedatadriven.

the class FilterUrlSerializer method toUrlFragment.

public static String toUrlFragment(Filter filter) {
    StringBuilder url = new StringBuilder();
    for (DimensionType dim : filter.getRestrictedDimensions()) {
        Set<Integer> ids = filter.getRestrictions(dim);
        if (url.length() > 0) {
            url.append("-");
        }
        url.append(dim.name());
        for (Integer id : ids) {
            url.append("+");
            url.append(id);
        }
    }
    if (filter.isDateRestricted()) {
        if (url.length() > 0) {
            url.append("-");
        }
        url.append("date+");
        appendDate(filter.getDateRange().getMinLocalDate(), url);
        url.append('+');
        appendDate(filter.getDateRange().getMaxLocalDate(), url);
    }
    return url.toString();
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType)

Example 8 with DimensionType

use of org.activityinfo.shared.report.model.DimensionType in project activityinfo by bedatadriven.

the class GetSitesHandler method applyFilter.

private void applyFilter(SqlQuery query, Filter filter) {
    if (filter != null) {
        if (filter.getRestrictedDimensions() != null && filter.getRestrictedDimensions().size() > 0) {
            query.onlyWhere(" AND (");
            boolean isFirst = true;
            boolean isRestricted = false;
            for (DimensionType type : filter.getRestrictedDimensions()) {
                if (isQueryableType(type)) {
                    addJoint(query, filter.isLenient(), isFirst);
                    isRestricted = true;
                }
                if (type == DimensionType.Activity) {
                    query.onlyWhere("activity.ActivityId").in(filter.getRestrictions(type));
                } else if (type == DimensionType.Database) {
                    query.onlyWhere("activity.DatabaseId").in(filter.getRestrictions(type));
                } else if (type == DimensionType.Partner) {
                    query.onlyWhere("site.PartnerId").in(filter.getRestrictions(type));
                } else if (type == DimensionType.Project) {
                    query.onlyWhere("site.ProjectId").in(filter.getRestrictions(type));
                } else if (type == DimensionType.AdminLevel) {
                    query.onlyWhere("site.LocationId").in(SqlQuery.select("Link.LocationId").from(Tables.LOCATION_ADMIN_LINK, "Link").where("Link.AdminEntityId").in(filter.getRestrictions(type)));
                } else if (type == DimensionType.Site) {
                    query.onlyWhere("site.SiteId").in(filter.getRestrictions(type));
                } else if (type == DimensionType.Attribute) {
                    Set<Integer> attributes = filter.getRestrictions(DimensionType.Attribute);
                    boolean isFirstAttr = true;
                    for (Integer attribute : attributes) {
                        SqlQuery attributefilter = SqlQuery.select().appendColumn("1", "__VAL_EXISTS").from("attributevalue", "av").whereTrue("av.value=1").and("av.SiteId = site.SiteId").where("av.AttributeId").equalTo(attribute);
                        addJoint(query, filter.isLenient(), isFirstAttr);
                        if (isFirstAttr) {
                            isFirstAttr = false;
                        }
                        query.onlyWhere("EXISTS (" + attributefilter.sql() + ") ");
                        query.appendParameter(attribute);
                    }
                }
                if (isQueryableType(type) && isFirst) {
                    isFirst = false;
                }
            }
            if (!isRestricted) {
                query.onlyWhere(" 1=1 ");
            }
            query.onlyWhere(")");
        }
        LocalDate filterMinDate = filter.getDateRange().getMinLocalDate();
        if (filterMinDate != null) {
            query.where("site.Date2").greaterThanOrEqualTo(filterMinDate);
        }
        LocalDate filterMaxDate = filter.getDateRange().getMaxLocalDate();
        if (filterMaxDate != null) {
            query.where("site.Date2").lessThanOrEqualTo(filterMaxDate);
        }
    }
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Example 9 with DimensionType

use of org.activityinfo.shared.report.model.DimensionType in project activityinfo by bedatadriven.

the class PivotQuery method appendDimensionRestrictions.

private void appendDimensionRestrictions() {
    if (filter != null) {
        if (filter.getRestrictedDimensions() != null && filter.getRestrictedDimensions().size() > 0) {
            query.where("(");
            boolean isFirst = true;
            for (DimensionType type : filter.getRestrictedDimensions()) {
                addJoint(query, filter.isLenient(), isFirst);
                if (isFirst) {
                    isFirst = false;
                }
                if (type == DimensionType.AdminLevel) {
                    query.onlyWhere(baseTable.getDimensionIdColumn(DimensionType.Location)).in(SqlQuery.select("Link.LocationId").from(Tables.LOCATION_ADMIN_LINK, "Link").where("Link.AdminEntityId").in(filter.getRestrictions(DimensionType.AdminLevel)));
                } else if (type == DimensionType.Attribute) {
                    Set<Integer> attributes = filter.getRestrictions(DimensionType.Attribute);
                    boolean isFirstAttr = true;
                    for (Integer attribute : attributes) {
                        SqlQuery attributefilter = SqlQuery.select().appendColumn("1", "__VAL_EXISTS").from("attributevalue", "v").whereTrue("v.value=1").and("v.SiteId = Site.SiteId").where("v.AttributeId").equalTo(attribute);
                        addJoint(query, filter.isLenient(), isFirstAttr);
                        if (isFirstAttr) {
                            isFirstAttr = false;
                        }
                        query.onlyWhere("EXISTS (" + attributefilter.sql() + ") ");
                        query.appendParameter(attribute);
                    }
                } else {
                    query.onlyWhere(baseTable.getDimensionIdColumn(type)).in(filter.getRestrictions(type));
                }
            }
            query.onlyWhere(")");
        }
    }
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) Set(java.util.Set) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery)

Example 10 with DimensionType

use of org.activityinfo.shared.report.model.DimensionType in project activityinfo by bedatadriven.

the class QueryParser method createFilter.

private void createFilter() {
    Filter filter = new Filter();
    for (String dimensionString : preciseDimensions.keySet()) {
        DimensionType dimension;
        try {
            dimension = fromString(dimensionString);
        } catch (Exception e) {
            // Ruthlessly ignore nonparseable string
            continue;
        }
        List<Integer> ids = new ArrayList<Integer>();
        for (String idString : preciseDimensions.get(dimensionString)) {
            try {
                int id = Integer.parseInt(idString);
                ids.add(id);
            } catch (Exception ex) {
                // Ruthlessly ignore nonparseable string
                continue;
            }
        }
        if (ids.size() > 0 && isSupportedDimension(dimension)) {
            filter.addRestriction(dimension, ids);
        }
    }
    this.filter = filter;
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) Filter(org.activityinfo.shared.command.Filter) ArrayList(java.util.ArrayList)

Aggregations

DimensionType (org.activityinfo.shared.report.model.DimensionType)17 Filter (org.activityinfo.shared.command.Filter)5 ArrayList (java.util.ArrayList)4 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)2 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Set (java.util.Set)2 FilterDescription (org.activityinfo.shared.report.content.FilterDescription)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 BubbleLayerGenerator (org.activityinfo.server.report.generator.map.BubbleLayerGenerator)1 IconLayerGenerator (org.activityinfo.server.report.generator.map.IconLayerGenerator)1 LayerGenerator (org.activityinfo.server.report.generator.map.LayerGenerator)1 Margins (org.activityinfo.server.report.generator.map.Margins)1