3.6.2 User-Defined Actions
In addition to the built-in Schedule actions, you can also define custom actions. A user-defined action class must implement the UserAction interface. There are three methods in the interface.
• The run() method is the main routine for performing the action.
• The other two methods, setRepletRequest() and getRepletRequest(), deal with the parameters for the user action.
You can configure a set of parameter values when you create an action in Enterprise Manager. The parameters are loaded and passed to the action through the setRepletRequest() method. This allows a user-defined action class to be parameterized in the same way as the default actions.
The DefaultUserAction class provides a default implementation of the UserAction interface. The subclass of DefaultUserAction only needs to define the run() method. As with conditions, the equals() method should also be implemented.
To make the user-defined action available for selection on the Enterprise Manager's Action tab (for a given scheduled task), add the replet.viewer.schedule.actions entry into sree.propertes. See User-Defined Action in Administration Reference for more information, and the example below.
The class below specifies a user-defined action called “MyAction.” The action executes a deployed report named “SomeReplet,” and exports the report to Excel format as C:\\SomeReplet.xls.
import inetsoft.sree.schedule.*;
import inetsoft.sree.*;
import inetsoft.sree.security.*;
import inetsoft.report.io.*;
import java.util.*;
import java.security.*;
import java.io.*;
public class MyAction extends DefaultUserAction implements RepletSupport {
public MyAction() {
super();
}
public MyAction(String replet) {
this.replet = replet;
}
public void run(Principal principal) throws Throwable {
FileOutputStream fos = null;
try {
final RepletRepository rr = SreeEnv.getRepletRepository();
final Object repletId = rr.createReplet(replet, principal, RepletRepository.REPLET);
RepletRequest request = getRepletRequest();
/*
...
Modify parameters here.
...
*/
rr.generateReplet(repletId, request);
final Object exportId = rr.export(repletId, Builder.EXCEL_DATA);
fos = new FileOutputStream("C:\\"+replet+".xls");
byte[] b = null;
while((b = rr.nextBlock(exportId)) != null) {
fos.write(b);
}
fos.flush();
}
catch(Exception e) {
e.printStackTrace();
throw new RepletException(e);
}
finally {
try {
fos.close();
}
catch(Exception e) {}
}
}
public String getRepletName() {
return replet;
}
public void setRepletName(String replet) {
this.replet = replet;
}
public String getLabel() {
return "MyAction";
}
private String replet = "SomeReplet";
}
To make the “MyAction” user-defined action available for selection in the Enterprise Manager's Action tab (for a given scheduled task), add the following line into the sree.propertes file.
replet.viewer.schedule.actions=MyAction
See Also
Scheduler Actions, in Administration Reference, to set a built-in or custom action in Enterprise Manager.
| << 3.6.1 User-Defined Conditions | © 1996-2013 InetSoft Technology Corporation (v11.4) | 3.7 Presenters >> |