Search in sources :

Example 1 with MonthlyReportResult

use of org.activityinfo.shared.command.result.MonthlyReportResult 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 MonthlyReportResult

use of org.activityinfo.shared.command.result.MonthlyReportResult in project activityinfo by bedatadriven.

the class MonthlyReportsTest method testGetReportsWhenEmpty.

@Test
public void testGetReportsWhenEmpty() throws Exception {
    GetMonthlyReports cmd = new GetMonthlyReports(7);
    cmd.setStartMonth(new Month(2009, 1));
    cmd.setEndMonth(new Month(2009, 2));
    MonthlyReportResult result = execute(cmd);
    Assert.assertEquals(1, result.getData().size());
}
Also used : Month(org.activityinfo.shared.command.Month) GetMonthlyReports(org.activityinfo.shared.command.GetMonthlyReports) MonthlyReportResult(org.activityinfo.shared.command.result.MonthlyReportResult) Test(org.junit.Test)

Example 3 with MonthlyReportResult

use of org.activityinfo.shared.command.result.MonthlyReportResult in project activityinfo by bedatadriven.

the class MonthlyReportsTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    ArrayList<UpdateMonthlyReports.Change> changes = new ArrayList<UpdateMonthlyReports.Change>();
    changes.add(new UpdateMonthlyReports.Change(6, new Month(2009, 1), 45.0));
    changes.add(new UpdateMonthlyReports.Change(6, new Month(2009, 3), 22.0));
    execute(new UpdateMonthlyReports(6, changes));
    // verify that that changes have been made
    GetMonthlyReports cmd = new GetMonthlyReports(6);
    cmd.setStartMonth(new Month(2009, 1));
    cmd.setEndMonth(new Month(2009, 3));
    MonthlyReportResult result = execute(cmd);
    Assert.assertEquals(1, result.getData().size());
    Assert.assertEquals(45, result.getData().get(0).getValue(2009, 1).intValue());
    Assert.assertEquals(70, result.getData().get(0).getValue(2009, 2).intValue());
    Assert.assertEquals(22, result.getData().get(0).getValue(2009, 3).intValue());
}
Also used : Month(org.activityinfo.shared.command.Month) GetMonthlyReports(org.activityinfo.shared.command.GetMonthlyReports) UpdateMonthlyReports(org.activityinfo.shared.command.UpdateMonthlyReports) ArrayList(java.util.ArrayList) MonthlyReportResult(org.activityinfo.shared.command.result.MonthlyReportResult) Test(org.junit.Test)

Example 4 with MonthlyReportResult

use of org.activityinfo.shared.command.result.MonthlyReportResult in project activityinfo by bedatadriven.

the class MonthlyReportsTest method testGetReports.

@Test
public void testGetReports() throws Exception {
    GetMonthlyReports cmd = new GetMonthlyReports(6);
    cmd.setStartMonth(new Month(2009, 1));
    cmd.setEndMonth(new Month(2009, 2));
    MonthlyReportResult result = execute(cmd);
    Assert.assertEquals(1, result.getData().size());
    Assert.assertEquals(35, result.getData().get(0).getValue(2009, 1).intValue());
    Assert.assertEquals(70, result.getData().get(0).getValue(2009, 2).intValue());
}
Also used : Month(org.activityinfo.shared.command.Month) GetMonthlyReports(org.activityinfo.shared.command.GetMonthlyReports) MonthlyReportResult(org.activityinfo.shared.command.result.MonthlyReportResult) Test(org.junit.Test)

Aggregations

Month (org.activityinfo.shared.command.Month)4 MonthlyReportResult (org.activityinfo.shared.command.result.MonthlyReportResult)4 GetMonthlyReports (org.activityinfo.shared.command.GetMonthlyReports)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 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 UpdateMonthlyReports (org.activityinfo.shared.command.UpdateMonthlyReports)1 IndicatorRowDTO (org.activityinfo.shared.dto.IndicatorRowDTO)1