Search in sources :

Example 11 with GetSites

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

Example 12 with GetSites

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

the class CalculatedIndicatorsQuery method querySites.

private void querySites() {
    GetSites sitesQuery = new GetSites(composeSiteFilter());
    sitesQuery.setFetchAdminEntities(query.isPivotedBy(DimensionType.AdminLevel));
    sitesQuery.setFetchAttributes(query.isPivotedBy(DimensionType.AttributeGroup));
    sitesQuery.setFetchAllIndicators(true);
    sitesQuery.setFetchLocation(query.isPivotedBy(DimensionType.Location) || query.isPivotedBy(DimensionType.Site));
    sitesQuery.setFetchPartner(query.isPivotedBy(DimensionType.Partner));
    sitesQuery.setFetchComments(false);
    sitesQuery.setFetchDates(query.isPivotedBy(DimensionType.Date));
    sitesQuery.setFetchLinks(false);
    sitesQuery.setFetchAllReportingPeriods(true);
    sitesQuery.setLimit(-1);
    for (Dimension dim : query.getDimensions()) {
        if (dim.getType() != DimensionType.Indicator) {
            dimAccessors.add(createAccessor(dim));
        }
    }
    queryContext.getExecutionContext().execute(sitesQuery, new AsyncCallback<SiteResult>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(SiteResult result) {
            try {
                aggregateSites(result);
                callback.onSuccess(null);
            } catch (Throwable caught) {
                callback.onFailure(caught);
            }
        }
    });
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)

Example 13 with GetSites

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

the class ImportWithMultiClassRangeTest method testSimple.

@Test
public void testSimple() throws IOException {
    setUser(3);
    FormTree formTree = assertResolves(locator.getFormTree(NFI_DISTRIBUTION_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "nfi.csv"), Charsets.UTF_8));
    source.parseAllRows();
    importModel.setSource(source);
    dumpList("COLUMNS", source.getColumns());
    importModel.setColumnAction(columnIndex("Date1"), target("Start Date"));
    importModel.setColumnAction(columnIndex("Date2"), target("End Date"));
    importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
    importModel.setColumnAction(columnIndex("Localité"), target("Localité Name"));
    importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
    importModel.setColumnAction(columnIndex("District"), target("District Name"));
    importModel.setColumnAction(columnIndex("Territoire"), target("Territoire Name"));
    importModel.setColumnAction(columnIndex("Secteur"), target("Secteur Name"));
    importModel.setColumnAction(columnIndex("Groupement"), target("Groupement Name"));
    importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
    importModel.setColumnAction(columnIndex("Nombre de ménages ayant reçu une assistance en NFI"), target("Nombre de ménages ayant reçu une assistance en NFI"));
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    GetSites query = new GetSites(Filter.filter().onActivity(33));
    query.setSortInfo(new SortInfo("date2", Style.SortDir.DESC));
    SiteResult result = execute(query);
    // 651 - 8 = 643 (8 records where start date is before end date)
    assertThat(result.getTotalLength(), equalTo(643));
    // assertThat(result.getTotalLength(), equalTo(313));
    SiteDTO lastSite = result.getData().get(0);
    // assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013,4,26)));
    assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013, 4, 30)));
    assertThat(lastSite.getLocationName(), equalTo("Kilimani Camp"));
    assertThat(lastSite.getAdminEntity(PROVINCE_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(DISTRICT_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(TERRITOIRE_LEVEL).getName(), equalTo("Masisi"));
    assertThat(lastSite.getAdminEntity(SECTEUR_LEVEL).getName(), equalTo("Masisi"));
    assertThat((Double) lastSite.getIndicatorValue(NUMBER_MENAGES), equalTo(348.0));
    assertThat(lastSite.getAttributeValue(ECHO), equalTo(false));
}
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) 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) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 14 with GetSites

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

the class DeleteTest method testDeleteSite.

@Test
public void testDeleteSite() throws CommandException {
    PagingResult<SiteDTO> sites = execute(GetSites.byId(3));
    execute(new Delete(sites.getData().get(0)));
    sites = execute(GetSites.byId(3));
    Assert.assertEquals(0, sites.getData().size());
    sites = execute(new GetSites());
    assertNull(getById(sites.getData(), 3));
}
Also used : Delete(org.activityinfo.legacy.shared.command.Delete) GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Example 15 with GetSites

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

the class TableGenerator method generateData.

public TableData generateData(TableElement element, Filter filter) {
    GetSites query = new GetSites(filter);
    if (!element.getSortBy().isEmpty()) {
        TableColumn sortBy = element.getSortBy().get(0);
        query.setSortInfo(new SortInfo(sortBy.getSitePropertyName(), sortBy.isOrderAscending() ? SortDir.ASC : SortDir.DESC));
    }
    SiteResult sites = getDispatcher().execute(query);
    return new TableData(element.getRootColumn(), sites.getData());
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) TableData(org.activityinfo.legacy.shared.reports.content.TableData) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) SortInfo(com.extjs.gxt.ui.client.data.SortInfo)

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