MicroStrategy ONE

Report Transform Example

The following code sample uses the objects contained by the Transforms infrastructure package. In the code sample below, you can see how a simple transform’s code can look. This sample is relatively simple, but it is only the beginning of what you can choose to add to a transform to manipulate a ReportBean’s data in exactly the way you choose. This example provides with a starting point toward building your own transforms and using objects from both the Web Objects API and the Web Beans API.

This sample includes the definition of a sample transform parameter that you can want to build into your custom transform definition. In the first half of the code, you can see the definition of the sample formal parameter:

  • The fontNameParam of type FormalParameterImpl is defined  

  •  A constructor is called to give it the name by which it is accessed by the user (in the Style Catalog, for example). The type of value is specified here as well.  

  • setRequired(true) indicates that this formal parameter requires a value to be set before the transform() method can be called with success.  

  • The description is set, which is useful when this transform is deployed in the Style Catalog.  

  • The transform’s addFormalParam method is called to add this object just built to the transform’s definition.

Code Sample

package mypackage.name;

import com.microstrategy.web.beans.*;

import com.microstrategy.web.objects.*;

import com.microstrategy.web.transform.*;

import com.microstrategy.webapi.*;

import java.io.*;

 

public class MySimpleTransformClass extends AbstractTransform{

     //Custom Formal Parameter Definition

     private FormalParameterImpl fontNameParam;

     //Set Values in Constructor

     public MySimpleTransformClass() {

          fontNameParam = new FormalParameterImpl("fontName", FormalParameter.PARAM_TYPE_STRING);

          fontNameParam.setRequired(true);

          fontNameParam.setDescription("This is the font name to use in rendering my transform");

          addFormalParam(fontNameParam);

     }

 

     public String getDescription() {

          return “My simple transform class to display basic report info";

     }

 

     public void transform(Transformable t, MarkupOutput out) {

          try{

               ReportBean rb = (ReportBean)t;

               WebObjectInfo woi = rb.getObjectInfo();

               out.append(<p style='font-family: fontNameParam.getValue()'+ "<br>")

               out.append("Report Name= " + woi.getName() + "<br>");

               out.append("Report Owner= " + woi.getOwner() + "<br>");

               out.append("Report Desc= " +woi.getDescription()+ "<br>");

               out.append("</p>")

          } catch (Exception e){

               out.append("Report Execution error " +e.getMessage());

          }

     }

 

     public Class getSupportedBeanType() {

          return ReportBean.class;

     }

}

Explanation

In the code example above, the input transformable object (in this case, the ReportBean) is cast as a ReportBean, and then a WebObjectInfo is derived from the bean. From the WebObjectInfo, output the report’s name, description, and owner. The value set on the formal parameter by the Style Catalog style definition is used to specify what font is used to output the results.

Generally, when writing your own transform, you create your class so that it extends the AbstractTransform or AbstractAppTransform interface, or some derived class. If you are extending AbstractAppTransform, the most important methods to override are transformForRequestSuccessful(MarkupOutput) and the other methods such as those defined in the topic that discusses the AbstractTransform interface.

If you are extending AbstractTransform, commonly overridden methods include:

  • getDescription()  

  • getSupportedBeanType()  

  • transform()—where the transformation rules are written