Search in sources :

Example 11 with SiteResult

use of org.activityinfo.shared.command.result.SiteResult 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.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) TableData(org.activityinfo.shared.report.content.TableData) TableColumn(org.activityinfo.shared.report.model.TableColumn) SortInfo(com.extjs.gxt.ui.client.data.SortInfo)

Example 12 with SiteResult

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

the class GetSitesHandler 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 = unionedQuery(context, command);
    unioned.appendAllColumns();
    if (isMySql()) {
        // 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 SiteResult result = new SiteResult(sites);
    result.setOffset(command.getOffset());
    Log.trace("About to execute primary query");
    unioned.execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            if (command.getLimit() <= 0) {
                result.setTotalLength(results.getRows().size());
            } else {
                queryTotalLength(tx, command, context, result);
            }
            Log.trace("Primary query returned, starting to add to map");
            for (SqlResultSetRow row : results.getRows()) {
                SiteDTO site = toSite(row);
                sites.add(site);
                siteMap.put(site.getId(), site);
            }
            Log.trace("Finished adding to map");
            if (!sites.isEmpty()) {
                if (command.isFetchAdminEntities()) {
                    joinEntities(tx, siteMap);
                }
                if (command.fetchAnyIndicators()) {
                    joinIndicatorValues(command, tx, siteMap);
                }
                if (command.isFetchAttributes()) {
                    joinAttributeValues(tx, siteMap);
                }
            }
            callback.onSuccess(result);
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) SiteResult(org.activityinfo.shared.command.result.SiteResult) ArrayList(java.util.ArrayList) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) SiteDTO(org.activityinfo.shared.dto.SiteDTO) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow)

Example 13 with SiteResult

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

the class ProjectTest method deleteProject.

@Test
public void deleteProject() {
    setUser(1);
    long originalDatabaseVersion = lookupDbVersion(1);
    int projectId = 2;
    execute(RequestChange.delete("Project", projectId));
    SchemaDTO schema = execute(new GetSchema());
    assertThat(schema.getProjectById(projectId), nullValue());
    // make sure it's gone from sites
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Site, 3);
    SiteResult sites = execute(new GetSites(filter));
    assertThat(sites.getData().get(0).getProject(), is(nullValue()));
    // and doesn't show up in pivoting...
    PivotSites pivot = new PivotSites();
    Dimension projectDimension = new Dimension(DimensionType.Project);
    pivot.setDimensions(projectDimension);
    pivot.setFilter(filter);
    PivotResult buckets = execute(pivot);
    assertThat(buckets.getBuckets().size(), equalTo(1));
    assertThat(buckets.getBuckets().get(0).getCategory(projectDimension), is(nullValue()));
    // make sure the version number of the database is updated
    assertThat(lookupDbVersion(1), not(equalTo(originalDatabaseVersion)));
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) Filter(org.activityinfo.shared.command.Filter) SiteResult(org.activityinfo.shared.command.result.SiteResult) PivotResult(org.activityinfo.shared.command.PivotSites.PivotResult) GetSites(org.activityinfo.shared.command.GetSites) Dimension(org.activityinfo.shared.report.model.Dimension) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 14 with SiteResult

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

the class UpdateSiteTest method testUpdatePreservesAdminMemberships.

@Test
public void testUpdatePreservesAdminMemberships() throws CommandException {
    Map<String, Object> changes = Maps.newHashMap();
    changes.put("comments", "new comments");
    execute(new UpdateSite(1, changes));
    // retrieve the old one
    SiteResult result = execute(GetSites.byId(1));
    SiteDTO secondRead = result.getData().get(0);
    assertThat(secondRead.getAdminEntity(1).getId(), equalTo(2));
    assertThat(secondRead.getAdminEntity(2).getId(), equalTo(12));
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) UpdateSite(org.activityinfo.shared.command.UpdateSite) Test(org.junit.Test)

Example 15 with SiteResult

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

Aggregations

SiteResult (org.activityinfo.shared.command.result.SiteResult)19 Test (org.junit.Test)12 SiteDTO (org.activityinfo.shared.dto.SiteDTO)11 GetSites (org.activityinfo.shared.command.GetSites)10 OnDataSet (org.activityinfo.server.database.OnDataSet)6 Date (java.util.Date)4 Filter (org.activityinfo.shared.command.Filter)4 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 User (org.activityinfo.server.database.hibernate.entity.User)2 CreateSite (org.activityinfo.shared.command.CreateSite)2 GetSchema (org.activityinfo.shared.command.GetSchema)2 UpdateSite (org.activityinfo.shared.command.UpdateSite)2 CreateResult (org.activityinfo.shared.command.result.CreateResult)2 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)2 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)2 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)2 TableColumn (org.activityinfo.shared.report.model.TableColumn)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1