Search in sources :

Example 6 with CreateSite

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()));
}
Also used : PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteResult(org.activityinfo.shared.command.result.SiteResult) RemovePartner(org.activityinfo.shared.command.RemovePartner) AddPartner(org.activityinfo.shared.command.AddPartner) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Date(java.util.Date) CreateSite(org.activityinfo.shared.command.CreateSite) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 7 with CreateSite

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);
        }
    });
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) CreateSite(org.activityinfo.shared.command.CreateSite)

Example 8 with CreateSite

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());
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.shared.dto.SiteDTO) CreateSite(org.activityinfo.shared.command.CreateSite) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with CreateSite

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);
}
Also used : PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) SiteDTO(org.activityinfo.shared.dto.SiteDTO) CreateSite(org.activityinfo.shared.command.CreateSite) Test(org.junit.Test)

Example 10 with CreateSite

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);
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) LocationDTO(org.activityinfo.shared.dto.LocationDTO) CreateSite(org.activityinfo.shared.command.CreateSite) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

CreateSite (org.activityinfo.shared.command.CreateSite)10 SiteDTO (org.activityinfo.shared.dto.SiteDTO)9 CreateResult (org.activityinfo.shared.command.result.CreateResult)7 Test (org.junit.Test)7 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)4 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)4 CreateLocation (org.activityinfo.shared.command.CreateLocation)3 LocationDTO (org.activityinfo.shared.dto.LocationDTO)3 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 SiteResult (org.activityinfo.shared.command.result.SiteResult)2 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 HashMap (java.util.HashMap)1 ColumnBinding (org.activityinfo.client.importer.column.ColumnBinding)1 FormAttributeGroup (org.activityinfo.server.endpoint.odk.SiteFormData.FormAttributeGroup)1 FormIndicator (org.activityinfo.server.endpoint.odk.SiteFormData.FormIndicator)1