MicroStrategy ONE

Converting a Report to a Data Mart Report Using Report Bean Events and Saving the Report Definition

The following code sample illustrates how to convert an existing report instance to a data mart report instance and save the report definition, using report bean events. This code converts the report and saves the report definition.

Code sample

This code sample assumes that a valid report instance exists. Otherwise, it throws an exception.

  public voidconvertToDatamartAndSave() throws Exception {

 

    //assuming datamartReport is an existing report;

    //Creates a report bean instance of a normal report - that is, a report that has not been set as a data mart report.

    //Sample code for the getReportBean method used in line 4 is provided for you in the Examples topic.

    ReportBean rb = getReportBean("Sample Report2");

 

    //make sure that the report is ready and get the report data from the Intelligence Server

    rb.collectData();

 

    //sets up the event handler (REPORT_EVENT_DEFINE_DATAMART) that converts

    //the report results to columns in the data mart table

    WebEvent we = rb.getWebEvent(EnumReportBeanEvents.REPORT_EVENT_DEFINE_DATAMART);

 

    // assume that mr is the Request key object.

    //set up the values of the event arguments - the name of the data mart table that is generated

    //when the data mart report is executed,whether the name contains macros that need to be replaced,

    //whether the report results should be appended to an existing table or a new table created,

    //and the database connection information. In this sample code, the name of the table is "Datamart2",

    //the name does not contain macros, a new table is created,

    //and the database connection with a GUID of"11111111111111111111111111111111" is used.

    mr.add(GenericWebEvent.URL_EVENT_NAME,String.valueOf(EnumReportBeanEvents.REPORT_EVENT_DEFINE_DATAMART));

    mr.add(we.getArgumentName(EnumReportBeanEvents.REPORT_EVENT_ARGUMENT_DM_TABLE_NAME),"Datamart2");

    mr.add(we.getArgumentName(EnumReportBeanEvents.REPORT_EVENT_ARGUMENT_DM_NAME_MACRO), "1");

    mr.add(we.getArgumentName(EnumReportBeanEvents.REPORT_EVENT_ARGUMENT_DM_APPEND), "1");

    mr.add(we.getArgumentName(EnumReportBeanEvents.REPORT_EVENT_ARGUMENT_DB_ROLE_ID),"11111111111111111111111111111111");

 

     // triggers the event that defines the data mart (REPORT_EVENT_DEFINE_DATAMART).

     rb.handleRequest(mr);

 

     // ensure that the results are ready; applies the changes to the report bean instance; the report instance now corresponds to a data mart 

     rb.collectData();

  

     // at this point the report instance should correspond to a datamart and we are ready

     // to use it such. To save, however, you can leverage another event.

  

     //sets up the event (REPORT_EVENT_SAVE_AS) that saves the report definition as a data mart report

     WebEvent weSave = rb.getWebEvent(EnumReportBeanEvents.REPORT_EVENT_SAVE_AS);

 

     //save the data mart report - using the specified table name, placing the table in the folder

     //whose folder ID is specified, and setting the display mode to display as a data mart

     mrSave.add(GenericWebEvent.URL_EVENT_NAME,String.valueOf(EnumReportBeanEvents.REPORT_EVENT_SAVE_AS));

     mrSave.add(weSave.getArgumentName(EnumReportBeanEvents.REPORT_EVENT_ARGUMENT_SAVE_AS_NAME), "Datamart2");

     mrSave.add(weSave.getArgumentName(EnumReportBeanEvents.REPORT_EVENT_ARGUMENT_SAVE_AS_PARENT_FOLDER_ID), "22222222222222222222222222222222");

 

     // IMPORTANT => make sure that the display mode is setup correctly to datamart.

     mrSave.add(weSave.getArgumentName(EnumReportBeanEvents.REPORT_EVENT_ARGUMENT_DISPLAY_FLAGS), String.valueOf(EnumDSSXMLDisplayMode.DssXmlDisplayModeDatamart));

 

     //Trigger the event that saves the data mart report definition

     rb.handleRequest(mrSave);

 

     // at this point, the report bean should correspond to the new saved datamart report.

  }

Explanation

Line 4 creates a report bean instance of a normal report - that is, a report that has not been set as a data mart report. (Sample code for the getReportBean method used in line 4 is provided for you in the Examples topic.)

Line 7 gets the report data from the Intelligence Server.

Line 10 sets up the event handler (REPORT_EVENT_DEFINE_DATAMART) that converts the report results to columns in the data mart table.

Line 12 indicates that users must implement their version of the request key.

Lines 13 - 17 set up the values of the event arguments - the name of the data mart table that is generated when the data mart report is executed, whether the name contains macros that need to be replaced, whether the report results should be appended to an existing table or a new table created, and the database connection information. In this sample code, the name of the table is "Datamart2", the name does not contain macros, a new table is created, and the database connection with a GUID of "11111111111111111111111111111111" is used.

Line 20 fires the event that defines the data mart (REPORT_EVENT_DEFINE_DATAMART).

Line 23 applies the changes to the report bean instance; the report instance now corresponds to a data mart.

Line 29 sets up the event (REPORT_EVENT_SAVE_AS) that saves the report definition as a data mart report. Lines 32 - 34 save the data mart report - using the specified table name, placing the table in the folder whose folder ID is specified, and setting the display mode to display as a data mart. Line 47 fires the event that saves the  (REPORT_EVENT_SAVE_AS).

Line 37 confirms that the executionflags are set to display the report as a data mart.

Line 40 fires the event that saves the data mart report definition.