use of org.activityinfo.shared.dto.IndicatorDTO in project activityinfo by bedatadriven.
the class ItemDetail method create.
static ItemDetail create(RenderContext ctx, Map.Entry<String, Object> entry) {
ItemDetail d = new ItemDetail();
Map<String, Object> state = ctx.getState();
SchemaDTO schema = ctx.getSchema();
String key = entry.getKey();
final Object oldValue = state.get(key);
final Object newValue = entry.getValue();
state.put(key, newValue);
final StringBuilder sb = new StringBuilder();
// basic
if (key.equals("date1")) {
addValues(sb, I18N.CONSTANTS.startDate(), oldValue, newValue);
} else if (key.equals("date2")) {
addValues(sb, I18N.CONSTANTS.endDate(), oldValue, newValue);
} else if (key.equals("comments")) {
addValues(sb, I18N.CONSTANTS.comments(), oldValue, newValue);
} else if (key.equals("locationId")) {
// schema loookups
String oldName = null;
if (oldValue != null) {
oldName = ctx.getLocation(toInt(oldValue)).getName();
}
String newName = ctx.getLocation(toInt(newValue)).getName();
addValues(sb, I18N.CONSTANTS.location(), oldName, newName);
} else if (key.equals("projectId")) {
String oldName = null;
if (oldValue != null) {
oldName = schema.getProjectById(toInt(oldValue)).getName();
}
String newName = schema.getProjectById(toInt(newValue)).getName();
addValues(sb, I18N.CONSTANTS.project(), oldName, newName);
} else if (key.equals("partnerId")) {
String oldName = null;
if (oldValue != null) {
oldName = schema.getPartnerById(toInt(oldValue)).getName();
}
String newName = schema.getPartnerById(toInt(newValue)).getName();
addValues(sb, I18N.CONSTANTS.partner(), oldName, newName);
} else if (key.startsWith(IndicatorDTO.PROPERTY_PREFIX)) {
// custom
int id = IndicatorDTO.indicatorIdForPropertyName(key);
IndicatorDTO dto = schema.getIndicatorById(id);
String name = dto.getName();
Month m = IndicatorDTO.monthForPropertyName(key);
if (m != null) {
name = I18N.MESSAGES.siteHistoryIndicatorName(name, m.toLocalDate().atMidnightInMyTimezone());
}
addValues(sb, name, oldValue, newValue, dto.getUnits());
} else if (key.startsWith(AttributeDTO.PROPERTY_PREFIX)) {
int id = AttributeDTO.idForPropertyName(key);
AttributeDTO dto = schema.getAttributeById(id);
if (Boolean.parseBoolean(newValue.toString())) {
sb.append(I18N.MESSAGES.siteHistoryAttrAdd(dto.getName()));
} else {
sb.append(I18N.MESSAGES.siteHistoryAttrRemove(dto.getName()));
}
} else {
// fallback
addValues(sb, key, oldValue, newValue);
}
d.stringValue = sb.toString();
return d;
}
use of org.activityinfo.shared.dto.IndicatorDTO in project activityinfo by bedatadriven.
the class DimensionPruner method getSelectedActivities.
private Set<ActivityDTO> getSelectedActivities(SchemaDTO schema) {
Set<ActivityDTO> activities = Sets.newHashSet();
Set<Integer> indicatorIds = Sets.newHashSet(model.getFilter().getRestrictions(DimensionType.Indicator));
for (UserDatabaseDTO db : schema.getDatabases()) {
for (ActivityDTO activity : db.getActivities()) {
for (IndicatorDTO indicator : activity.getIndicators()) {
if (indicatorIds.contains(indicator.getId())) {
activities.add(activity);
}
}
}
}
return activities;
}
use of org.activityinfo.shared.dto.IndicatorDTO in project activityinfo by bedatadriven.
the class SiteExporter method createHeaders.
private void createHeaders(ActivityDTO activity, HSSFSheet sheet) {
// / The HEADER rows
Row headerRow1 = sheet.createRow(0);
Row headerRow2 = sheet.createRow(1);
headerRow2.setHeightInPoints(HEADER_CELL_HEIGHT);
// Create a title cell with the complete database + activity name
Cell titleCell = headerRow1.createCell(0);
titleCell.setCellValue(creationHelper.createRichTextString(activity.getDatabase().getName() + " - " + activity.getName()));
titleCell.setCellStyle(titleStyle);
int column = 0;
createHeaderCell(headerRow2, column++, "Date1", CellStyle.ALIGN_RIGHT);
createHeaderCell(headerRow2, column++, "Date2", CellStyle.ALIGN_RIGHT);
createHeaderCell(headerRow2, column, "Partner");
sheet.setColumnWidth(column, characters(PARTNER_COLUMN_WIDTH));
column++;
createHeaderCell(headerRow2, column, activity.getLocationType().getName());
sheet.setColumnWidth(column, characters(LOCATION_COLUMN_WIDTH));
column++;
createHeaderCell(headerRow2, column++, "Axe");
indicators = new ArrayList<Integer>(activity.getIndicators().size());
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
for (IndicatorGroup group : activity.groupIndicators()) {
if (group.getName() != null) {
// create a merged cell on the top row spanning all members
// of the group
createHeaderCell(headerRow1, column, group.getName());
sheet.addMergedRegion(new CellRangeAddress(0, 0, column, column + group.getIndicators().size() - 1));
}
for (IndicatorDTO indicator : group.getIndicators()) {
indicators.add(indicator.getId());
createHeaderCell(headerRow2, column, indicator.getName(), indicatorHeaderStyle);
sheet.setColumnWidth(column, characters(INDICATOR_COLUMN_WIDTH));
column++;
}
}
}
attributes = new ArrayList<Integer>();
for (AttributeGroupDTO group : activity.getAttributeGroups()) {
if (group.getAttributes().size() != 0) {
createHeaderCell(headerRow1, column, group.getName(), CellStyle.ALIGN_CENTER);
sheet.addMergedRegion(new CellRangeAddress(0, 0, column, column + group.getAttributes().size() - 1));
for (AttributeDTO attrib : group.getAttributes()) {
attributes.add(attrib.getId());
createHeaderCell(headerRow2, column, attrib.getName(), attribHeaderStyle);
sheet.setColumnWidth(column, characters(ATTRIBUTE_COLUMN_WIDTH));
column++;
}
}
}
levels = new ArrayList<Integer>();
for (AdminLevelDTO level : activity.getAdminLevels()) {
createHeaderCell(headerRow2, column++, "Code " + level.getName());
createHeaderCell(headerRow2, column++, level.getName());
levels.add(level.getId());
}
int latColumn = column++;
int lngColumn = column++;
createHeaderCell(headerRow2, latColumn, I18N.CONSTANTS.longitude(), CellStyle.ALIGN_RIGHT);
createHeaderCell(headerRow2, lngColumn, I18N.CONSTANTS.latitude(), CellStyle.ALIGN_RIGHT);
sheet.setColumnWidth(lngColumn, characters(COORD_COLUMN_WIDTH));
sheet.setColumnWidth(latColumn, characters(COORD_COLUMN_WIDTH));
createHeaderCell(headerRow2, column++, I18N.CONSTANTS.comments());
}
use of org.activityinfo.shared.dto.IndicatorDTO in project activityinfo by bedatadriven.
the class ItextMapRenderer method addSingleIndicatorDescription.
private void addSingleIndicatorDescription(MapReportElement element, MapLayer layer, Cell descriptionCell) {
int indicatorId = layer.getIndicatorIds().get(0);
IndicatorDTO indicator = element.getContent().getIndicatorById(indicatorId);
if (indicator == null) {
throw new NullPointerException("indicatorId:" + indicatorId);
}
descriptionCell.add(ThemeHelper.filterDescription(indicator.getName()));
}
use of org.activityinfo.shared.dto.IndicatorDTO in project activityinfo by bedatadriven.
the class DimensionPrunerTest method setupData.
@Before
public void setupData() {
ActivityDTO dist = new ActivityDTO(1, "Distribution");
IndicatorDTO nbMenages = new IndicatorDTO();
nbMenages.setId(NB_MENAGES_INDICATOR_ID);
nbMenages.setName("Nb Menages");
dist.getIndicators().add(nbMenages);
AttributeGroupDTO distFunding = new AttributeGroupDTO(NFI_FUNDING_GROUP_ID);
distFunding.setName("Funding Source");
dist.getAttributeGroups().add(distFunding);
ActivityDTO fairs = new ActivityDTO(2, "Faire");
AttributeGroupDTO fairFunding = new AttributeGroupDTO(FAIR_FUNDING_GROUP_ID);
fairFunding.setName("Funding Source");
fairs.getAttributeGroups().add(fairFunding);
IndicatorDTO voucherValue = new IndicatorDTO();
voucherValue.setId(VOUCHER_INDICATOR_ID);
voucherValue.setName("Voucher Value");
fairs.getIndicators().add(voucherValue);
UserDatabaseDTO nfi = new UserDatabaseDTO(1, "NFI");
nfi.getActivities().add(dist);
nfi.getActivities().add(fairs);
this.schema = new SchemaDTO();
schema.getDatabases().add(nfi);
dispatcher.setResult(GetSchema.class, schema);
}
Aggregations