CentraSite Documentation : Runtime Governance with CentraSite : Run-Time Governance Reference : Computed Runtime Actions : Writing Your Own Computed Runtime Action : Implementation Guidelines for Computed Runtime Action : Implementation for Computed Action Parser
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);
}
}
Copyright © 2005-2015 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback