Search in sources :

Example 6 with Activity

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;
}
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 7 with Activity

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));
    }
}
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 8 with Activity

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

Example 9 with 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);
}
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

Activity (org.activityinfo.store.mysql.metadata.Activity)9 LinkedActivity (org.activityinfo.store.mysql.metadata.LinkedActivity)5 ResourceId (org.activityinfo.model.resource.ResourceId)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Test (org.junit.Test)2 TraceContext (com.google.cloud.trace.core.TraceContext)1 Nullable (javax.annotation.Nullable)1 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)1 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)1 FormTree (org.activityinfo.model.formTree.FormTree)1 ColumnModel (org.activityinfo.model.query.ColumnModel)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 ColumnView (org.activityinfo.model.query.ColumnView)1 QueryModel (org.activityinfo.model.query.QueryModel)1 QueryFilter (org.activityinfo.server.command.QueryFilter)1 ActivityField (org.activityinfo.store.mysql.metadata.ActivityField)1 ActivityLoader (org.activityinfo.store.mysql.metadata.ActivityLoader)1 BatchingFormTreeBuilder (org.activityinfo.store.spi.BatchingFormTreeBuilder)1 FormNotFoundException (org.activityinfo.store.spi.FormNotFoundException)1