Search in sources :

Example 21 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class DeleteTest method testDeleteIndicator.

@Test
public void testDeleteIndicator() throws CommandException {
    SchemaDTO schema = execute(new GetSchema());
    execute(new Delete(schema.getIndicatorById(1)));
    schema = execute(new GetSchema());
    Assert.assertNull(schema.getIndicatorById(1));
    PagingResult<SiteDTO> sites = execute(GetSites.byId(1));
    Assert.assertNull(sites.getData().get(0).getIndicatorValue(1));
}
Also used : Delete(org.activityinfo.shared.command.Delete) SiteDTO(org.activityinfo.shared.dto.SiteDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 22 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class SiteRendererTest method multipleGroupsRender.

@Test
public void multipleGroupsRender() {
    IndicatorDTO indicator1 = new IndicatorDTO();
    indicator1.setId(1);
    indicator1.setAggregation(IndicatorDTO.AGGREGATE_SUM);
    indicator1.setName("First indicator");
    indicator1.setCategory("First group");
    IndicatorDTO indicator2 = new IndicatorDTO();
    indicator2.setAggregation(IndicatorDTO.AGGREGATE_SUM);
    indicator2.setId(2);
    indicator2.setName("Second indicator");
    indicator2.setCategory("Second group");
    ActivityDTO activity = new ActivityDTO();
    activity.setId(1);
    activity.getIndicators().add(indicator1);
    activity.getIndicators().add(indicator2);
    SiteDTO site = new SiteDTO();
    site.setIndicatorValue(1, 1000d);
    site.setIndicatorValue(2, 2000d);
    String html = siteRenderer.renderSite(site, activity, false, true);
    assertTrue(html.contains(indicator1.getName()));
    assertTrue(html.contains(indicator2.getName()));
}
Also used : IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) SiteDTO(org.activityinfo.shared.dto.SiteDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) Test(org.junit.Test)

Example 23 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO 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)));
    PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
    Assert.assertEquals(1, loadResult.getData().size());
    SiteDTO secondRead = loadResult.getData().get(0);
    SiteDTOs.validateNewSite(secondRead);
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) LocationDTO(org.activityinfo.shared.dto.LocationDTO) CreateSite(org.activityinfo.shared.command.CreateSite) Test(org.junit.Test)

Example 24 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO 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());
    // cmd.onCompleted(result);
    // 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.attribute[2]", false, secondRead.getAttributeValue(1));
    Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(2));
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) CreateResult(org.activityinfo.shared.command.result.CreateResult) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) CreateSite(org.activityinfo.shared.command.CreateSite) Test(org.junit.Test)

Example 25 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class SyncIntegrationTest method run.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void run() throws SQLException, InterruptedException {
    synchronizeFirstTime();
    Collector<Date> lastUpdate = Collector.newCollector();
    syncHistoryTable.get(lastUpdate);
    assertThat(lastUpdate.getResult(), is(not(nullValue())));
    assertThat(queryString("select Name from Indicator where IndicatorId=103"), equalTo("Nb. of distributions"));
    assertThat(queryString("select Name from AdminLevel where AdminLevelId=1"), equalTo("Province"));
    assertThat(queryString("select Name from AdminEntity where AdminEntityId=21"), equalTo("Irumu"));
    assertThat(queryString("select Name from Location where LocationId=7"), equalTo("Shabunda"));
    assertThat(queryInt("select value from IndicatorValue where ReportingPeriodId=601 and IndicatorId=6"), equalTo(35));
    assertThat(queryInt("select PartnerId from partnerInDatabase where databaseid=2"), equalTo(1));
    assertThat(queryInt("select AttributeGroupId  from AttributeGroupInActivity where ActivityId=2"), equalTo(1));
    assertThat(queryInt("select count(*) from LockedPeriod"), equalTo(4));
    assertThat(queryInt("select count(*) from LockedPeriod where ProjectId is not null"), equalTo(1));
    assertThat(queryInt("select count(*) from LockedPeriod where ActivityId is not null"), equalTo(1));
    assertThat(queryInt("select count(*) from LockedPeriod where UserDatabaseId is not null"), equalTo(2));
    // / now try updating a site remotely (from another client)
    // and veryify that we get the update after we synchronized
    Thread.sleep(1000);
    SiteDTO s1 = executeLocally(GetSites.byId(1)).getData().get(0);
    assertThat(s1.getIndicatorValue(1), equalTo(1500d));
    Map<String, Object> changes = Maps.newHashMap();
    changes.put(AttributeDTO.getPropertyName(1), true);
    changes.put("comments", "newComments");
    executeRemotely(new UpdateSite(1, changes));
    synchronize();
    s1 = executeLocally(GetSites.byId(1)).getData().get(0);
    assertThat(s1.getAttributeValue(1), equalTo(true));
    assertThat(s1.getAttributeValue(2), equalTo(false));
    assertThat(s1.getComments(), equalTo("newComments"));
    // old values are preserved...
    assertThat(s1.getIndicatorValue(1), equalTo(1500d));
    // Try deleting a site
    executeRemotely(new Delete("Site", 1));
    synchronize();
    SiteResult siteResult = executeLocally(GetSites.byId(1));
    assertThat(siteResult.getData().size(), equalTo(0));
    // Verify that we haven't toasted the other data
    SiteDTO site = executeLocally(GetSites.byId(3)).getData().get(0);
    assertThat(site.getIndicatorValue(1), equalTo(10000d));
}
Also used : Delete(org.activityinfo.shared.command.Delete) SiteResult(org.activityinfo.shared.command.result.SiteResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) UpdateSite(org.activityinfo.shared.command.UpdateSite) Date(java.util.Date) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

SiteDTO (org.activityinfo.shared.dto.SiteDTO)71 Test (org.junit.Test)32 GetSites (org.activityinfo.shared.command.GetSites)16 SiteResult (org.activityinfo.shared.command.result.SiteResult)11 CreateSite (org.activityinfo.shared.command.CreateSite)9 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)8 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)7 ArrayList (java.util.ArrayList)7 CreateResult (org.activityinfo.shared.command.result.CreateResult)7 Date (java.util.Date)6 OnDataSet (org.activityinfo.server.database.OnDataSet)6 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)6 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)6 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)5 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)5 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)5 UpdateSite (org.activityinfo.shared.command.UpdateSite)5 LocationDTO (org.activityinfo.shared.dto.LocationDTO)5 PointValue (org.activityinfo.shared.report.model.PointValue)5 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)4