Fluent custom analysis hierarchy definition

Overview

Since Atoti Server version 6.0.8, the best way to define a custom analysis hierarchy is to use the provided method:

/**
 * Adds a new analysis hierarchy.
 * <p>
 * Contrary to {@link #withAnalysisHierarchy(String)} this method does not need an
 * {@link IAnalysisHierarchyDescriptionProvider}.
 *
 * @param description the description of the hierarchy to add
 * @return The builder for chained calls.
 */
IWithAnalysisHierarchyDescriptionBuilder withAnalysisHierarchy(IAnalysisHierarchyDescription description);

Atoti Common Libraryprovides an extension of the IAnalysisHierarchyDescription object to create a more fluent experience and a higher-level user experience.

Here is the proposed way of building a custom analysis hierarchy:

@QuartetExtendedPluginValue(intf = IMultiVersionHierarchy.class, key = MyHierarchy.PLUGIN_KEY)
public class MyHierarchy extends AAnalysisHierarchyV2 {

    public static final String PLUGIN_KEY = "MY_HIERARCHY";

    /**
     * Return a description object to setup the hierarchy
     * @param hierarchy The hierarchy name
     * @return The description
     */
    @Contract(value = "_ -> new", pure = true)
    public static @NonNull Description hierarchy(@NonNull String hierarchy) {
        return new Description(hierarchy);
    }

    public static class Description extends MultipleLevelsHierarchyDescription<Description> {

        /**
         * Create a hierarchy description for MyHierarchy instance
         */
        public Description(@NonNull String hierarchyName) {
            super(PLUGIN_KEY, hierarchyName);
        }

        // Here comes some specific customizations
    }

    // Here comes the code of the custom hierarchy itself
}

Additionally, it can also be used like this:

.withAnalysisHierarchy(
        MyHierarchy.hierarchy("h1")
            .withSlicingLevel("lx", "v0", "v1")
                .withComparator(NaturalOrderComparator.type)
                .withType(Types.TYPE_STRING)
            .withLevel("ly"))

Basic fluent helper class

The class AccAnalysisHierarchyDescription extends AccAnalysisHierarchyDescription that implements the IAnalysisHierarchyDescription only defines the basic usable fluent methods that may be useful for all analysis hierarchies :

Method Parameters Usage
withAllMembersEnabled Boolean Specifies if the level 0 is the AllMembers level. Set to false makes the dimension slicing.
slicing Makes the hierarchy slicing, equivalent to withAllMembersEnabled(false).
withVisible Boolean Sets the visible flag to the hierarchy.
hidden Hides the hierarchy, equivalent to withVisible(false)
cast AccAnalysisHierarchyDescription<U> This is an internal function used to cast to the return the type U the this reference.

Helper for a single-level analysis hierarchy

To create a fluent setup for a custom single-level analysis hierarchy, you can override the class SingleLevelHierarchyDescription. This class holds a subclass used to set the required level name, and then creates the description itself. Here is how to configure it:

public class MyHierarchy extends AAnalysisHierarchyV2 {
    public static @NonNull SingleLevelHierarchyDescription.Builder<Description> hierarchy(@NonNull String hierarchy) {
        return new SingleLevelHierarchyDescription.Builder<>(Description::new, hierarchy);
    }

    public static class Description extends SingleLevelHierarchyDescription<Description> {
        private Description(String hierarchy, String level) {
            super(PLUGIN_KEY, hierarchy, level);
            // Here you should set all the default properties related to your single level hierarchy
        }

        // Here comes some specific customizations
    }

    // Here comes the code of the custom hierarchy itself
}

It will provide the following fluent methods, in addition to the ones provided by AccAnalysisHierarchyDescription:

Method Parameters Usage
withLevel String Specifies the name of the required level.
withType int The Copper type of the level (mandatory for Copper usage), for instance withType(Types.TYPE_STRING).
withComparator IComparator Sets the level comparator directly from a comparator object instance (the running hierarchy will create its own instance).
withComparator IComparatorDescription Sets the level comparator from a comparator description.
withComparator String Sets the level comparator from a comparator Plug-In Key.

Helper for a multi-level analysis hierarchy

To create a fluent setup for a custom multi-level analysis hierarchy, you can override the MultipleLevelsHierarchyDescription class. It will provide the following fluent methods, in addition to the ones provided by AccAnalysisHierarchyDescription:

Method Parameters Usage
withLevel String Specifies the name of the required level.
withType int The Copper type of the level (mandatory for Copper usage), for instance withType(Types.TYPE_STRING).
withComparator IComparator Sets the level comparator directly from a comparator object instance (the running hierarchy will create its own instance).
withComparator IComparatorDescription Sets the level comparator from a comparator description.
withComparator String Sets the level comparator from a comparator Plug-In Key.
lastLevel IAxisLevelDescription This is an internal function used to retrieve the last defined level to set additional level parameters.