use of org.activityinfo.shared.command.CreateSite in project activityinfo by bedatadriven.
the class LocalSiteCreateTest method siteRemovePartnerConflict.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void siteRemovePartnerConflict() {
// FIRST U1 adds a new partner
int databaseId = 1;
PartnerDTO iom = new PartnerDTO();
iom.setName("IOM");
CreateResult result = executeRemotely(new AddPartner(databaseId, iom));
iom.setId(result.getNewId());
// Now U2 synchronizes, and adds a new site with this partner
synchronizeFirstTime();
SiteDTO site = new SiteDTO();
site.setId(3343234);
site.setActivityId(1);
site.setPartner(iom);
site.setDate1(new Date());
site.setDate2(new Date());
site.setLocationId(1);
executeLocally(new CreateSite(site));
// At T+3, U2 thinks better, removes IOM
executeRemotely(new RemovePartner(databaseId, iom.getId()));
// At T+4, U1 synchronizes, and IOM is removed, but site remains
synchronize();
// Verify that there is still a label for this partner
SiteResult sites = executeLocally(GetSites.byId(site.getId()));
assertThat(sites.getTotalLength(), equalTo(1));
assertThat(sites.getData().get(0).getName(), equalTo(site.getName()));
}
use of org.activityinfo.shared.command.CreateSite in project activityinfo by bedatadriven.
the class SiteDialog method saveNewSite.
private void saveNewSite() {
final SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(activity.getId());
if (activity.getReportingFrequency() == ActivityDTO.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(newSite);
}
});
}
use of org.activityinfo.shared.command.CreateSite in project activityinfo by bedatadriven.
the class CreateSiteTest method testAdminBoundCreate.
@Test
@Ignore("WIP")
public void testAdminBoundCreate() throws CommandException {
// create a new detached, client model
SiteDTO newSite = new SiteDTO();
newSite.setActivityId(4);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setAdminEntity(1, new AdminEntityDTO(1, 2, "Sud Kivu"));
newSite.setAdminEntity(2, new AdminEntityDTO(2, 11, "Walungu"));
newSite.setAdminEntity(3, null);
newSite.setX(27.432);
newSite.setY(1.23);
newSite.setComments("huba huba");
newSite.setProject(new ProjectDTO(1, "SomeProject"));
// create command
CreateSite cmd = new CreateSite(newSite);
// execute the command
setUser(1);
newSite.setProject(new ProjectDTO(1, "SomeProject"));
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
// try to retrieve what we've created
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
// confirm that the changes are there
Assert.assertEquals("site.location.name", "Walungu", secondRead.getLocationName());
}
use of org.activityinfo.shared.command.CreateSite in project activityinfo by bedatadriven.
the class CreateSiteTest method unauthorized.
@Test(expected = NotAuthorizedException.class)
public void unauthorized() throws CommandException {
// create a new detached, client model
SiteDTO newSite = SiteDTOs.newSite();
newSite.setPartner(new PartnerDTO(2, "Not NRC"));
// create command
CreateSite cmd = new CreateSite(newSite);
// execute the command
// bavon (only has access to his own partners in database 1)
setUser(2);
execute(cmd);
}
use of org.activityinfo.shared.command.CreateSite in project activityinfo by bedatadriven.
the class LocalSiteCreateTest method createNew.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void createNew() throws CommandException {
synchronizeFirstTime();
// create a new detached, client model
SiteDTO newSite = SiteDTOs.newSite();
LocationDTO location = LocationDTOs.newLocation();
executeLocally(new CreateLocation(location));
newSite.setLocation(location);
// create command
CreateSite cmd = new CreateSite(newSite);
// execute the command
CreateResult result = executeLocally(cmd);
// let the client know the command has succeeded
newSite.setId(result.getNewId());
// try to retrieve what we've created FROM OUR CLIENT SIDE DATABASE
SiteResult loadResult = executeLocally(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
// confirm that the changes are there
SiteDTOs.validateNewSite(secondRead);
newRequest();
// now Sync with the server
synchronize();
// Confirm that paging works client side
GetSites pagingRequest = new GetSites();
pagingRequest.setLimit(1);
loadResult = executeLocally(pagingRequest);
}
Aggregations