use of org.activityinfo.legacy.shared.command.result.SiteResult 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.result.SiteResult 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.result.SiteResult in project activityinfo by bedatadriven.
the class SiteUpdate method ensureInitialHistoryEntry.
public void ensureInitialHistoryEntry(Site site, User user) {
long count = entityManager.createQuery("select count(h.id) from " + "SiteHistory h where h.site = :site", Long.class).setParameter("site", site).getSingleResult();
if (count == 0) {
// update, but first entry -> repair history by adding baseline
// record with complete site json
LOGGER.fine("site is not new, but history was empty. Adding baseline record..");
SiteResult siteResult = dispatcher.execute(GetSites.byId(site.getId()));
SiteDTO siteDTO = siteResult.getData().get(0);
String completeProperties = JsonUtil.encodeMap(siteDTO.getProperties()).toString();
SiteHistory baseline = new SiteHistory();
baseline.setSite(site);
baseline.setUser(user);
baseline.setJson(completeProperties);
baseline.setTimeCreated(new Date().getTime());
baseline.setInitial(false);
entityManager.persist(baseline);
}
}
use of org.activityinfo.legacy.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.legacy.shared.command.result.SiteResult in project activityinfo by bedatadriven.
the class GetSitesHandler method execute.
@Override
public SiteResult execute(GetSites cmd, User user) {
if (useLegacyMethod(cmd, user)) {
return dispatcher.execute(new OldGetSites(cmd));
}
LOGGER.info("Entering execute()");
aggregateTime.start();
try {
initialiseHandler(cmd, user);
fetchActivityMetadata(cmd.getFilter());
queryFormTrees();
constructActivityLinks();
buildQueries();
batchQueries();
executeBatch();
mergeMonthlyRootSites();
setSitesLinkedStatus();
sort();
} catch (CommandException excp) {
// old method at any point of execution and elongate the return time
return dispatcher.execute(new OldGetSites(cmd));
}
aggregateTime.stop();
printTimes();
SiteResult result = new SiteResult(siteList);
result.setOffset(cmd.getOffset());
result.setTotalLength(totalResultLength);
LOGGER.info("Exiting execute()");
return result;
}
Aggregations