Search in sources :

Example 1 with LinkedActivity

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;
}
Also used : LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) Activity(org.activityinfo.store.mysql.metadata.Activity) LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity) BatchingFormTreeBuilder(org.activityinfo.store.spi.BatchingFormTreeBuilder)

Example 2 with LinkedActivity

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));
    }
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity) Activity(org.activityinfo.store.mysql.metadata.Activity) LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity)

Example 3 with LinkedActivity

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);
    }
}
Also used : LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity)

Example 4 with 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);
}
Also used : LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity) ResourceId(org.activityinfo.model.resource.ResourceId) TraceContext(com.google.cloud.trace.core.TraceContext) Activity(org.activityinfo.store.mysql.metadata.Activity) LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity)

Aggregations

LinkedActivity (org.activityinfo.store.mysql.metadata.LinkedActivity)4 Activity (org.activityinfo.store.mysql.metadata.Activity)3 ResourceId (org.activityinfo.model.resource.ResourceId)2 TraceContext (com.google.cloud.trace.core.TraceContext)1 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)1 FormTree (org.activityinfo.model.formTree.FormTree)1 BatchingFormTreeBuilder (org.activityinfo.store.spi.BatchingFormTreeBuilder)1