use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.
the class PivotAdapter method queryFormTrees.
private Map<ResourceId, FormTree> queryFormTrees() {
treeTime.start();
Set<ResourceId> formIds = new HashSet<>();
for (Activity activity : activities) {
formIds.add(activity.getLeafFormClassId());
if (command.getValueType() == PivotSites.ValueType.TOTAL_SITES) {
formIds.add(activity.getSiteFormClassId());
}
for (LinkedActivity linkedActivity : activity.getLinkedActivities()) {
formIds.add(linkedActivity.getLeafFormClassId());
if (command.getValueType() == PivotSites.ValueType.TOTAL_SITES) {
formIds.add(activity.getSiteFormClassId());
}
}
}
BatchingFormTreeBuilder formTreeBuilder = new BatchingFormTreeBuilder(catalog);
Map<ResourceId, FormTree> trees = formTreeBuilder.queryTrees(formIds);
treeTime.stop();
return trees;
}
use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.
the class PivotAdapter method execute.
public PivotSites.PivotResult execute() throws SQLException {
try {
for (Activity activity : activities) {
switch(command.getValueType()) {
case INDICATOR:
executeIndicatorValuesQuery(activity, activity.getSelfLink());
for (LinkedActivity linkedActivity : activity.getLinkedActivities()) {
executeIndicatorValuesQuery(activity, linkedActivity);
}
break;
case TOTAL_SITES:
executeSiteCountQuery(activity, activity.getSelfLink());
for (LinkedActivity linkedActivity : activity.getLinkedActivities()) {
executeSiteCountQuery(activity, linkedActivity);
}
break;
}
}
if (command.isPivotedBy(DimensionType.Target) && command.getValueType() == PivotSites.ValueType.INDICATOR) {
for (Integer databaseId : databases.keySet()) {
executeTargetValuesQuery(databaseId);
}
}
executeQueryBatch();
PivotSites.PivotResult result = new PivotSites.PivotResult(createBuckets());
return result;
} finally {
LOGGER.info(String.format("Pivot timings: metadata %s, trees: %s, query: %s, aggregate: %s", metadataTime, treeTime, queryTime, aggregateTime));
}
}
use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.
the class GetSitesHandler method constructActivityLinks.
private void constructActivityLinks() {
if (!command.isFetchLinks()) {
return;
}
for (Activity activity : activities.values()) {
addSelfLink(activity);
addExternalLinks(activity);
}
}
use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.
the class GetSitesHandler method queryFormTrees.
private void queryFormTrees() {
TraceContext formTreeQueryTrace = Trace.startSpan("ai/cmd/GetSites/queryFormTrees");
treeTime.start();
Set<ResourceId> formIds = new HashSet<>();
Set<ResourceId> linkedFormIds = new HashSet<>();
List<Integer> linkedActivitiesToFetch = new ArrayList<>();
ResourceId activityFormId;
for (Activity activity : activities.values()) {
if (reject(activity)) {
continue;
}
activityFormId = activity.getSiteFormClassId();
formIds.add(activityFormId);
if (activity.isMonthly() && command.isFetchAllReportingPeriods()) {
formIds.add(CuidAdapter.reportingPeriodFormClass(CuidAdapter.getLegacyIdFromCuid(activityFormId)));
}
if (command.isFetchLinks()) {
for (LinkedActivity linkedActivity : activity.getLinkedActivities()) {
linkedActivitiesToFetch.add(linkedActivity.getActivityId());
linkedFormIds.add(CuidAdapter.activityFormClass(linkedActivity.getActivityId()));
}
}
}
formTreeMap = batchFormTreeBuilder.queryTrees(formIds);
if (!linkedActivitiesToFetch.isEmpty()) {
fetchLinkedActivityMetadata(linkedActivitiesToFetch);
linkedFormTreeMap = batchFormTreeBuilder.queryTrees(linkedFormIds);
}
treeTime.stop();
Trace.endSpan(formTreeQueryTrace);
}
Aggregations