To create a custom action programmatically, you perform the following high-level steps:
Create a custom action category and template.
To do this, you create a Java class that uses the
com.centrasite.jaxr.CentraSiteLifeCycleManager interface.
To view the Javadoc for this interface, see
Javadoc:
metamodelAPI.
Create a Java class action rule or a Groovy script action
rule.
See Creating Action
Rules.
Upload the action rule to the action template.
See Uploading Action Rules to
Action Templates.
If creating a rule in a Java class:
Create a Java action executor class that implements the com.softwareag.centrasite.policy.api.IActionExecutor interface. To view the Javadoc for this interface, see Javadoc: policyAPI.
Important:
The Java executor class must return an
AssertionResult object that contains the completion code
ResultStatus.SUCCESS
(if the action was
successful) or ResultStatus.FAILURE
(if the action
failed). There are other possible completion codes (for example,
ResultStatus.IN_PROCESS
), however, these codes are
used by internal processes and are not intended to be returned by
user-defined actions. Custom actions that you create must only return a
completion code of ResultStatus.SUCCESS
or
ResultStatus.FAILURE
. For more information, see
the Javadoc for the AssertionResult and
ResultStatus
classes.
Create a .zip file that contains the following:
A folder named lib
, which should contain a
jar file with the action’s executor class and the external libraries.
A folder named META-INF
, which should
contain a property file named assertion.properties
,
which is the build file for the action. It includes an entry of the following
format:
com.softwareag.centrasite.policy.rule.class=<fully_qualified_class_name>
Upload the .zip file, as described in Uploading Action Rules to Action Templates.
For example, the sample Java action rule provided in the your CentraSite installation has the following file structure:
<CentraSite_Install_Dir>\demos\Custom actions\Java\META-INF\assertions.properties
This is the build file for the action. It includes an entry of the following format: com.softwareag.centrasite.policy.rule.class=<fully_qualified_class_name>.
<CentraSite_Install_Dir>\demos\Custom actions\Java\src\com\softwareag\demo\actions\UniqueNameChecker.java
This is the sample source file for the action executor. You can modify this file as needed, and compile it using the build file.
<CentraSite_Install_Dir>\demos\Custom actions\Java\build.xml
This build file has the default target “zip”, which will compile the Java file, build a jar out of it and pack it as a zip file.
<CentraSite_Install_Dir>\demos\Custom actions\Java\uniquenamechecker.zip
This .zip file contains the following:
A folder named lib
, which contains a jar file
with the action’s executor class and the external libraries.
A folder named META-INF
, which contains the
property file assertion.properties, which is the build file for the
action
.
For more information about the sample Java action, see Sample Custom Actions.
If using a Groovy script rule:
Upload the .groovy file as described in Uploading Action Rules to Action Templates.
Before you upload a Java action rule, you must first create a .zip file as described in Creating Action Rules.
If you want to upload a Groovy script rule, the .groovy file can contain the following variables. You cannot upload external libraries.
Variable | Description |
---|---|
entity |
This represents the RegistryObject which is in the context. The following fields are available in this object:
|
policyContext |
The PolicyContext in which the policy is running. |
assertion |
The IAssertionInstance that is in execution. |
result |
The result object that has the status and message. Set the result.successMessage or result.failureMessage. Based on the message, the status is inferred. If you fail to set a message, the status will be treated as a successful execution with an empty message. |
To upload an action rule
There are two ways you can upload a rule’s .zip file or .groovy file to a custom action template:
If you are uploading the rule to a custom action template you created using the CentraSite UI, you upload the rule (either a Java .zip file or a .groovy file) when you create the action template, on the Add Action Template page. For procedures, see Adding an Action Template to the Action Category.
—OR—
If you are uploading the rule to a custom action template that you created programmatically, you upload the rule (either a Java .zip file or a .groovy file) using a JAXR-based call in the action template.