ActivePivot: Member Properties and Analysis Hierarchies (together at last).

Analysis Hierarchies

Analysis hierarchies* are one of the key features of ActivePivot.  They allow data, aggregated in a compressed/OOP form, to be expanded dynamically at query time from a single aggregated Object to display its components individually against derived MDX Members.

A classic use case is a set of VaR scenarios that are aggregated in an array object, but are displayed with an MDX member for each scenario.

Member Properties

A standard feature of the MDX language is Member Properties.  These allow meta-data to be included with a member.  On a Pivot Table in Excel, these member properties can be displayed in a tool-tip when the user selects the member cell.  For example, a product name could be the member value, with its serial number as a member property.

In ActivePivot, Member Properties are implemented as extended plugins and then instantiated as defined for hierarchy levels in the cube schema, e.g.:

<level name="Product">
    <memberProperties>
        <property name="Serial No." pluginKey="ProductSerialNumber"/>
    </memberProperties>
</level>

Together at last

Unfortunately, this will not work for Analysis Hierarchies**, because their levels are created programmatically based on the plugin implementation of the hierarchy with no reference to the cube schema file.

To add member properties to an analysis dimension, one can override the createLevels() function in their class that extends ActivePivot’s external class AAnalysisHierarchy, and use reflection*** like so:

@Override
protected List createLevels() {
    List levels = super.createLevels();
    levels.stream()
            .filter(l -> !ILevel.ALLMEMBER.equals(l.getName()))
            .forEach(l -> {
                    l.getLevelInfo().getMemberProperties();
                    try {
                        Map<String,IProperty> analysisMemberProperties = new HashMap<>();
                        analysisMemberProperties.put(
                                "memberPropertyName",
                                Registry.createExtendedPluginValue(ICustomProperty.class, AlternateFormat.PLUGIN_KEY, new Object[]{"alternativeFormattedValue"})
                            );
                        FieldUtils.writeDeclaredField(l.getLevelInfo(), "memberProperties", analysisMemberProperties, true);
                    } catch (IllegalAccessException e) {
                        throw new RuntimeException("Unable to set level member property for analysis hierarchy", e);
                    }
                });
    return levels;
}

* Known as Analysis Dimensions in verions prior to ActivePivot 5.
** At least not in versions 5.1.5 or lower.
*** The field is type final.

Advertisements
This entry was posted in Development and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s