use of org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change in project activityinfo by bedatadriven.
the class CommandQueue method deserializeMonthlyReports.
private Command deserializeMonthlyReports(JsonObject root) {
int siteId = root.get("siteId").getAsInt();
JsonArray changeArray = root.get("changes").getAsJsonArray();
ArrayList<Change> changes = Lists.newArrayList();
for (int i = 0; i != changeArray.size(); ++i) {
JsonObject changeObject = changeArray.get(i).getAsJsonObject();
int indicatorId = changeObject.get("indicatorId").getAsInt();
Month month = new Month(changeObject.get("year").getAsInt(), changeObject.get("month").getAsInt());
Double value = null;
if (changeObject.get("value").isJsonPrimitive()) {
value = changeObject.get("value").getAsDouble();
}
changes.add(new Change(indicatorId, month, value));
}
return new UpdateMonthlyReports(siteId, changes);
}
use of org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change in project activityinfo by bedatadriven.
the class CommandQueue method serialize.
private JsonObject serialize(UpdateMonthlyReports cmd) {
JsonArray changeArray = new JsonArray();
for (Change change : cmd.getChanges()) {
JsonObject changeObject = new JsonObject();
changeObject.addProperty("year", change.getMonth().getYear());
changeObject.addProperty("month", change.getMonth().getMonth());
changeObject.addProperty("indicatorId", change.getIndicatorId());
changeObject.addProperty("value", change.getValue());
changeArray.add(changeObject);
}
JsonObject root = new JsonObject();
root.addProperty("commandClass", "UpdateMonthlyReports");
root.addProperty("siteId", cmd.getSiteId());
root.add("changes", changeArray);
return root;
}
use of org.activityinfo.legacy.shared.command.UpdateMonthlyReports.Change 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