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