Chapter 6. Registering custom tasks

Red Hat Process Automation Manager must know how to associate a custom task work item with the code executed by the work item handler. The work item definition file links the custom task with the work item handler by name and Java class. The work item handler’s Java class has to be registered as usable in Red Hat Process Automation Manager.

Note

Service repositories contain domain-specific services that provide integration of your processes with different types of systems. Registering a custom task is not necessary when using a service repository because the import process registers the custom task.

Red Hat Process Automation Manager creates a WID file by default for projects that contain at least one business process. You can create a WID file when registering a work item handler or edit the default WID file. For more information about WID file locations or formatting, see Chapter 4, Work item definitions.

For non-service repository deployments, work item handlers can be registered in two ways:

  • Registering using the deployment descriptor.
  • Registering using the spring component registration.

6.1. Registering custom tasks using the deployment descriptor inside Business Central

You can register a custom task work item with the work item handler using the deployment descriptor in Business Central.

Procedure

  1. In Business Central, go to MenuDesignProjects and select the project name.
  2. In the project pane, select SettingsDeploymentsWork Item Handlers.
  3. Click Add Work Item Handler.
  4. In the Name field, enter the display name for the custom task.
  5. From the Resolver list, select MVEL, Reflection or Spring.
  6. In the Value field, enter the value based on the resolver type:

    • For MVEL, use the format new <full Java package>.<Java work item handler class name>()

      Example: new com.redhat.MyWorkItemWorkItemHandler()

    • For Reflection, use the format <full Java package>.<Java work item handler class name>

      Example: com.redhat.MyWorkItemWorkItemHandler

    • For Spring, use the format <Spring bean identifier>

      Example: workItemSpringBean

  7. Click Save to save your changes

6.2. Registering custom tasks using the deployment descriptor outside Business Central

You can register a custom task work item with the work item handler using the deployment descriptor outside Business Central.

Procedure

  1. Open the file src/main/resources/META-INF/kie-deployment-descriptor.xml.
  2. Add the following content based on the resolver type under <work-item-handlers>:

    • For MVEL, add the following:

      <work-item-handler>
        <resolver>mvel</resolver>
        <identifier>new com.redhat.MyWorkItemWorkItemHandler()</identifier>
        <parameters/>
        <name>MyWorkItem</name>
      </work-item-handler>
    • For Reflections, add the following:

      <work-item-handler>
        <resolver>reflection</resolver>
        <identifier>com.redhat.MyWorkItemWorkItemHandler</identifier>
        <parameters/>
        <name>MyWorkItem</name>
      </work-item-handler>
    • For Spring, add the following and ensure the identifier is the identifier of a Spring bean:

      <work-item-handler>
        <resolver>spring</resolver>
        <identifier>beanIdentifier</identifier>
        <parameters/>
        <name>MyWorkItem</name>
      </work-item-handler>
      Note

      If you are using Spring to discover and configure Spring beans, it is possible to use an annotation of the org.springframework.stereotype.Component class to automatically register work item handlers.

      Within a work item handler, add the annotation @Component("<Name>") before the declaration of the work item handler class. For example: @Component("MyWorkItem") public class MyWorkItemWorkItemHandler extends AbstractLogOrThrowWorkItemHandler {