use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.
the class UpdateMonthlyReportsAsync method queryPeriodMap.
private Promise<Map<Month, Integer>> queryPeriodMap(UpdateMonthlyReports command, ExecutionContext context) {
final Promise<Map<Month, Integer>> promise = new Promise<>();
SqlQuery.select("reportingPeriodId", "Date2").from(Tables.REPORTING_PERIOD, "rp").where("siteId").equalTo(command.getSiteId()).execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
Map<Month, Integer> periodMap = Maps.newHashMap();
for (SqlResultSetRow row : results.getRows()) {
Date endDate = row.getDate("Date2");
Month month = Month.of(endDate);
periodMap.put(month, row.getInt("reportingPeriodId"));
}
promise.resolve(periodMap);
}
});
return promise;
}
use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.
the class MonthWidget method input.
private FieldInput input() {
try {
int year = Integer.parseInt(yearBox.getText());
int monthOfYear = MONTHS.indexOf(monthBox.getText()) + 1;
return new FieldInput(new Month(year, monthOfYear));
} catch (Exception e) {
return FieldInput.INVALID_INPUT;
}
}
use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.
the class MonthWidget method init.
@Override
public void init(FieldValue value) {
if (value instanceof Month) {
Month month = (Month) value;
yearBox.setText(Integer.toString(month.getYear()));
monthBox.setText(MONTHS.get(month.getMonth() - 1));
}
}
use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.
the class HandlerUtil method monthFromRange.
static Month monthFromRange(Date date1, Date date2) {
Calendar c1 = Calendar.getInstance();
c1.setTime(date1);
if (c1.get(Calendar.DAY_OF_MONTH) != 1) {
return null;
}
Calendar c2 = Calendar.getInstance();
c2.setTime(date2);
if (c2.get(Calendar.DAY_OF_MONTH) != c2.getActualMaximum(Calendar.DAY_OF_MONTH)) {
return null;
}
if (c2.get(Calendar.MONTH) != c1.get(Calendar.MONTH) || c2.get(Calendar.YEAR) != c2.get(Calendar.YEAR)) {
return null;
}
return new Month(c1.get(Calendar.YEAR), c1.get(Calendar.MONTH) + 1);
}
use of org.activityinfo.model.type.time.Month in project activityinfo by bedatadriven.
the class SyncIntegrationTest method updateMonthlyReports.
@Test
@OnDataSet("/dbunit/monthly-calc-indicators.db.xml")
public void updateMonthlyReports() throws SQLException, InterruptedException {
synchronize();
int siteId = 1;
MonthlyReportResult result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
IndicatorRowDTO women = result.getData().get(0);
IndicatorRowDTO men = result.getData().get(1);
assertThat(women.getIndicatorName(), equalTo("women"));
assertThat(women.getIndicatorId(), equalTo(7002));
assertThat(men.getIndicatorName(), equalTo("men"));
assertThat(men.getActivityName(), equalTo("NFI"));
assertThat(men.getActivityId(), equalTo(901));
assertThat(men.getIndicatorId(), equalTo(7001));
assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(200d));
assertThat(women.getValue(2009, 1), equalTo(300d));
assertThat(men.getValue(2009, 2), equalTo(150d));
assertThat(women.getValue(2009, 2), equalTo(330d));
// Update locally
executeLocally(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 221d), new Change(men.getIndicatorId(), new Month(2009, 3), 444d), new Change(women.getIndicatorId(), new Month(2009, 5), 200d), new Change(men.getIndicatorId(), new Month(2009, 5), 522d))));
result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
women = result.getData().get(0);
men = result.getData().get(1);
assertThat(men.getValue(2009, 1), equalTo(221d));
assertThat(women.getValue(2009, 1), equalTo(300d));
// same - no change
assertThat(men.getValue(2009, 2), equalTo(150d));
assertThat(women.getValue(2009, 2), equalTo(330d));
// new periods
assertThat(men.getValue(2009, 3), equalTo(444d));
assertThat(women.getValue(2009, 5), equalTo(200d));
assertThat(men.getValue(2009, 5), equalTo(522d));
// Synchronize
synchronize();
newRequest();
MonthlyReportResult remoteResult = executeRemotely(new GetMonthlyReports(siteId, new Month(2009, 1), 12));
women = remoteResult.getData().get(0);
men = remoteResult.getData().get(1);
assertThat(men.getValue(2009, 1), equalTo(221d));
assertThat(women.getValue(2009, 1), equalTo(300d));
// same - no change
assertThat(men.getValue(2009, 2), equalTo(150d));
assertThat(women.getValue(2009, 2), equalTo(330d));
// new periods
assertThat(men.getValue(2009, 3), equalTo(444d));
assertThat(women.getValue(2009, 5), equalTo(200d));
assertThat(men.getValue(2009, 5), equalTo(522d));
newRequest();
// REmote update
executeRemotely(new UpdateMonthlyReports(siteId, Lists.newArrayList(new Change(men.getIndicatorId(), new Month(2009, 1), 40d), new Change(women.getIndicatorId(), new Month(2009, 3), 6000d))));
newRequest();
synchronize();
result = executeLocally(new GetMonthlyReports(siteId, new Month(2009, 1), 5));
women = result.getData().get(0);
men = result.getData().get(1);
assertThat(men.getValue(2009, 1), CoreMatchers.equalTo(40d));
// unchanged
assertThat(women.getValue(2009, 1), CoreMatchers.equalTo(300d));
assertThat(women.getValue(2009, 3), equalTo(6000d));
}
Aggregations