Version 9.6
 —  Run-Time Governance Reference  —

Computed Runtime Actions

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 CentraSiteBUIExtension 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 under:

<CentraSiteInstallDir>\demos

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 following topics are discussed in this document:

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 Guidelines for Computed Runtime Action

In order to create, install and use plug-ins, you must perform the following tasks:

This section does not explain all the details of the Java source file; its purpose is to indicate the code that must be modified to suit your environment.

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 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 instnace 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(actionInfo.getId());
		} else {
			policyActionInstance = objectManager.createPolicyActionInstance(actionInfo.getId());
		}
		
		if (policyActionInstance == null) {
			return null;
		}
		
		setParameterValues(policyActionInstance, actionInfo);
		return policyActionInstance; 
	}

	private void setParameterValues(CentraSitePolicyActionInstance policyActionInstance,
			MyComputedRuntimeActionInfo actionInfo) throws CLLException {
		List<MyComputedRuntimeParameterInfo> parameters = actionInfo.getParameters();
		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().getId(), policyActionTemplate.getName());
			actionInfo.setActionId(policyActionTemplate.getId());
			actionInfo.setIsActionInstance(true);
		} else if (getActionTemplate() != null) {
			actionInfo = new MyComputedRuntimeActionInfo(getActionTemplate().getId(), 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.getAttributes();
		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);
	}
}

Setting up the Computed Action Plug-in

The following diagram describes the main methods on each of the two Java source files MyComputedRuntimeActionWidget.java and MyComputedRuntimeActionParser.java and describes the type of functions that they serve.

# Description

graphics/sym_1.png

The getPolicyActionJson method returns the JavaScript Object (JSO) from the given JSON-formatted string.

graphics/sym_2.png

The getActionInstance method returns a CentraSitePolicyActionInstance object from the given JSON-formatted string.

graphics/sym_3.png

The String getJson method returns a JSON-formatted string from the existing policy action action instance.

graphics/sym_4.png

The boolean isValid() method enforces a validation logic for the user-defined rendering of the runtime action.

Assuming that you have set up all the Java files correctly in the directories, you should be able to build with the command:

ant -f build.xml jar all

Activating the Computed Action

After you define the computed action as a plug-in (extension point) with the above steps, enable the computed action in the Business UI configuration file centrasite.xml in order to display the action in the policy accordion.

Important:
Remember that the action parameters defined in the configuration file are editable and cannot be protected.

Start of instruction setTo activate the plug-in

  1. Open the centrasite.xml file.

    The configuration file is located in the cast\cswebapps\BusinessUI\system\conf directory.

  2. Navigate to the property lines <UIProperties> -> <Extensions> -> <PolicyActions>

  3. Append the property statement for your custom computed runtime action ("MyComputedRuntimeAction") as below:

    <PolicyActions>
       <PolicyAction id="uddi:44e3e2de-064c-432f-b67a-8fbca0fb04d6" class="com.softwareag.centrasite.bui.extension.service.MyComputedRuntimeActionParser" />
    </PolicyActions>

    wherein,

    Parameter Description
    id

    A unique identifier for the computed action.

    It uniquely distinguishes an action in the CentraSite registry. If you wish to reconfigure the action at a later stage, you identify the action using this id.

    class

    A parser implementation for the computed action.

  4. Save and close the configuration file.

  5. Restart Software AG Runtime.

Sample Computed Runtime Action

Your CentraSite installation contains a sample computed runtime action (which is contained in demos folder) that you can use to create an archive file for the custom runtime action specific to the CentraSite Business UI.

Top of page