MicroStrategy ONE

Web Feature Examples

Out of the box, MicroStrategy Web provides just a finite number of web features based on its own requirements. The features available out of the box are listed in the following two enumerations:

  • com.microstrategy.web.beans.EnumWebFeatures

    Enumerates features that are resolved by beans in the SDK layer.

  • com.microstrategy.web.app.beans.EnumAppWebFeatures

    Enumerates features that are resolved by the GlobalFeatures and application beans.

It is not possible or practical for the application to provide a feature for every different value that can be checked through the SDK. However, you have the ability to aggregate your own web features with those that are already being checked by any WebComponent in the application. To do this, simply create a new class that extends the AggregatedWebFeatures abstract class and implements the resolveCustomFeature method that receives the featureId. The class provides a getWebComponent() method that returns the corresponding WebComponent associated with this feature. The method can query this object to determine if the feature must be enabled or not.

An example of such a class is shown below. This class checks to see whether the name of a report is "Page-by" and whether the name of the user is "Guest".

import com.microstrategy.web.app.WebAppSessionManager;

import com.microstrategy.web.app.beans.AppContext;

import com.microstrategy.web.beans.AggregatedWebFeatures;

import com.microstrategy.web.beans.ReportBean;

import com.microstrategy.web.beans.WebBeanException;

/**

 * This custom WebFeatures class checks to custom features:

 * <ul>

 *  <li><b><code>page-by-report</code></b>: which returns true only if the name of the report is "f. Page-by"

 *  <li><b><code>guest-user</code></b>: which is available only if the name of the user is "Guest"

 * </ul>

 */

public class MyFeatures extends AggregatedWebFeatures {

    private static String PAGEBY_REPORT = "f. Page-by";

    private static String GUEST_USER = "Guest";

    public boolean resolveCustomFeature(String featureId) {

        boolean result = true;

        if ("page-by-report".equals(featureId)) {

            result = resolvePageByReport();

        } else if ("guest-user".equals(featureId)) {

            result = resolveGuestUser();

        }

        return result;

    }

    /**

     * For this feature, we check that the associated web-component

     * is a ReportBean and we return true only if the object-name

     * is a pre-defined value:

     **/

    private boolean resolvePageByReport() {

        boolean result = false;

        if (getWebComponent() instanceof ReportBean) {

            try {

                String reportName = ((ReportBean) getWebComponent()).getObjectName();

                result = PAGEBY_REPORT.equals(reportName);

            } catch (WebBeanException ex) {

                ex.printStackTrace();

            }

        } else {

            result = false;

        }

        return result;

    }

    /**

     * For this feature, we retrieve the session manager from the AppContext

     * and return true only if the user-name is a pre-defined value:

     **/

    private boolean resolveGuestUser() {

        boolean result = false;

        if (getWebComponent().getBeanContext() instanceof AppContext) {

            WebAppSessionManager sm = ((AppContext) getWebComponent().getBeanContext()).getAppSessionManager();

            result = GUEST_USER.equals(sm.getUserName());

        }

        return result;

    }    

}

To associate this class to a particular bean, invoke the aggregateFeatures method of the new class (inherited from this class AggregatedWebFeatures), this method expects as an argument the WebComponent to whom WebFeatures is associated. The resolveCustomFeature method can query this object to determine if the feature must be enabled or not.

An example of an add-on associated to the new WebFeature:

public class MyFeaturesAddOn extends AbstractAppAddOn {

  public void preCollectData(PageComponent pg) {

    ReportBean rb = page.getChildByClass(ReportBean.class);

    if (rb != null) {

    MyFeatures features = new MyFeatures();

    features.aggregateFeatures(rb);

    }

  }

}

When a feature is not specific to functionality of a particular bean (e.g. the features to check depend on application parameters, like preferences, or are based on the current session, like the user-name), the custom WebFeature can be associated directly to the page, in which case it can be used on any page, for example:

public class MyFeaturesAddOn extends AbstractAppAddOn {

  public void preCollectData(PageComponent pg) {

  MyFeatures features = new MyFeatures();

  features.aggregateFeatures(page);

  }

}