use of org.activityinfo.store.mysql.metadata.LinkedActivity 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.LinkedActivity 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.LinkedActivity in project activityinfo by bedatadriven.
the class GetSitesHandler method addExternalLinks.
private void addExternalLinks(Activity activity) {
Iterator<LinkedActivity> links = activity.getLinkedActivities().iterator();
while (links.hasNext()) {
ActivityLink activityLink = new ActivityLink(activity.getId());
LinkedActivity linkedActivity = links.next();
activityLink.buildIndicatorMap(activity, linkedActivity);
activityLink.buildAttributeMap(activity, linkedActivities.get(linkedActivity.getActivityId()));
addToLinkMap(activityLink, linkedActivity);
}
}
use of org.activityinfo.store.mysql.metadata.LinkedActivity 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