Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

If you want to write some code that make makes the Pentaho BI Platform talk to an external system, this may be what you are looking for, so read on...

...

Table of Contents
indent20px
styledisc

What is an Action?

Actions are the lightweight alternative to Pentaho BI Components.  For an understanding of how and why they are different, let's take a step back and examine what a BI Component is and how it is used.  A BI Component is historically a Java class that does some work, yielding some output, when it is provided certain inputs and resources.  The work done as well as the inputs and resources required are entirely up to the component developer.  It's purpose is to perform some work in a sequential success-based workflow (action sequence).  A saavy BI Platform user with a bit of inclination for Java coding can implement his or her own custom component to do just about anything.  However, this is not an easy endeavour since developing your own BI Component requires intimate knowledge of internal Pentaho APIs.  When you are done writing your custom component, the code you have written will be tightly coupled to the Pentaho BI Platform, so much so, that it will be difficult to unit test and may be difficult to maintain.

...

  • IAction - advertises that your bean has something to do and gives the platform's solution engine a method to execute.  This is the API that identifies your bean an Action.
  • IStreamingAction - indicates that your bean accepts output streams managed by action sequence content outputs, such as a ServletResponse output stream.  You would implement this if you intended to write to such an output stream during execution.
  • ILoggingAction - if your bean implements this, it will be provided a logger instance to which it can write errors, warnings, and debug messages.
  • ISessionAwareAction - supplies your bean with an instance of the current Pentaho session
  • IVarArgsAction - Allows an Action to accept inputs from the action sequence that are unspecified by the Action itself
  • IDefinitionAwareAction - Makes an Action privy to certain details about the action definition that is responsible for executing it
  • IPreProcessingAction - Allows an Action to do some preliminary work prior to execution

...

The Action framework expects Action objects to be Java bean compliant with respect to setting inputs, setting resources, and getting outputs.  In other words, if your action needs takes a string input, the action definition in the xaction solution file will specify this string input, and the Action framework will cause that value to be set via a setter method on the Action object.  You do not see parameter Maps and such in the Action API for this reason.  All inputs, output, and resources IO will involve Java bean reflection on your Action object to find the appropriate IO methods.

See the Echo Plugin - a sample plugin for the BI PlatformBIServer project for examples of how to get data into your IAction and how to expose the output of your IAction so something else can do something with it (i.e. display the results of your IAction, pipe them to another step in an action sequence, or bind them to a session parameter).

...

Sometimes your Action bean will need to pass inputs through to another subsystem and not act on them directly. For these inputs, it is cumbersome and sometimes impossible to create setter methods for each possible input. If this is the case for you, then have your Action bean implement the IVarArgsAction interface. This will allow you to receive a map containing all the inputs that were specified in the action definition but had no setter method counterpart in your Action bean. h3.

Collection Inputs

Your Action may need to operate on an array of similar items, such as sending an email with multiple attachments, like so:

...

Code Block
public class MyAction implements IAction {
\\
public void setAttachments(int index, Object o)
{     //do something   }\\
public Object getAttachments(int index)\\
 { //will not be called }\\
public void execute() throws Exception {}
\\
}

Alternatively, you can specify a getter method that returns a reference to the array to which the attachment object will be added, e.g.

Code Block
public class MyAction implements IAction {
\\
private List<Object> attachments = new ArrayList<Object>();
\\
public List<Object> getAttachments()
{     return attachments;   }\\
public void execute() throws Exception {}
\\
}

These two behaviors are employed by BeanUtils to implement what they called call indexed properties. In summary,

...

xaction resource

Java type

expected Action bean method (Java)

<myResource type="resource"/>

java.io.InputStream

setMyResource(InputStream o) { ...

 

 


Plugging in Actions

Of course writing an Action does no good unless you can use it in an action sequence, right? Well the way you make the Pentaho BI Platform aware of your Action is to write a plugin. See the wiki page on developing plugins for more information.