Developing custom policies

To use the custom policy review API to write policies, you must first create a policy governor. To add the custom policies, the policy governor must include a reference to each custom policy. You set up a policy governor class and policy implementation, and then add the policy governor to your repository.

Before you begin

Procedure

  1. Set up the project:
    1. Create a Java project for your custom policy. You can use the sample policy governor and the policies in the SampleGovernor.jar file to get started by importing them into your project and modifying them to create custom policies.
    2. Import the sample policy governor into the /src subdirectory of the project, by right-clicking the project and selecting Import.
    3. Select Archive File and click Next.
    4. Click Browse and select the SampleGovernor archive file.
    5. Click Finish. The contents are added to your new project.
  2. Add the dependencies to your build path: You must specify each JAR file that is included in the RAM Java API (in the ramclient.zip file) individually in the class path. The name of the JAR file name in the class path must include the full name, for example: org.eclipse.emf.ecore.xmi_2.4.1.v200902171115.jar.
    1. To import files from the ramclient archive, you can download the archive from the Extensions page. To open that page, click the Help icon and then click Extensions.
    2. Extract the ram.client archive contents to add the required files to your new project.
    3. Right-click the project and select Build Path > Add External Archives.
    4. Navigate to where you extracted the ramclient.zip file and select all the com.ibm.ram.common,ramclient, jaxb, and org.eclipse JAR files. You must include the following JAR files:
      com.ibm.ram.common
      ramclient
      jaxb-api
      jaxb-impl
      org.eclipse.emf.common
      org.eclipse.emf.ecore.xmi
      org.eclipse.emf.ecore
      org.eclipse.equinox.common
      org.eclipse.osgi
      In V 7.5 and earlier, you must add the following JAR files to your class path:
      • From your installation of the product (WebSphere_INSTALL_Directory\profiles\<PROFILE>\installedApps\<APPLICATION>\com.ibm.ram.repository.web.war\WEB-INF\lib):
        com.ibm.ram.common.jar
      • From WebSphere Application Server (WebSphere_INSTALL_Directory\plugins):
        org.eclipse.emf.common.jar
        org.eclipse.emf.commonj.sdo.jar
        org.eclipse.emf.ecore.jar
        org.eclipse.emf.ecore.change.jar
        org.eclipse.emf.ecore.sdo.jar
        org.eclipse.emf.ecore.xmi.jar
  3. Write the policies:
    1. You can create a policy with or without extending one of the supplied policies, such as MyPolicy. You can use methods in a supplied policy file and change the methods. For example, in the test() method, you can approve or fail an asset policy test depending on a specific set of asset type details for your governance model.

      For information on what APIs you can use in writing custom policies, see APIs to use in custom policies

      Note: You can store policies in a map and get a policy by ID; for example, private Map policies;. To retrieve a policy from the map, enter the policy ID in the getPolicies().get(id) method.
    2. In the Governor class, add a reference to each new policy. Your Governor class must include a reference to each custom policy in the policy governor. For example, for MyPolicy, these lines are added to the MyGovernor class (in MyGovernor.java):
      	//My XML Policy
      		Policy policy = new MyPolicy(this);
      		policies.put(policy.getID(), policy);

      You can use the Rational Asset Manager Java APIs to work with the current asset and other assets within a custom policy. For examples on how to use the Java APIs, see: Using Rational Asset Manager Java API. Examples and additional information about the APIs you can use are on the custom policies wiki page on jazz.net

  4. Install the policies. You package your custom policies by exporting the project as a JAR file and then adding it as a new policy extension.
    1. Export the project as a JAR file.
      When you save your package as an Eclipse project, you must also include these JAR files, which are required for using the Rational Asset Manager Java APIs in a policy:
      • On WebSphere Application Server:
        • axis.jar
        • jaxrpc.jar
        • ramclient.jar
        • saaj.jar
        • wsdl47-1.5.1.jar
      • On Tomcat:
        • ramclient.jar
        • org.eclipse.equinox.common (for IProgressMonitor)

      In version 7.5.0.1 and later, you can include multiple JAR files (such as ramclient.jar and the policy JAR) as a .zip file when you upload a policy.

    2. Log in to the product as a repository administrator.
    3. On the Administration page, click Custom Extensions.
    4. Add a new policy extension.
    5. Enter the fully qualified class name (package and class) of your policy governor.
    6. Browse to the JAR file that you exported in step 4a. Your policy is available to use in a lifecycle or policy process.
    For additional instructions on how to add your governor, see Defining external policy governors.

What to do next

Test and debug your policy. For instructions, see Testing and debugging policies.

Feedback