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();
}
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();
}
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);
}
}
}
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(")");
}
}
}
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;
}
Aggregations