use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class TableGenerator method generate.
@Override
public void generate(User user, TableElement element, Filter inheritedFilter, DateRange dateRange) {
Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
TableContent content = new TableContent();
content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
TableData data = generateData(element, effectiveFilter);
content.setData(data);
if (element.getMap() != null) {
mapGenerator.generate(user, element.getMap(), effectiveFilter, dateRange);
Map<Integer, String> siteLabels = element.getMap().getContent().siteLabelMap();
for (SiteDTO row : data.getRows()) {
row.set("map", siteLabels.get(row.getId()));
}
}
element.setContent(content);
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class PiechartLayerGenerator method generatePoints.
public void generatePoints(TiledMap map, PiechartMapLayer layer, Clusterer clusterer, List<PointValue> mapped, List<PointValue> unmapped) {
for (SiteDTO site : sites) {
if (hasValue(site, layer.getIndicatorIds())) {
Point px = null;
if (site.hasLatLong()) {
px = map.fromLatLngToPixel(new AiLatLng(site.getLatitude(), site.getLongitude()));
}
Double value = getValue(site, layer.getIndicatorIds());
if (value != null && value != 0) {
PointValue pv = new PointValue(site, new MapSymbol(), value, px);
calulateSlices(pv, site);
if (clusterer.isMapped(site)) {
mapped.add(pv);
} else {
unmapped.add(pv);
}
}
}
}
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class ItextTableRenderer method renderTable.
private void renderTable(Document document, TableData data) throws DocumentException {
int colDepth = data.getRootColumn().getDepth();
List<TableColumn> colLeaves = data.getRootColumn().getLeaves();
int colBreadth = colLeaves.size();
Table table = new Table(colBreadth, 1);
table.setUseVariableBorders(true);
table.setWidth(100.0f);
table.setBorderWidth(0);
for (int depth = 1; depth <= colDepth; ++depth) {
List<TableColumn> columns = data.getRootColumn().getDescendantsAtDepth(depth);
for (TableColumn column : columns) {
Cell cell = ThemeHelper.columnHeaderCell(column.getLabel(), column.isLeaf(), computeHAlign(column));
cell.setColspan(Math.max(1, column.getChildren().size()));
cell.setRowspan(colDepth - depth - column.getDepth() + 1);
table.addCell(cell);
}
}
table.endHeaders();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
NumberFormat numberFormat = NumberFormat.getIntegerInstance();
numberFormat.setGroupingUsed(true);
for (SiteDTO row : data.getRows()) {
for (TableColumn column : colLeaves) {
Object value = row.get(column.getSitePropertyName());
String label = "";
if (value instanceof Date) {
label = dateFormat.format(value);
} else if (value instanceof Number) {
label = numberFormat.format(value);
} else if (value != null) {
label = value.toString();
}
table.addCell(ThemeHelper.bodyCell(label, false, 0, true, computeHAlign(column)));
}
}
document.add(table);
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class GetSitesHandler method joinIndicatorValues.
private void joinIndicatorValues(GetSites command, SqlTransaction tx, final Multimap<Integer, SiteDTO> siteMap) {
Log.trace("Starting joinIndicatorValues()");
SqlQuery query = SqlQuery.select().appendColumn("P.SiteId", "SiteId").appendColumn("V.IndicatorId", "SourceIndicatorId").appendColumn("I.ActivityId", "SourceActivityId").appendColumn("D.IndicatorId", "DestIndicatorId").appendColumn("D.ActivityId", "DestActivityId").appendColumn("V.Value").from(Tables.REPORTING_PERIOD, "P").innerJoin(Tables.INDICATOR_VALUE, "V").on("P.ReportingPeriodId = V.ReportingPeriodId").innerJoin(Tables.INDICATOR, "I").on("I.IndicatorId = V.IndicatorId").leftJoin(Tables.INDICATOR_LINK, "L").on("L.SourceIndicatorId=I.IndicatorId").leftJoin(Tables.INDICATOR, "D").on("L.DestinationIndicatorId=D.IndicatorId").where("P.SiteId").in(siteMap.keySet()).and("I.dateDeleted IS NULL");
Log.info(query.toString());
query.execute(tx, new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
Log.trace("Received results for join indicators");
for (SqlResultSetRow row : results.getRows()) {
double indicatorValue = row.getDouble("Value");
int sourceActivityid = row.getInt("SourceActivityId");
for (SiteDTO site : siteMap.get(row.getInt("SiteId"))) {
if (sourceActivityid == site.getActivityId()) {
int indicatorId = row.getInt("SourceIndicatorId");
site.setIndicatorValue(indicatorId, indicatorValue);
} else if (!row.isNull("DestActivityId")) {
int destActivityId = row.getInt("DestActivityId");
if (site.getActivityId() == destActivityId) {
int indicatorId = row.getInt("DestIndicatorId");
site.setIndicatorValue(indicatorId, indicatorValue);
}
}
}
}
Log.trace("Done populating dtos for join indicators");
}
});
}
use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.
the class GetSitesHandler method joinEntities.
private void joinEntities(SqlTransaction tx, final Multimap<Integer, SiteDTO> siteMap) {
Log.trace("Starting joinEntities()");
SqlQuery.select("site.SiteId", "Link.adminEntityId", "e.name", "e.adminLevelId", "e.adminEntityParentId", "x1", "y1", "x2", "y2").from(Tables.SITE).innerJoin(Tables.LOCATION).on("location.LocationId = site.LocationId").innerJoin(Tables.LOCATION_ADMIN_LINK, "Link").on("Link.LocationId = location.LocationId").innerJoin(Tables.ADMIN_ENTITY, "e").on("Link.AdminEntityId = e.AdminEntityId").where("site.SiteId").in(siteMap.keySet()).execute(tx, new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
Log.trace("Received results for joinEntities()");
Map<Integer, AdminEntityDTO> entities = Maps.newHashMap();
for (SqlResultSetRow row : results.getRows()) {
int adminEntityId = row.getInt("adminEntityId");
AdminEntityDTO entity = entities.get(adminEntityId);
if (entity == null) {
entity = GetAdminEntitiesHandler.toEntity(row);
entities.put(adminEntityId, entity);
}
for (SiteDTO site : siteMap.get(row.getInt("SiteId"))) {
site.setAdminEntity(entity.getLevelId(), entity);
}
}
Log.trace("Done populating results for joinEntities");
}
});
}
Aggregations