use of org.activityinfo.server.database.hibernate.entity.IndicatorValue in project activityinfo by bedatadriven.
the class GetMonthlyReportsHandler method execute.
@Override
public CommandResult execute(GetMonthlyReports cmd, User user) throws CommandException {
List<ReportingPeriod> periods = em.createQuery("select p from ReportingPeriod p where p.site.id = ?1").setParameter(1, cmd.getSiteId()).getResultList();
List<Indicator> indicators = em.createQuery("select i from Indicator i where i.activity.id =" + "(select s.activity.id from Site s where s.id = ?1)").setParameter(1, cmd.getSiteId()).getResultList();
List<IndicatorRowDTO> list = new ArrayList<IndicatorRowDTO>();
for (Indicator indicator : indicators) {
IndicatorRowDTO dto = new IndicatorRowDTO();
dto.setIndicatorId(indicator.getId());
dto.setSiteId(cmd.getSiteId());
dto.setIndicatorName(indicator.getName());
for (ReportingPeriod period : periods) {
Month month = HandlerUtil.monthFromRange(period.getDate1(), period.getDate2());
if (month != null && month.compareTo(cmd.getStartMonth()) >= 0 && month.compareTo(cmd.getEndMonth()) <= 0) {
for (IndicatorValue value : period.getIndicatorValues()) {
if (value.getIndicator().getId() == indicator.getId()) {
dto.setValue(month, value.getValue());
}
}
}
}
list.add(dto);
}
return new MonthlyReportResult(list);
}
Aggregations