use of org.activityinfo.legacy.shared.command.GetSites in project activityinfo by bedatadriven.
the class KmlDataServlet method querySites.
private List<SiteDTO> querySites(int activityId) {
Filter filter = new Filter();
filter.addRestriction(DimensionType.Activity, activityId);
return dispatcher.execute(new GetSites(filter)).getData();
}
use of org.activityinfo.legacy.shared.command.GetSites in project activityinfo by bedatadriven.
the class PointLayerGenerator method queryFor.
private GetSites queryFor(Filter effectiveFilter, PointMapLayer layer) {
Filter layerFilter = new Filter(effectiveFilter, layer.getFilter());
boolean allMonthly = true;
for (int id : layer.getIndicatorIds()) {
Indicator indicator = indicators.get(id);
if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_SITE_COUNT) {
layerFilter.addRestriction(DimensionType.Activity, indicator.getActivity().getId());
} else {
layerFilter.addRestriction(DimensionType.Indicator, indicator.getId());
}
if (allMonthly) {
allMonthly = indicator.getActivity().getReportingFrequency() == ActivityFormDTO.REPORT_MONTHLY;
}
}
layerFilter.addRestriction(DimensionType.Indicator, physicalIndicators(layer));
GetSites query = new GetSites();
query.setFilter(layerFilter);
query.setFetchAttributes(false);
query.setFetchAdminEntities(true);
query.setFetchAllIndicators(false);
query.setFetchIndicators(physicalIndicators(layer));
if (allMonthly) {
query.setFetchAllReportingPeriods(true);
query.setFetchLinks(false);
}
return query;
}
use of org.activityinfo.legacy.shared.command.GetSites in project activityinfo by bedatadriven.
the class ImportSimpleTest method test.
@Test
public void test() throws IOException {
FormTree formTree = assertResolves(locator.getFormTree(HOUSEHOLD_SURVEY_FORM_CLASS));
FormTreePrettyPrinter.print(formTree);
importModel = new ImportModel(formTree);
// Step 1: User pastes in data to import
PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
source.parseAllRows();
assertThat(source.getRows().size(), equalTo(63));
importModel.setSource(source);
importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
dumpList("COLUMNS", source.getColumns());
// Step 2: User maps imported columns to FormFields
dumpList("FIELDS", importer.getImportTargets());
importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultMale"));
importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultFemale"));
importModel.setColumnAction(columnIndex("_CREATION_DATE"), target("Start Date"));
importModel.setColumnAction(columnIndex("_SUBMISSION_DATE"), target("End Date"));
importModel.setColumnAction(columnIndex("district name"), target("District Name"));
importModel.setColumnAction(columnIndex("upazila"), target("Upzilla Name"));
importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
// Step 3: Validate for user
ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
showValidationGrid(validatedResult);
assertResolves(importer.persist(importModel));
// VERIFY total count
SiteResult allResults = execute(new GetSites(Filter.filter().onActivity(1)));
assertThat(allResults.getData().size(), equalTo(63));
// AND... verify
Filter filter = new Filter();
filter.addRestriction(DimensionType.AdminLevel, MODHUPUR);
SiteResult sites = execute(new GetSites(filter));
assertThat(sites.getTotalLength(), equalTo(1));
SiteDTO site = sites.getData().get(0);
assertThat(site.getDate1(), equalTo(new LocalDate(2012, 12, 19)));
assertThat(site.getDate2(), equalTo(new LocalDate(2012, 12, 19)));
assertThat(site.getAdminEntity(3), not(nullValue()));
}
use of org.activityinfo.legacy.shared.command.GetSites in project activityinfo by bedatadriven.
the class GetSitesTest method testActivityQueryBasic.
@Test
public void testActivityQueryBasic() throws CommandException {
setUser(DATABASE_OWNER);
GetSites cmd = new GetSites();
cmd.filter().onActivity(1);
cmd.setSortInfo(new SortInfo("date2", SortDir.DESC));
PagingLoadResult<SiteDTO> result = execute(cmd);
Assert.assertEquals("totalLength", 3, result.getData().size());
Assert.assertEquals("totalLength", 3, result.getTotalLength());
Assert.assertEquals("offset", 0, result.getOffset());
// Assert.assertNull("row(0).activity",
// result.getData().get(0).getActivity());
// assure sorted
Assert.assertEquals("sorted", 2, result.getData().get(0).getId());
Assert.assertEquals("sorted", 1, result.getData().get(1).getId());
Assert.assertEquals("sorted", 3, result.getData().get(2).getId());
// assure indicators are present (site id=3)
SiteDTO s = result.getData().get(2);
Assert.assertEquals("entityName", "Ituri", s.getAdminEntity(1).getName());
// try {
Assert.assertNotNull("admin bounds", s.getAdminEntity(1).getBounds());
// throw new CommandException("Admin Bounds Location extraction enabled - remove AssertionError catch");
// } catch (AssertionError err) {
// Admin Bounds Location extraction disabled until "ST_" functions corrected on QueryEngine
// Remove try{} catch{} when enabled and I start throwing CommandExceptions
// }
Assert.assertThat("indicator", (Double) s.getIndicatorValue(1), equalTo(10000.0));
Assert.assertNull("site x", s.getX());
// assure project is present
SiteDTO s1 = result.getData().get(1);
assertThat(s1.getId(), equalTo(1));
assertThat(s1.getProject().getId(), equalTo(3));
}
use of org.activityinfo.legacy.shared.command.GetSites in project activityinfo by bedatadriven.
the class GetSitesTest method duplicated.
@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void duplicated() {
// A given site can be appear multiple times in the list if it is the
// source
// of one or more indicators
setUser(1);
GetSites cmd = new GetSites();
SiteResult result = execute(cmd);
assertThat(result.getData().size(), equalTo(3));
}
Aggregations