Adding New Cube Measures
This page provides a description of how we can add a measure. The techniques employed are generic examples that can be extended, adapted, and repeated for any use case that we need.
To avoid forking library code, all extensions are made by subclassing the relevant configuration class from the cvarc-starter library module and wiring the subclass into your project’s ApplicationConfig in the cvarc-application module.
Step 1 - Extend the cube selection
If your new measure depends on a field that is not yet reachable through the cube’s selection, extend the selection so the field can be found.
The selection is built in createBASelection() / createSASchemaSelectionDescription(), which live in BACubeConfig / SACubeConfig (in the cvarc-starter library module). Use the subclass pattern described in Adding a Hierarchy — Step 2: create a CustomBACubeConfig extends BACubeConfig (or CustomSACubeConfig extends SACubeConfig) in cvarc-application/src/main/java/com/activeviam/cvarc/application/cfg/extensions/, annotated with @Configuration and @Primary, and override the selection method to add the reference to your new field’s store.
note
Make sure that any new field added to the selection does not exist in the selection already, and that it points to a corresponding field in a datastore.
Step 2 - Define the measure
Extend BAMeasureBuilder (or SAMeasureBuilder) to add new measures. Place the new class in cvarc-application/src/main/java/com/activeviam/cvarc/application/cfg/extensions/.
public class ExtendedBAMeasureBuilder extends BAMeasureBuilder {
@Override
public void measures(ICopperContext context) {
super.measures(context);
Copper.sum("TestField").publish(context);
}
}
To read more about creating measures with Copper, see Creating and publishing measures.
Step 3 - Wire the extended measure builder into the cube config
To swap BAMeasureBuilder::measures for ExtendedBAMeasureBuilder::measures, extend the cube config rather than editing it in place. If you already created CustomBACubeConfig for Step 1, override configureCubeBuilder() in the same class; otherwise create it now in cvarc-application/src/main/java/com/activeviam/cvarc/application/cfg/extensions/.
@Configuration
@Primary
public class CustomBACubeConfig extends BACubeConfig {
@Override
public ICanBuildCubeDescription<IActivePivotInstanceDescription> configureCubeBuilder(
final INamedCubeDescriptionBuilder builder) {
return builder
.withMeasures(ExtendedBAMeasureBuilder::measures) // use the extended measure builder
// ... copy the rest of the parent's chain, or call super.configureCubeBuilder(builder)
// and post-process the result if you only need a localized change.
;
}
}
Then add CustomBACubeConfig to the @Import list of ApplicationConfig in cvarc-application/src/main/java/com/activeviam/cvarc/application/cfg/ApplicationConfig.java.