use of org.activityinfo.legacy.shared.command.CreateSite in project activityinfo by bedatadriven.
the class CreateSiteTest method testAllAttribsFalse.
@Test
public void testAllAttribsFalse() throws CommandException {
// create a new detached, client model
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setLocationName("Virunga");
newSite.setAttributeValue(1, false);
newSite.setAttributeValue(2, false);
newSite.setProject(new ProjectDTO(1, "SomeProject"));
// create command
CreateSite cmd = new CreateSite(newSite);
assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
// execute the command
setUser(1);
CreateResult result = execute(cmd);
// let the client know the command has succeeded
newSite.setId(result.getNewId());
// try to retrieve what we've created
SiteDTO secondRead = readSite(newSite.getId());
// confirm that the changes are there
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(1));
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(2));
}
use of org.activityinfo.legacy.shared.command.CreateSite in project activityinfo by bedatadriven.
the class CreateSiteTest method test.
@Test
public void test() throws CommandException {
LocationDTO location = LocationDTOs.newLocation();
execute(new CreateLocation(location));
SiteDTO newSite = SiteDTOs.newSite();
newSite.setLocation(location);
CreateSite cmd = new CreateSite(newSite);
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
assertThat(result.getNewId(), not(equalTo(0)));
SiteDTO secondRead = readSite(newSite.getId());
SiteDTOs.validateNewSite(secondRead);
}
use of org.activityinfo.legacy.shared.command.CreateSite in project activityinfo by bedatadriven.
the class CreateSiteTest method testSiteWithCalculatedIndicators.
@OnDataSet("/dbunit/sites-calculated-indicators.db.xml")
@Test
public void testSiteWithCalculatedIndicators() throws CommandException {
// create a new detached, client model
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setLocationName("Virunga");
newSite.setProject(new ProjectDTO(1, "SomeProject"));
newSite.setReportingPeriodId(11);
newSite.setIndicatorValue(1, 1);
newSite.setIndicatorValue(2, 2);
// create command
CreateSite cmd = new CreateSite(newSite);
assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
// execute the command
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
// try to retrieve what we've created
SiteDTO firstRead = readSite(newSite.getId());
Assert.assertEquals(1d, firstRead.<Object>getIndicatorValue(1));
Assert.assertEquals(2d, firstRead.<Object>getIndicatorValue(2));
Assert.assertEquals(3d, firstRead.<Object>getIndicatorValue(11));
Assert.assertEquals(0.5d, firstRead.<Object>getIndicatorValue(12));
SiteDTO updateSite = new SiteDTO(newSite);
updateSite.setIndicatorValue(1, null);
updateSite.setIndicatorValue(2, null);
// update site
execute(new UpdateSite(newSite, updateSite));
SiteDTO secondRead = readSite(newSite.getId());
// BACHE
Assert.assertEquals(null, secondRead.getIndicatorValue(1));
// BENE
Assert.assertEquals(null, secondRead.getIndicatorValue(2));
Assert.assertEquals(null, secondRead.getIndicatorValue(11));
Assert.assertEquals(null, secondRead.getIndicatorValue(12));
}
use of org.activityinfo.legacy.shared.command.CreateSite in project activityinfo by bedatadriven.
the class CommandQueueTest method testCreateSite.
@Test
public void testCreateSite() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("anInt", 34);
properties.put("aString", "testing");
properties.put("aDouble", 3.0);
properties.put("aBoolean", true);
properties.put("anotherBoolean", false);
properties.put("aTime", new Date());
properties.put("aDate", new LocalDate(2011, 3, 15));
final CreateSite cmd = new CreateSite(properties);
db.transaction(new SqlTransactionCallback() {
@Override
public void begin(SqlTransaction tx) {
queue.queue(tx, cmd);
}
});
Collector<CommandQueue.QueueEntry> reread = Collector.newCollector();
queue.peek(reread);
assertThat(reread.getResult(), not(nullValue()));
assertThat(cmd, equalTo(reread.getResult().getCommand()));
Collector<Void> deleted = Collector.newCollector();
queue.remove(reread.getResult(), deleted);
Collector<CommandQueue.QueueEntry> entry2 = Collector.newCollector();
queue.peek(entry2);
assertThat(entry2.getResult(), is(nullValue()));
}
use of org.activityinfo.legacy.shared.command.CreateSite in project activityinfo by bedatadriven.
the class SiteDialog method saveNewSite.
private void saveNewSite() {
final SiteDTO newSite = new SiteDTO();
keyGenerator = new KeyGenerator();
newSite.setId(keyGenerator.generateInt());
newSite.setActivityId(activity.getId());
if (activity.getReportingFrequency() == ActivityFormDTO.REPORT_ONCE) {
newSite.setReportingPeriodId(new KeyGenerator().generateInt());
}
updateModel(newSite);
dispatcher.execute(new CreateSite(newSite), new AsyncCallback<CreateResult>() {
@Override
public void onFailure(Throwable caught) {
showError(caught);
}
@Override
public void onSuccess(CreateResult result) {
hide();
callback.onSaved();
}
});
}
Aggregations