CentraSite 10.7 | CentraSite Developer's Guide | Custom Policy Actions | Custom Policy Actions | Sample Java Action: Enforce Unique Asset Names
 
Sample Java Action: Enforce Unique Asset Names
You can use the sample Java class action rule uniquenamechecker that is present in the CentraSite installation to create a custom action, Unique Name Checker. This action ensures that the name and version combination of a newly-created asset is unique within the CentraSite catalog.
Note:
If the name and version combination of a newly-created asset is not unique, then the action returns a Failure message, and does not create the new asset in CentraSite registry.
To create the custom action, you have to:
1. Create a custom action category.
2. Create a custom action template, to which you upload the sample Java rule.
3. Create a Design/Change-Time policy and add the custom action template to it.
*To create and test the custom action Enforce Unique Asset Names
1. In CentraSite Control, go to Policies > Action Templates.
2. Click the Add Action Category button.
3. In the Add Action Category dialog box, do the following:
a. Specify a name for the new custom category, for example My Custom Actions. An action category name can contain any character (including spaces).
b. Select Design/Change-Time as the action category type.
c. Click OK.
The action category that you created appears as a custom category next to an icon in the Policy Information panel.
4. Click Add Action Template.
5. In the Add Action Template page, specify the following information:
In this field...
Do the following...
Category
Select the custom action category you just created.
Name
Type the name Enforce Unique Asset Names for the new action template.
Description
(Optional). Type a description for the new action template. For example: Ensures that asset names are unique.
Uploaded File
Click Browse and upload the Java class action rule:
<CentraSiteInstall_Directory>\demos\CustomActions\Java\uniquenamechecker.zip
6. In the Scope panel, specify the following information:
In this field...
Do the following...
Object Types
Select Service as the type of object to which this action template applies.
Event Types
Select Pre-Create as the type of event to which this action template applies.
7. Click Save.
The Edit Action Template Detail page is displayed.
8. Create a policy and add the sample action to the policy as follows:
a. In CentraSite Control, go to Policies > Design/Change Time.
b. Click Add Policy.
c. In the Policy Information panel, type a name for the new policy, for example, Ensure Unique Asset Names Policy. A policy name can contain any character (including spaces).
d. In the Scope panel, specify the object and event types to which the policy applies as follows:
*In the Object Types field, select Service as the type of object to which this policy applies.
*In the Event Types field, select Pre-Create as the type of event to which this policy applies.
*In the Organization field, select your organization name as the organization to which this policy belongs (and to whose objects the policy is applied).
e. Click Next.
f. From the Available Actions list, select the custom action Enforce Unique Asset Names action that you created.
g. Click Finish to save the new policy.
The Design/Change-Time Policy Details page is displayed.
h. Activate the policy by clicking the Change State button and selecting the Productive state.