Search in sources :

Example 1 with SortInfo

use of com.extjs.gxt.ui.client.data.SortInfo in project activityinfo by bedatadriven.

the class SiteExporter method querySites.

private SiteResult querySites(ActivityFormDTO activity, Filter filter, int offset) {
    Filter effectiveFilter = new Filter(filter);
    effectiveFilter.addRestriction(DimensionType.Activity, activity.getId());
    GetSites query = new GetSites();
    query.setFilter(effectiveFilter);
    query.setSortInfo(new SortInfo("date2", SortDir.DESC));
    query.setOffset(offset);
    query.setLimit(SITE_BATCH_SIZE);
    if (activity.getReportingFrequency() == ActivityFormDTO.REPORT_MONTHLY) {
        query.setFetchAllReportingPeriods(true);
        query.setFetchLinks(false);
    }
    SiteResult result = context.execute(query);
    if (result.getTotalLength() > 0) {
        context.updateProgress(Math.min(1.0, (double) offset) / ((double) result.getTotalLength()));
    }
    return result;
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SortInfo(com.extjs.gxt.ui.client.data.SortInfo)

Example 2 with SortInfo

use of com.extjs.gxt.ui.client.data.SortInfo in project activityinfo by bedatadriven.

the class GetSitesTest method testActivityQueryBasic.

@Test
public void testActivityQueryBasic() throws CommandException {
    setUser(DATABASE_OWNER);
    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());
    // try {
    Assert.assertNotNull("admin bounds", s.getAdminEntity(1).getBounds());
    // throw new CommandException("Admin Bounds Location extraction enabled - remove AssertionError catch");
    // } catch (AssertionError err) {
    // Admin Bounds Location extraction disabled until "ST_" functions corrected on QueryEngine
    // Remove try{} catch{} when enabled and I start throwing CommandExceptions
    // }
    Assert.assertThat("indicator", (Double) s.getIndicatorValue(1), equalTo(10000.0));
    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(3));
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 3 with SortInfo

use of com.extjs.gxt.ui.client.data.SortInfo in project activityinfo by bedatadriven.

the class GetSitesTest method testAdminEntitySort.

@Test
@OnDataSet("/dbunit/sites-public.db.xml")
public void testAdminEntitySort() throws CommandException {
    setUser(DATABASE_OWNER);
    // level 1 - DESC
    GetSites cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E1", SortDir.DESC));
    PagingLoadResult<SiteDTO> result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E1"), equalTo("Sud Kivu"));
    assertThat("sorted", adminName(result, 1, "E1"), equalTo("Sud Kivu"));
    assertThat("sorted", adminName(result, 2, "E1"), equalTo("Ituri"));
    // level 1 - ASC
    cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E1", SortDir.ASC));
    result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E1"), equalTo("Ituri"));
    assertThat("sorted", adminName(result, 1, "E1"), equalTo("Sud Kivu"));
    assertThat("sorted", adminName(result, 2, "E1"), equalTo("Sud Kivu"));
    // level 2 - DESC
    cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E2", SortDir.DESC));
    result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E2"), equalTo("Walungu"));
    assertThat("sorted", adminName(result, 1, "E2"), equalTo("Shabunda"));
    assertThat("sorted", adminName(result, 2, "E2"), equalTo("Irumu"));
    // level 2 - ASC
    cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E2", SortDir.ASC));
    result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E2"), equalTo("Irumu"));
    assertThat("sorted", adminName(result, 1, "E2"), equalTo("Shabunda"));
    assertThat("sorted", adminName(result, 2, "E2"), equalTo("Walungu"));
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 4 with SortInfo

use of com.extjs.gxt.ui.client.data.SortInfo in project activityinfo by bedatadriven.

the class GetSitesTest method testIndicatorSort.

@Test
public void testIndicatorSort() throws CommandException {
    setUser(DATABASE_OWNER);
    GetSites cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo(IndicatorDTO.getPropertyName(1), SortDir.DESC));
    PagingLoadResult<SiteDTO> result = execute(cmd);
    // assure sorted
    assertThat("sorted", (Double) result.getData().get(0).getIndicatorValue(1), equalTo(10000.0));
    assertThat("sorted", (Double) result.getData().get(1).getIndicatorValue(1), closeTo(3600.0, 1d));
    assertThat("sorted", (Double) result.getData().get(2).getIndicatorValue(1), closeTo(1500.0, 1d));
    Assert.assertNotNull("activityId", result.getData().get(0).getActivityId());
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 5 with SortInfo

use of com.extjs.gxt.ui.client.data.SortInfo in project activityinfo by bedatadriven.

the class GetSitesTest method testSeekSite.

@Test
@Ignore
public void testSeekSite() throws Exception {
    setUser(DATABASE_OWNER);
    GetSites cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo(IndicatorDTO.getPropertyName(1), SortDir.DESC));
    cmd.setLimit(2);
    cmd.setSeekToSiteId(1);
    PagingLoadResult<SiteDTO> result = execute(cmd);
    Assert.assertEquals("second page returned", 2, result.getOffset());
    Assert.assertEquals("rows on this page", 1, result.getData().size());
    Assert.assertEquals("correct site returned", 1, result.getData().get(0).getId());
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SortInfo (com.extjs.gxt.ui.client.data.SortInfo)11 GetSites (org.activityinfo.legacy.shared.command.GetSites)10 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)9 Test (org.junit.Test)9 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)5 OnDataSet (org.activityinfo.server.database.OnDataSet)4 Ignore (org.junit.Ignore)2 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 TableData (org.activityinfo.legacy.shared.reports.content.TableData)1 TableColumn (org.activityinfo.legacy.shared.reports.model.TableColumn)1 FormTree (org.activityinfo.model.formTree.FormTree)1 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)1 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)1 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)1