Search in sources :

Example 1 with GetSites

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

the class KmlDataServlet method querySites.

private List<SiteDTO> querySites(int activityId) {
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Activity, activityId);
    return dispatcher.execute(new GetSites(filter)).getData();
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) GetSites(org.activityinfo.legacy.shared.command.GetSites)

Example 2 with GetSites

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

the class PointLayerGenerator method queryFor.

private GetSites queryFor(Filter effectiveFilter, PointMapLayer layer) {
    Filter layerFilter = new Filter(effectiveFilter, layer.getFilter());
    boolean allMonthly = true;
    for (int id : layer.getIndicatorIds()) {
        Indicator indicator = indicators.get(id);
        if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_SITE_COUNT) {
            layerFilter.addRestriction(DimensionType.Activity, indicator.getActivity().getId());
        } else {
            layerFilter.addRestriction(DimensionType.Indicator, indicator.getId());
        }
        if (allMonthly) {
            allMonthly = indicator.getActivity().getReportingFrequency() == ActivityFormDTO.REPORT_MONTHLY;
        }
    }
    layerFilter.addRestriction(DimensionType.Indicator, physicalIndicators(layer));
    GetSites query = new GetSites();
    query.setFilter(layerFilter);
    query.setFetchAttributes(false);
    query.setFetchAdminEntities(true);
    query.setFetchAllIndicators(false);
    query.setFetchIndicators(physicalIndicators(layer));
    if (allMonthly) {
        query.setFetchAllReportingPeriods(true);
        query.setFetchLinks(false);
    }
    return query;
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) GetSites(org.activityinfo.legacy.shared.command.GetSites) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator)

Example 3 with GetSites

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

the class ImportSimpleTest method test.

@Test
public void test() throws IOException {
    FormTree formTree = assertResolves(locator.getFormTree(HOUSEHOLD_SURVEY_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
    source.parseAllRows();
    assertThat(source.getRows().size(), equalTo(63));
    importModel.setSource(source);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    dumpList("COLUMNS", source.getColumns());
    // Step 2: User maps imported columns to FormFields
    dumpList("FIELDS", importer.getImportTargets());
    importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultMale"));
    importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultFemale"));
    importModel.setColumnAction(columnIndex("_CREATION_DATE"), target("Start Date"));
    importModel.setColumnAction(columnIndex("_SUBMISSION_DATE"), target("End Date"));
    importModel.setColumnAction(columnIndex("district name"), target("District Name"));
    importModel.setColumnAction(columnIndex("upazila"), target("Upzilla Name"));
    importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
    // Step 3: Validate for user
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    // VERIFY total count
    SiteResult allResults = execute(new GetSites(Filter.filter().onActivity(1)));
    assertThat(allResults.getData().size(), equalTo(63));
    // AND... verify
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.AdminLevel, MODHUPUR);
    SiteResult sites = execute(new GetSites(filter));
    assertThat(sites.getTotalLength(), equalTo(1));
    SiteDTO site = sites.getData().get(0);
    assertThat(site.getDate1(), equalTo(new LocalDate(2012, 12, 19)));
    assertThat(site.getDate2(), equalTo(new LocalDate(2012, 12, 19)));
    assertThat(site.getAdminEntity(3), not(nullValue()));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) Filter(org.activityinfo.legacy.shared.command.Filter) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) Test(org.junit.Test)

Example 4 with GetSites

use of org.activityinfo.legacy.shared.command.GetSites 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 5 with GetSites

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

the class GetSitesTest method duplicated.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void duplicated() {
    // A given site can be appear multiple times in the list if it is the
    // source
    // of one or more indicators
    setUser(1);
    GetSites cmd = new GetSites();
    SiteResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(3));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

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