CentraSite 10.7 | CentraSite Developer's Guide | Custom Policy Actions | Computed Run-Time Actions
 
Computed Run-Time Actions
 
Computed Run-Time Action Plug-in
Activating the Computed Run-Time Action
Sample Computed Run-Time Action
CentraSite Business UI offers you the possibility to add computed runtime actions into the policy workflow; this gives you the option to define your own runtime action, which means that you can implement your own algorithms for representing the action's user interface.
Computed runtime actions let you create your own layout by using a UI Rendering Concept. You can also specify your own rendering logic to display the computed values. You could, for example, create a custom display of the attribute as a drop down or a radio button.
A computed runtime action can be implemented using the GWT framework. For a computed runtime action, you create an archive file that contains the plug-in definition, and you load the archive file in the CentraSite BUIExtension folder.
Writing Your Own Computed Runtime Action
A computed runtime action can be implemented as a plug-in. The prepared plug-in is a collection of files in a specific directory structure. After implementing the plug-in, the files are copied into the CentraSiteBUIExtension folder in <CentraSiteInstall_Directory>\demos directory.
In the following sections, we demonstrate a sample framework named MyComputedRuntimeAction that illustrates how a custom computed runtime action may be set up.
You may use this sample as a guideline, adapting it and renaming it to suit your individual requirements. The sample indicates where customization is required.
The Build Environment
This section explains the build environment for generating the files that are used for the GUI and for compiling the necessary Java source files. It assumes the use of Ant, the Java-based build tool.
The following file system structure under the computed runtime action directory is assumed:
Name of File or Folder
Description
src
This folder that holds the Java source files.
lib
This folder contains the archive file, plug-in's executor class and the external libraries.
build.xml
The Ant input file for building the destination files
The Ant file,build.xml can be used to establish a custom computed profile.
The classpath for the build step must refer to all JAR files contained in the redist folder of the CentraSite installation. Add these JAR files to the build path of your java project also.
Implementation for Computed Action UI
src\com\softwareag\centrasite\bui\extension\client\runtime\action\MyComputedRuntimeActionWidget.java
public class MyComputedRuntimeActionWidget extends Composite {
private PolicyActionJSO policyActionJso = null;
private TextBox valueBox = null;
private static final String WARNING_CSS = "loginTextBoxErrorBorder";
 
public MyComputedRuntimeActionWidget(String policyActionJson) {
FlowPanel container = new FlowPanel();
initWidget(container);
 
policyActionJso = getPolicyActionJso(policyActionJson);
if (policyActionJso == null) {
Label helloLabel = new Label("The JSON content is empty");
container.add(helloLabel);
return;
}
 
//Render widgets
container.add(getParametersView(policyActionJso));
}
 
private Widget getParametersView(PolicyActionJSO policyActionJso) {
FlowPanel parametersContainer = new FlowPanel();
 
JsArray<ParameterJSO> parameters = policyActionJso.getParameters();
if (parameters == null) {
return parametersContainer;
}
 
for (int i = 0; i < parameters.length(); i++) {
parametersContainer.add(getParameterView(parameters.get(i)));
}
 
return parametersContainer;
}
private Widget getParameterView(ParameterJSO parameterJso) {
FlowPanel parameterContainer = new FlowPanel();
Label nameLabel = new Label(parameterJso.getName());
parameterContainer.add(nameLabel);
 
valueBox = new TextBox();
valueBox.setLayoutData(parameterJso.getId());
 
String[] values = parameterJso.getValues();
if (values != null && values.length > 0) {
valueBox.setValue(values[0]);
}
 
parameterContainer.add(valueBox);
return parameterContainer;
}
public static native PolicyActionJSO getPolicyActionJso(String json) /*-{
return eval('(' + json + ')');
}-*/;
public String getJson() {
JsArray<ParameterJSO> parameters = policyActionJso.getParameters();
ParameterJSO parameterJso = null;
if (parameters != null && parameters.length() > 0) {
parameterJso = parameters.get(0);
 
String[] values = {valueBox.getValue()};
parameterJso.setValues(values);
}
 
return policyActionJso.toJSON();
}
public boolean isValid() {
String value = valueBox.getValue();
boolean isValid = (value != null && !"".equals(value));
if (!isValid) {
valueBox.addStyleName(WARNING_CSS);
} else {
valueBox.removeStyleName(WARNING_CSS);
}
 
return isValid;
}
}
The MyComputedRuntimeActionWidget class extends the class Composite, which declares the basic rendering methods for the CentraSite Business user interface.
Implementations and Description
MyComputedRuntimeActionWidget(String policyActionJson)
Constructor dictates the user-defined rendering of the action's UI.
getPolicyActionJson
Returns the JSON object from the specified object.
String getJson()
Returns a JSON encoded string representing the action's parameters.
boolean isValid()
Enforces validation logic for the action's parameter values.
Implementation for Computed Action Parser
To implement your own computed runtime action with custom UI rendering, the parser (MyComputedRuntimeActionParser.java) must be located in the service directory. A parser is responsible for generating compressed JSON data from the given policy action instance, and creating a custom rendering of the action instance using the JSON data.
Here is the frame of the computed runtime action parser implementation:
src\com\softwareag\centrasite\bui\extension\service\ MyComputedRuntimeActionParser.java
public class MyComputedRuntimeActionParser extends
BasePolicyActionExtensionParser {
public MyComputedRuntimeActionParser(CentraSiteSession centraSiteSession,
CentraSitePolicyActionTemplate actionTemplate,
CentraSitePolicyActionInstance actionInstance) {
super(centraSiteSession, actionTemplate, actionInstance);
}
@Override
public CentraSitePolicyActionInstance getActionInstance(String json)
throws CLLException {
Gson gson = new Gson();
MyComputedRuntimeActionInfo = gson.fromJson(json,
MyComputedRuntimeActionInfo.class);
if (actionInfo == null) {
return null;
}
 
CentraSitePolicyActionInstance policyActionInstance = null;
CentraSiteObjectManager objectManager =
getCentraSiteSession().getCentraSiteObjectManager();
 
if (actionInfo.isActionInstance()) {
policyActionInstance = objectManager.getPolicyActionInstance(action
Info.getId());
} else {
policyActionInstance = objectManager.createPolicyActionInstance(act
ionInfo.getId());
}
 
if (policyActionInstance == null) {
return null;
}
 
setParameterValues(policyActionInstance, actionInfo);
return policyActionInstance;
}
private void setParameterValues(CentraSitePolicyActionInstance
policyActionInstance, MyComputedRuntimeActionInfo actionInfo)
throws CLLException {
List<MyComputedRuntimeParameterInfo> parameters = actionInfo.getParame
ters();
if (parameters == null || parameters.isEmpty()) {
return;
}
 
MyComputedRuntimeParameterInfo parameterInfo = parameters.get(0);
Collection<Object> convertedParameterValues = new ArrayList<Object>();
convertedParameterValues.addAll(parameterInfo.getValues());
policyActionInstance.setAttributeValue(parameterInfo.getId(),
convertedParameterValues);
}
@Override
public String getJson() throws CLLException {
Gson gson = new Gson();
 
MyComputedRuntimeActionInfo actionInfo = null;
if (getActionInstance() != null) {
CentraSitePolicyActionTemplate policyActionTemplate =
getActionInstance().getCentraSitePolicyActionTemplate();
actionInfo = new MyComputedRuntimeActionInfo(getActionInstance().g
etId(),
policyActionTemplate.getName());
actionInfo.setActionId(policyActionTemplate.getId());
actionInfo.setIsActionInstance(true);
} else if (getActionTemplate() != null) {
actionInfo = new MyComputedRuntimeActionInfo(getActionTemplate().g
etId(),
getActionTemplate().getName());
actionInfo.setActionId(getActionTemplate().getId());
}
 
fillParameterInfos(getActionTemplate(), actionInfo);
return (actionInfo != null ? gson.toJson(actionInfo) : null);
}
private void fillParameterInfos(CentraSitePolicyActionTemplate
actionTemplate,
MyComputedRuntimeActionInfo actionInfo) throws CLLException {
if (actionTemplate == null) {
return;
}
 
Collection<CentraSiteObjectAttribute> attributes = actionTemplate.getA
ttributes();
if (attributes == null || attributes.isEmpty()) {
return;
}
 
List<MyComputedRuntimeParameterInfo> parameters = new
ArrayList<MyComputedRuntimeParameterInfo>(attributes.size());
MyComputedRuntimeParameterInfo parameter = null;
for (CentraSiteObjectAttribute attribute : attributes) {
parameter = new MyComputedRuntimeParameterInfo(attribute.getName(),
attribute.getDisplayName());
parameters.add(parameter);
}
 
actionInfo.setParameters(parameters);
}
}