MicroStrategy ONE

Code Sample

Two code samples are provided below to illustrate how to transform a report bean. One sample uses a style that you create, and the other sample uses an existing style with a layout definition. You can see the definitions for all existing styles in the Style Catalog Configuration file.

The following code sample shows how to transform a bean using a style, grid, that you create.

 //Step 1. Create Report Bean and TransformInstances to be used later

 WebBeanFactory factory = WebBeanFactory.getInstance();

 ReportBean rb = (ReportBean) factory.newBean("ReportBean");

 TransformInstance ti1 = rb.addTransform(new com.microstrategy.web.app.transforms.ReportGridTransformImpl());

 ti1.setKey("grid");

 

 //Step 2. Set I-Server Session, and set bean state through arbitrary name

 rb.setSessionInfo((WebSessionInfo)mySess);

 rb.setName("MyReportBean");

 

 //Step 3. Specify report to be used by name or ID, and call collectData()

 rb.setObjectID("8A4348234290A8E2B721ABAC65818F47");

 rb.collectData();

 

 //Step 4. Render collected data

 MarkupOutput mo = rb.transform("grid");

 StringWriter sw = new StringWriter();

 mo.send(sw);

 System.out.println(sw.getBuffer().toString());

A brief explanation of this code sample is provided below:

  • In step 1, a TransformInstance is created using ReportGridTransformImpl, and the key parameter "grid" is set on the transform.  

  • In step 2, the setName() method is not explicitly necessary, but providing this line allows you to easily persist this bean by its specified name.  

  • In step 2, mySess is presumed to already exist either by creation from the WebObjectsFactory on this page, or by persisting the WebIServerSession defined on a previous page.  

  • In Step 3, the setObjectID() method is used, but the setName() method can also be used. You can use either the ID or the name of the report to set the state of the report bean.  

  • In Step 4, the transform() method of the report bean rb passes the key parameter "grid"  to indicate that the TransformInstance created in step 1 should be used to render the report bean data.

    If a TransformInstance had called setDefault(), and the transform()method had been called without providing a key parameter, the Transform object associated with the default TransformInstance would be used to render the report bean data.

The following code sample shows how to transform a bean using an existing style, ReportGridStyle, that has a layout definition. ReportGridStyle is defined in the Style Catalog Configuration file along with its layout definition file.

 //Step 1. Create Report Bean and TransformInstances to be used later

 WebBeanFactory factory = WebBeanFactory.getInstance();

 ReportBean rb = (ReportBean) factory.newBean("ReportBean");

 StyleCatalog styleCatalog = (StyleCatalog) ConfigurationFilesCache.getConfiguration("/WEB-INF/xml/styleCatalog.xml", StyleCatalogImpl.class);

 Transform transform =

 TransformInstance ti1 = rb.addTransform(transform);

 ti1.setKey("ReportGridStyle");

 

 //Step 2. Set I-Server Session, and set bean state through arbitrary name

 rb.setSessionInfo((WebSessionInfo)mySess);

 rb.setName("MyReportBean");

 

 //Step 3. Specify report to be used by name or ID, and call collectData()

 rb.setObjectID("8A4348234290A8E2B721ABAC65818F47");

 rb.setMaxWait(-1);

 rb.collectData();

 

 //Step 4. Render collected data

 MarkupOutput mo = rb.transform("ReportGridStyle");

 StringWriter sw = new StringWriter();

 mo.send(sw);

 System.out.println(sw.getBuffer().toString());

 mySess.closeSession();

A brief explanation of this code sample is provided below:

  • In step 1, a TransformInstance is created using an existing style in the Style Catalog, ReportGridStyle. This style has a layout definition associated with it. The key parameter for the transform is the style name, ReportGridStyle

  • The setName() method in Step 2 is not explicitly necessary in this example.  However, providing this line allows us to easily persist this bean by our specified name. 

  • In step 2, mySess is presumed to already exist either by creation from the WebObjectsFactory on this page, or by persisting the WebIServerSession defined on a previous page. 

  • In Step 3, the setObjectID() method is used, but the setName() method can also be used. You can use either the ID or the name of the report to set the state of the report bean. 

  • In Step 4, the transform() method of the report bean rb passes the key parameter "ReportGridStyle"  to indicate that this style, and its layout definition, should be used to render the bean’s data.