use of org.activityinfo.legacy.shared.command.DimensionType in project activityinfo by bedatadriven.
the class OldGetSitesHandler method applyFilter.
private void applyFilter(SqlQuery query, GetSites command) {
Filter filter = command.getFilter();
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, 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, isFirstAttr);
if (isFirstAttr) {
isFirstAttr = false;
}
query.onlyWhere("EXISTS (" + attributefilter.sql() + ") ");
query.appendParameter(attribute);
}
} else if (type == DimensionType.Location) {
query.onlyWhere("location.locationId").in(filter.getRestrictions(type));
}
if (isQueryableType(type) && isFirst) {
isFirst = false;
}
}
if (!isRestricted) {
query.onlyWhere(" 1=1 ");
}
query.onlyWhere(")");
}
if (!command.isFetchAllReportingPeriods()) {
// it does not make sense to filter monthly activity by site dates (filter by reporting period instead)
applyDateRangeFilter("site.Date1", filter.getStartDateRange(), query);
applyDateRangeFilter("site.Date2", filter.getEndDateRange(), query);
}
}
}
use of org.activityinfo.legacy.shared.command.DimensionType in project activityinfo by bedatadriven.
the class CalculatedIndicatorsQuery method composeSiteFilter.
private Filter composeSiteFilter() {
Filter siteFilter = new Filter();
siteFilter.addRestriction(DimensionType.Activity, activityIds);
siteFilter.setEndDateRange(query.getFilter().getEndDateRange());
for (DimensionType type : query.getFilter().getRestrictedDimensions()) {
if (type != DimensionType.Activity && type != DimensionType.Database && type != DimensionType.Indicator) {
siteFilter.addRestriction(type, query.getFilter().getRestrictions(type));
}
}
return siteFilter;
}
use of org.activityinfo.legacy.shared.command.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, 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, 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.legacy.shared.command.DimensionType in project activityinfo by bedatadriven.
the class FilterAdapter method marshal.
@Override
public FilterElement marshal(Filter filter) throws Exception {
FilterElement element = new FilterElement();
element.startDateRange = filter.getStartDateRange();
element.endDateRange = filter.getEndDateRange();
for (DimensionType t : filter.getRestrictedDimensions()) {
Restriction r = new Restriction();
r.dimension = t.toString().toLowerCase();
for (Integer id : filter.getRestrictions(t)) {
r.categories.add(id.toString());
}
element.restrictions.add(r);
}
return element;
}
use of org.activityinfo.legacy.shared.command.DimensionType in project activityinfo by bedatadriven.
the class MapGenerator method generate.
@Override
public void generate(User user, MapReportElement element, Filter inheritedFilter, DateRange dateRange) {
Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
MapContent content = new MapContent();
content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
Map<Integer, Indicator> indicators = queryIndicators(element);
// Set up layer generators
List<LayerGenerator> layerGenerators = new ArrayList<LayerGenerator>();
for (MapLayer layer : element.getLayers()) {
if (layer.isVisible()) {
LayerGenerator layerGtor = createGenerator(layer, indicators);
layerGtor.query(getDispatcher(), effectiveFilter);
layerGenerators.add(layerGtor);
}
}
// FIRST PASS: calculate extents and margins
int width = element.getWidth();
int height = element.getHeight();
AiLatLng center;
int zoom;
Extents extents = Extents.emptyExtents();
Margins margins = new Margins(0);
for (LayerGenerator layerGtor : layerGenerators) {
extents.grow(layerGtor.calculateExtents());
margins.grow(layerGtor.calculateMargins());
}
content.setExtents(extents);
if (element.getCenter() == null) {
// Now we're ready to calculate the zoom level
// and the projection
zoom = TileMath.zoomLevelForExtents(extents, width, height);
center = extents.center();
} else {
center = element.getCenter();
zoom = element.getZoomLevel();
}
content.setCenter(center);
// Retrieve the basemap and clamp zoom level
BaseMap baseMap = findBaseMap(element, indicators.values());
if (zoom < baseMap.getMinZoom()) {
zoom = baseMap.getMinZoom();
}
if (zoom > baseMap.getMaxZoom()) {
zoom = baseMap.getMaxZoom();
}
if (zoom > element.getMaximumZoomLevel()) {
zoom = element.getMaximumZoomLevel();
}
TiledMap map = new TiledMap(width, height, center, zoom);
content.setBaseMap(baseMap);
content.setZoomLevel(zoom);
// Generate the actual content
for (LayerGenerator layerGtor : layerGenerators) {
layerGtor.generate(map, content);
}
content.setIndicators(toDTOs(indicators.values()));
element.setContent(content);
}
Aggregations