Search in sources :

Example 6 with SiteResult

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

the class GetSitesTest method filterByIndicator.

@Test
public void filterByIndicator() throws CommandException {
    setUser(1);
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, 5);
    SiteResult result = execute(new GetSites(filter));
    assertThat(result.getData().size(), equalTo(1));
    assertThat(result.getData().get(0).getId(), equalTo(9));
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) Test(org.junit.Test)

Example 7 with SiteResult

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

the class GetSitesTest method filterOnPartner.

@Test
public void filterOnPartner() {
    setUser(1);
    GetSites cmd = new GetSites();
    cmd.filter().addRestriction(DimensionType.Project, 2);
    SiteResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(1));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) Test(org.junit.Test)

Example 8 with SiteResult

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

the class LocalSiteCreateTest method siteRemovePartnerConflict.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void siteRemovePartnerConflict() {
    // FIRST U1 adds a new partner
    int databaseId = 1;
    PartnerDTO iom = new PartnerDTO();
    iom.setName("IOM");
    CreateResult result = executeRemotely(new UpdatePartner(databaseId, iom));
    iom.setId(result.getNewId());
    // Now U2 synchronizes, and adds a new site with this partner
    synchronize();
    SiteDTO site = new SiteDTO();
    site.setId(3343234);
    site.setActivityId(1);
    site.setPartner(iom);
    site.setDate1(new Date());
    site.setDate2(new Date());
    site.setLocationId(1);
    executeLocally(new CreateSite(site));
    // At T+3, U2 thinks better, removes IOM
    executeRemotely(new RemovePartner(databaseId, iom.getId()));
    // At T+4, U1 synchronizes, and IOM is removed, but site remains
    synchronize();
    // Verify that there is still a label for this partner
    SiteResult sites = executeLocally(GetSites.byId(site.getId()));
    assertThat(sites.getTotalLength(), equalTo(1));
    assertThat(sites.getData().get(0).getName(), equalTo(site.getName()));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Date(java.util.Date) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 9 with SiteResult

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

the class SiteExporterTest method sheetNameTest.

@Test
public void sheetNameTest() {
    LocaleProxy.initialize();
    CountryDTO somalia = new CountryDTO(1, "Somalia");
    LocationTypeDTO locationType = new LocationTypeDTO(1, "Village");
    locationType.setAdminLevels(somalia.getAdminLevels());
    somalia.getLocationTypes().add(locationType);
    UserDatabaseDTO syli = new UserDatabaseDTO();
    syli.setId(444);
    syli.setName("SYLI");
    syli.setCountry(somalia);
    ActivityFormDTO activity = new ActivityFormDTO();
    activity.setId(1);
    activity.setDatabase(syli);
    activity.setName("Construction/Rehabilitation of Sec. Schools");
    activity.setLocationType(locationType);
    ActivityFormDTO activity2 = new ActivityFormDTO();
    activity2.setId(2);
    activity2.setDatabase(syli);
    activity2.setName("Construction/Rehabilitation of Primary Schools");
    activity2.setLocationType(locationType);
    ActivityFormDTO activity3 = new ActivityFormDTO();
    activity3.setId(3);
    activity3.setDatabase(syli);
    activity3.setName("Construction Rehabil (2)");
    activity3.setLocationType(locationType);
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(new ArrayList<SiteDTO>())).anyTimes();
    replay(dispatcher);
    Filter filter = new Filter();
    SiteExporter exporter = new SiteExporter(new TaskContext(dispatcher, new NullStorageProvider(), "XYZ"));
    exporter.export(activity, filter);
    exporter.export(activity2, filter);
    exporter.export(activity3, filter);
    HSSFWorkbook book = exporter.getBook();
    assertThat(book.getSheetAt(0).getSheetName(), equalTo("Construction Rehabilitation of "));
    assertThat(book.getSheetAt(1).getSheetName(), equalTo("Construction Rehabilitation"));
    assertThat(book.getSheetAt(2).getSheetName(), equalTo("Construction Rehabil 2"));
}
Also used : HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) NullStorageProvider(org.activityinfo.server.report.NullStorageProvider) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) Filter(org.activityinfo.legacy.shared.command.Filter) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 10 with SiteResult

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

the class OldGetSitesHandler method doQuery.

private void doQuery(final GetSites command, final ExecutionContext context, final AsyncCallback<SiteResult> callback) {
    // in order to pull in the linked queries, we want to
    // to create two queries that we union together.
    // for performance reasons, we want to apply all of the joins
    // and filters on both parts of the union query
    SqlQuery unioned;
    if (command.isFetchLinks()) {
        unioned = unionedQuery(context, command);
        unioned.appendAllColumns();
    } else {
        unioned = primaryQuery(context, command);
    }
    if (isMySql() && command.getLimit() >= 0) {
        // with this feature, MySQL will keep track of the total
        // number of rows regardless of our limit statement.
        // This way we don't have to execute the query twice to
        // get the total count
        // 
        // unfortunately, this is not available on sqlite
        unioned.appendKeyword("SQL_CALC_FOUND_ROWS");
    }
    applySort(unioned, command.getSortInfo());
    applyPaging(unioned, command);
    final Multimap<Integer, SiteDTO> siteMap = HashMultimap.create();
    final List<SiteDTO> sites = new ArrayList<SiteDTO>();
    final Map<Integer, SiteDTO> reportingPeriods = Maps.newHashMap();
    final SiteResult result = new SiteResult(sites);
    result.setOffset(command.getOffset());
    Log.trace("About to execute primary query: " + unioned.sql());
    unioned.execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            Log.trace("Primary query returned " + results.getRows().size() + ", rows, starting to add to map");
            for (SqlResultSetRow row : results.getRows()) {
                SiteDTO site = toSite(command, row);
                sites.add(site);
                siteMap.put(site.getId(), site);
                if (command.isFetchAllReportingPeriods()) {
                    reportingPeriods.put(row.getInt("PeriodId"), site);
                }
            }
            Log.trace("Finished adding to map");
            List<Promise<Void>> queries = Lists.newArrayList();
            if (command.getLimit() <= 0) {
                result.setTotalLength(results.getRows().size());
            } else {
                queries.add(queryTotalLength(tx, command, context, result));
            }
            if (!sites.isEmpty()) {
                if (command.isFetchAdminEntities()) {
                    queries.add(joinEntities(tx, siteMap));
                }
                if (command.isFetchAttributes()) {
                    queries.add(joinAttributeValues(command, tx, siteMap));
                }
                if (command.fetchAnyIndicators()) {
                    queries.add(joinIndicatorValues(command, tx, siteMap, reportingPeriods));
                }
            }
            Promise.waitAll(queries).then(Functions.constant(result)).then(callback);
        }
    });
}
Also used : SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback)

Aggregations

SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)24 Test (org.junit.Test)14 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)12 GetSites (org.activityinfo.legacy.shared.command.GetSites)9 OnDataSet (org.activityinfo.server.database.OnDataSet)6 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)5 Date (java.util.Date)4 Filter (org.activityinfo.legacy.shared.command.Filter)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)2 TableColumn (org.activityinfo.legacy.shared.reports.model.TableColumn)2 FormTree (org.activityinfo.model.formTree.FormTree)2 SiteHistory (org.activityinfo.server.database.hibernate.entity.SiteHistory)2 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1