Blog

  Embedding MicroStrategy in an Adobe Flex Application


Introduction

MicroStrategy is a company primarily developing Business Intelligence (BI) software. Its main product, also named MicroStrategy, allows its users to perform reporting and analysis of data stored in a relational database, multidimensional database, or a flat data file.

Adobe Flex is a software development kit (SDK) released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. Flex applications can be written either using Adobe Flash Builder or by using the freely available Flex compiler from Adobe.

In this blog, we shall see how to integrate MicroStrategy into Adobe Flex to create Internet applications which involve handling efficient database transactions along with presenting the user with rich, quality and usable content.

Why the integration is needed

Adobe Flex is an excellent tool for creating a UI (user interface), but it does not have features which can let it connect to any database directly. Flex requires an intermediate layer which can fetch the data from a database and this is where MicroStrategy comes into the picture. The MicroStrategy query engine can work as the intermediate layer between Flex and the database. This blog also illustrates how to embed MicroStrategy into Flex using the former’s SDK (formally known as the MicroStrategy Visualization plug-in).

The main advantage of using the plug-in is to utilize MicroStrategy’s robust query engine, along with its ready-to-use data-aware controls. At the same time, MicroStrategy provides the flexibility to the developer to use the general Flex controls and to create customized classes in order to provide complex functionality and UI which might not be possible within MicroStrategy Web Universal – a platform provided by MicroStrategy to create the Flash based reports.

What you will need for the integration

  • MicroStrategy report(s) – already developed
  • Adobe Flex Builder 3
  • MicroStrategy Visualization Plug-in

Installing the MicroStrategy Visualization Plug-In

This is a plug-in provided by MicroStrategy for Adobe Flex Builder 3. This plug-in provides all of the files that you will need to create a MicroStrategy-data-aware Flex application. The following are the steps to install the plug-in:

  • Unzip the com.microstrategy.sdk.tools.visframe.visualizationbuilder.zip file, provided by MicroStrategy. You will find this file under <microstrategy_installation_directory>SDKtools FlexVisualizationBuilder.
  • Extract the contents of this ZIP file to the plugins folder in your Adobe Flex Builder installation directory. This will create a folder called com.microstrategy.sdk.tools.visframe.visualizationbuilder within the plugins folder.

Configuring the MicroStrategy Visualization Plug-In

  • Start Flex Builder.
  • Open Preferences under the Windows menu.

Select the Visualization Builder node from the left panel.

  • In the right panel, enter the following values:
  • Task URL: http://<webserver>/MicroStrategy/servlet/taskProc
  • Web URL: http://<webserver>/MicroStrategy/servlet/mstrWeb
  • Intelligent Server: Select the I-Server you want to connect to.
  • Visualization Deployment Folder: Enter or browse to the root folder where MicroStrategy Web is installed.
  • You can verify the settings by clicking on the Test Connection button.

Creating a MicroStrategy enabled project

  • Create a new Flex project.
  • Open Project Properties and add the required visualization related swcs under Library.

MicroStrategy enabled project

Code for connecting to the MicroStrategy project

 

1 var loginTask:LoginTask = new LoginTask(taskURL);
2 loginTask.addEventListener(TaskEvent.SUCCESS, handleSuccess);
3 loginTask.addEventListener(TaskEvent.FAILURE,handleFailure);
4 loginTask.user = userid;
5 loginTask.password = password;
6 loginTask.server = serverName;
7 loginTask.project = projectName;
8 loginTask.authMode = 1;
9 loginTask.execute();
  • Create a login task as shown in line 1 of the code above. taskURL is the URL where all the tasks are located. A typical taskURL looks like http://localhost:8080/MicroStrategy/servlet/taskProc
  • Assign event handlers to the login task created in line 1. These handlers will handle the success and failure of the task.
  • projectName is the name of the MicroStrategy project you want to connect to (this project must be available on the server mentioned in line 6).
  • A successful login task returns a sessionState (a string), which will be used in future calls made to MicroStrategy. So in the success handler of the login task, add the following line of code:
1 sessionState = LoginTask(event.getTask()).getSessionState();

MVC Pattern for MicroStrategy

The SDK provides a controller object, model related objects and various embedded Flex controls (view objects). Using these objects, we can display the data of a MicroStrategy report in Flex. Initiate the controller as:

1 private var _controller:Controller;
2 _controller = Controller.getInstance(MstrApplication(myApp).appNameSpace);

Here, myApp is the name of my application’s mxml file. To this controller, add a handler for the completion event of report execution. Then execute the MicroStrategy report using the initializeFromReport method of the controller object, as below:

1 _controller.addEventListener(ControllerEvent.XML_LOAD_COMPLETE,
2 completeXMLLoad);
3
4 _controller.initializeFromReport(taskURL, sessionState, RPT_ID,
5 "&maxRows=-1");

taskURL: URL where all MicroStrategy tasks are located on the server.

sessionState: Session state returned by a successful login task.

RPT_ID: Unique object ID of the MicroStrategy report.

The last parameter specifies that we wish to retrieve all the rows from the report.

In the completeXMLLoad handler, populate the models required for your views. We assume that we have a line chart and a dropdown on our screen. The models for these view controls are populated as follows:

1 _controller.createModel("modelMainDay",RPT_ID,
2 "r.[r:(3):(1)],c.1");
3 _controller.createModel("modelActivity",
4 RPT_ID, "[r:(1):]""""""modelMainDay");

In the first step, we populate a model (modelMainDay) to be used for the chart control. We are specifying that we want to use the third attribute (r:(3):(1)) and first and second metrics (c:(1):(1);c:(1):(2)) from the report in the chart.

In the second step, we create a model (modelActivity) for the dropdown. This model will use the first attribute of the report, and that attribute will act as a filter for the modelMainDay model. So whenever we change the dropdown, the data in the chart will automatically get filtered as per the current value of the dropdown.

The view is defined as:

1 <mstr:MstrLineChart id="chartMain"
2   useDefaults="false"
3   seriesFilters="[]"
4 styleName="mainChartStyle">
5
6 <mstr:MstrComboBox id="cboActivity" />

Finally, we assign the modelMainDay model to this chart and the dropdown.

1 chartMain.modelKey = modelMainDay;
2 cboActivity.modelKey = modelActivity;

A sample report created using this Framework

The following screenshot shows how the final report created using this integrated framework will be displayed.

Conclusion

We saw in this blog how the correct integration of a BI product with a UI tool can help us analyze data, generate accurate and timely business reports, and increase the productivity of any business. It should, therefore, not come as a surprise that such tools are being used today by a majority of the Fortune 500 companies worldwide.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.