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());
}
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);
}
});
}
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)));
}
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));
}
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));
}
Aggregations