Search in sources :

Example 1 with Activity

use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.

the class ActivityFormProvider method openForm.

@Override
public FormStorage openForm(QueryExecutor executor, ResourceId formId) throws SQLException {
    int activityId = CuidAdapter.getLegacyIdFromCuid(formId);
    Map<Integer, Activity> map = activityLoader.load(singleton(activityId));
    Activity activity = map.get(activityId);
    if (activity == null) {
        throw new FormNotFoundException(formId);
    }
    return new SiteFormStorage(activity, buildMapping(activity, formId), executor, activityLoader.getPermissionCache());
}
Also used : Activity(org.activityinfo.store.mysql.metadata.Activity) FormNotFoundException(org.activityinfo.store.spi.FormNotFoundException)

Example 2 with Activity

use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.

the class MySqlCatalogIntegrationTest method testSerializeActivity.

@Test
public void testSerializeActivity() throws SQLException, IOException {
    Activity activity = catalog.getActivityLoader().load(33);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(activity);
}
Also used : Activity(org.activityinfo.store.mysql.metadata.Activity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Example 3 with Activity

use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.

the class MySqlCatalogTest method testActivitySerialization.

@Test
public void testActivitySerialization() throws SQLException, IOException {
    ActivityLoader loader = new ActivityLoader(dbunit.getExecutor());
    Map<Integer, Activity> map = loader.load(Collections.singleton(1));
    Activity activity = map.get(1);
    ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
    oos.writeObject(activity);
}
Also used : Activity(org.activityinfo.store.mysql.metadata.Activity) ActivityLoader(org.activityinfo.store.mysql.metadata.ActivityLoader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Example 4 with Activity

use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.

the class ActivityFormProvider method openForms.

@Override
public Map<ResourceId, FormStorage> openForms(QueryExecutor executor, Set<ResourceId> formIds) throws SQLException {
    Set<Integer> activityIds = new HashSet<>();
    for (ResourceId collectionId : formIds) {
        if (accept(collectionId)) {
            activityIds.add(CuidAdapter.getLegacyIdFromCuid(collectionId));
        }
    }
    if (activityIds.isEmpty()) {
        return Collections.emptyMap();
    } else {
        Map<Integer, Activity> activityMap = activityLoader.load(activityIds);
        Map<ResourceId, FormStorage> collectionMap = new HashMap<>();
        for (ResourceId collectionId : formIds) {
            if (accept(collectionId)) {
                Activity activity = activityMap.get(CuidAdapter.getLegacyIdFromCuid(collectionId));
                if (activity != null) {
                    collectionMap.put(collectionId, new SiteFormStorage(activity, buildMapping(activity, collectionId), executor, activityLoader.getPermissionCache()));
                }
            }
        }
        return collectionMap;
    }
}
Also used : FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Activity(org.activityinfo.store.mysql.metadata.Activity)

Example 5 with Activity

use of org.activityinfo.store.mysql.metadata.Activity in project activityinfo by bedatadriven.

the class PivotAdapter method executeTargetValuesQuery.

private void executeTargetValuesQuery(Integer databaseId) {
    if (filter.isRestricted(DimensionType.AttributeGroup) || filter.isRestricted(DimensionType.AdminLevel) || filter.isRestricted(DimensionType.Site) || filter.isRestricted(DimensionType.Location)) {
        // No results, exit now
        return;
    }
    ResourceId targetFormClassId = CuidAdapter.cuid(CuidAdapter.TARGET_FORM_CLASS_DOMAIN, databaseId);
    QueryModel queryModel = new QueryModel(targetFormClassId);
    QueryFilter queryFilter = new QueryFilter(filter, attributeFilters, LOGGER);
    queryModel.setFilter(queryFilter.composeTargetFilter());
    final Collection<Activity> activities = databases.get(databaseId);
    // Add all indicators we're querying for
    for (Activity activity : activities) {
        for (ActivityField indicator : selectedIndicators(activity)) {
            queryModel.selectField(targetFieldExpr(indicator)).as(alias(indicator));
        }
    }
    for (DimBinding dimension : groupBy) {
        for (ColumnModel columnModel : dimension.getTargetColumnQuery(targetFormClassId)) {
            queryModel.addColumn(columnModel);
        }
    }
    enqueueQuery(queryModel, new Function<ColumnSet, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable ColumnSet columnSet) {
            for (Activity activity : activities) {
                for (ActivityField indicator : selectedIndicators(activity)) {
                    ColumnView measureView = columnSet.getColumnView(alias(indicator));
                    DimensionCategory indicatorCategory = null;
                    if (indicatorDimension.isPresent()) {
                        indicatorCategory = indicatorDimension.get().category(indicator);
                    }
                    for (int i = 0; i < columnSet.getNumRows(); i++) {
                        double value = measureView.getDouble(i);
                        if (!Double.isNaN(value) && !Double.isInfinite(value)) {
                            Map<Dimension, DimensionCategory> key = new HashMap<>();
                            for (DimBinding dim : groupBy) {
                                DimensionCategory category = dim.extractTargetCategory(activity, columnSet, i);
                                if (category != null) {
                                    key.put(dim.getModel(), category);
                                }
                            }
                            if (indicatorCategory != null) {
                                key.put(indicatorDimension.get().getModel(), indicatorCategory);
                            }
                            Accumulator bucket = bucketForKey(key, indicator.getAggregation());
                            bucket.addValue(value);
                        }
                    }
                }
            }
            return null;
        }
    });
}
Also used : DimensionCategory(org.activityinfo.legacy.shared.reports.content.DimensionCategory) ColumnView(org.activityinfo.model.query.ColumnView) Activity(org.activityinfo.store.mysql.metadata.Activity) LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) QueryFilter(org.activityinfo.server.command.QueryFilter) ResourceId(org.activityinfo.model.resource.ResourceId) ColumnModel(org.activityinfo.model.query.ColumnModel) ActivityField(org.activityinfo.store.mysql.metadata.ActivityField) Nullable(javax.annotation.Nullable)

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