Search in sources :

Example 21 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class GetSitesTest method testGetPublicSites.

@Test
@OnDataSet("/dbunit/sites-public.db.xml")
public void testGetPublicSites() throws CommandException {
    int anonnoymsUserID = 0;
    setUser(anonnoymsUserID);
    GetSites cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("date2", SortDir.DESC));
    PagingLoadResult<SiteDTO> result = execute(cmd);
    Assert.assertEquals("totalLength", 3, result.getData().size());
    Assert.assertEquals("totalLength", 3, result.getTotalLength());
    Assert.assertEquals("offset", 0, result.getOffset());
    // Assert.assertNull("row(0).activity",
    // result.getData().get(0).getActivity());
    // assure sorted
    Assert.assertEquals("sorted", 2, result.getData().get(0).getId());
    Assert.assertEquals("sorted", 1, result.getData().get(1).getId());
    Assert.assertEquals("sorted", 3, result.getData().get(2).getId());
    // assure indicators are present (site id=3)
    SiteDTO s = result.getData().get(2);
    Assert.assertEquals("entityName", "Ituri", s.getAdminEntity(1).getName());
    Assert.assertNotNull("admin bounds", s.getAdminEntity(1).getBounds());
    Assert.assertEquals("indicator", 10000.0, s.getIndicatorValue(1));
    Assert.assertNull("site x", s.getX());
    // assure project is present
    SiteDTO s1 = result.getData().get(1);
    assertThat(s1.getId(), equalTo(1));
    assertThat(s1.getProject().getId(), equalTo(1));
}
Also used : GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 22 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class GetSitesTest method testAll.

@Test
public void testAll() throws CommandException {
    setUser(DATABASE_OWNER);
    GetSites cmd = new GetSites();
    PagingLoadResult<SiteDTO> result = execute(cmd);
    Assert.assertEquals("rows", 8, result.getData().size());
    Assert.assertNotNull("activityId", result.getData().get(0).getActivityId());
}
Also used : GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Test(org.junit.Test)

Example 23 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class GetSitesTest method testActivityQueryPaged.

@Test
public void testActivityQueryPaged() throws CommandException {
    setUser(DATABASE_OWNER);
    GetSites cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo(IndicatorDTO.getPropertyName(1), SortDir.DESC));
    cmd.setLimit(2);
    cmd.setOffset(0);
    PagingLoadResult<SiteDTO> result = execute(cmd);
    assertThat("offset", result.getOffset(), equalTo(0));
    cmd.setOffset(1);
    cmd.setLimit(2);
    result = execute(cmd);
    assertThat(result.getOffset(), equalTo(1));
    assertThat(result.getData().size(), equalTo(2));
    assertThat("total length", result.getTotalLength(), equalTo(3));
    cmd.setOffset(0);
    cmd.setLimit(50);
    result = execute(cmd);
    assertThat(result.getOffset(), equalTo(0));
    assertThat(result.getData().size(), equalTo(3));
    assertThat("total length", result.getTotalLength(), equalTo(3));
}
Also used : GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 24 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class GetSitesTest method linkedSitesFilteredByIndicator.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void linkedSitesFilteredByIndicator() {
    setUser(1);
    GetSites cmd = new GetSites();
    cmd.filter().addRestriction(DimensionType.Indicator, 1);
    cmd.setSortInfo(new SortInfo("locationName", SortDir.ASC));
    SiteResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(2));
    SiteDTO site1 = result.getData().get(0);
    SiteDTO site2 = result.getData().get(1);
    System.out.println(site1.getProperties());
    System.out.println(site2.getProperties());
    assertThat(site1.getId(), equalTo(1));
    assertThat(site1.getLocationName(), equalTo("Penekusu Kivu"));
    assertThat(site1.getActivityId(), equalTo(1));
    assertThat(site1.getIndicatorValue(1), equalTo(1500d));
    assertThat(site2.getId(), equalTo(2));
    assertThat(site2.getLocationName(), equalTo("Penekusu Kivu 2"));
    assertThat(site2.getActivityId(), equalTo(1));
    assertThat(site2.getIndicatorValue(1), equalTo(400d));
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 25 with GetSites

use of org.activityinfo.shared.command.GetSites in project activityinfo by bedatadriven.

the class GetSitesTest method testDatabase.

@Test
public void testDatabase() throws CommandException {
    setUser(DATABASE_OWNER);
    GetSites cmd = new GetSites();
    cmd.filter().addRestriction(DimensionType.Database, 2);
    PagingLoadResult<SiteDTO> result = execute(cmd);
    Assert.assertEquals("rows", 3, result.getData().size());
    Assert.assertNotNull("activityId", result.getData().get(0).getActivityId());
}
Also used : GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Test(org.junit.Test)

Aggregations

GetSites (org.activityinfo.shared.command.GetSites)28 Test (org.junit.Test)18 SiteDTO (org.activityinfo.shared.dto.SiteDTO)16 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)10 SiteResult (org.activityinfo.shared.command.result.SiteResult)10 Filter (org.activityinfo.shared.command.Filter)8 OnDataSet (org.activityinfo.server.database.OnDataSet)5 StringWriter (java.io.StringWriter)2 GET (javax.ws.rs.GET)2 JsonGenerator (org.codehaus.jackson.JsonGenerator)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 CreateLocation (org.activityinfo.shared.command.CreateLocation)1 CreateSite (org.activityinfo.shared.command.CreateSite)1 Delete (org.activityinfo.shared.command.Delete)1 GenerateElement (org.activityinfo.shared.command.GenerateElement)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 PivotSites (org.activityinfo.shared.command.PivotSites)1