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