Search in sources :

Example 1 with IndicatorRowDTO

use of org.activityinfo.shared.dto.IndicatorRowDTO 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);
}
Also used : ReportingPeriod(org.activityinfo.server.database.hibernate.entity.ReportingPeriod) Month(org.activityinfo.shared.command.Month) IndicatorValue(org.activityinfo.server.database.hibernate.entity.IndicatorValue) ArrayList(java.util.ArrayList) MonthlyReportResult(org.activityinfo.shared.command.result.MonthlyReportResult) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) IndicatorRowDTO(org.activityinfo.shared.dto.IndicatorRowDTO)

Example 2 with IndicatorRowDTO

use of org.activityinfo.shared.dto.IndicatorRowDTO in project activityinfo by bedatadriven.

the class MonthlyReportsPanel method save.

private void save() {
    ArrayList<UpdateMonthlyReports.Change> changes = new ArrayList<UpdateMonthlyReports.Change>();
    for (Record record : store.getModifiedRecords()) {
        IndicatorRowDTO report = (IndicatorRowDTO) record.getModel();
        for (String property : record.getChanges().keySet()) {
            UpdateMonthlyReports.Change change = new UpdateMonthlyReports.Change();
            change.setIndicatorId(report.getIndicatorId());
            change.setMonth(IndicatorRowDTO.monthForProperty(property));
            change.setValue((Double) report.get(property));
            changes.add(change);
        }
    }
    service.execute(new UpdateMonthlyReports(currentSiteId, changes), new MaskingAsyncMonitor(this, I18N.CONSTANTS.save()), new AsyncCallback<VoidResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // handled by monitor
        }

        @Override
        public void onSuccess(VoidResult result) {
        }
    });
}
Also used : UpdateMonthlyReports(org.activityinfo.shared.command.UpdateMonthlyReports) VoidResult(org.activityinfo.shared.command.result.VoidResult) ArrayList(java.util.ArrayList) IndicatorRowDTO(org.activityinfo.shared.dto.IndicatorRowDTO) MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) Record(com.extjs.gxt.ui.client.store.Record)

Aggregations

ArrayList (java.util.ArrayList)2 IndicatorRowDTO (org.activityinfo.shared.dto.IndicatorRowDTO)2 Record (com.extjs.gxt.ui.client.store.Record)1 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 IndicatorValue (org.activityinfo.server.database.hibernate.entity.IndicatorValue)1 ReportingPeriod (org.activityinfo.server.database.hibernate.entity.ReportingPeriod)1 Month (org.activityinfo.shared.command.Month)1 UpdateMonthlyReports (org.activityinfo.shared.command.UpdateMonthlyReports)1 MonthlyReportResult (org.activityinfo.shared.command.result.MonthlyReportResult)1 VoidResult (org.activityinfo.shared.command.result.VoidResult)1