Search

Chapter 60. Work item handler project customization

download PDF

You can customize the code of a work item handler project. There are two Java methods required by a work item handler, executeWorkItem and abortWorkItem.

Table 60.1. Java method descriptions
Java MethodDescription

executeWorkItem(WorkItem workItem, WorkItemManager manager)

Executed by default when the work item handler is run.

abortWorkItem(WorkItem workItem, WorkItemManager manager)

Executed when the work item is aborted.

In both methods, the WorkItemDefinition parameter contains any of the parameters entered into the custom task through a GUI or API call, and the WorkItem parameter is responsible for tracking the state of the custom task.

Example code structure

public class MyWorkItemWorkItemHandler extends AbstractLogOrThrowWorkItemHandler {

  public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    try {
      RequiredParameterValidator.validate(this.getClass(), workItem);

      // sample parameters
      String sampleParam = (String) workItem.getParameter("SampleParam");
      String sampleParamTwo = (String) workItem.getParameter("SampleParamTwo");

      // complete workitem impl...

      // return results
      String sampleResult = "sample result";
      Map<String, Object> results = new HashMap<String, Object>();
      results.put("SampleResult", sampleResult);
      manager.completeWorkItem(workItem.getId(), results);
    } catch(Throwable cause) {
      handleException(cause);
    }
	}

	@Override
	public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
    // similar
	}
}

Table 60.2. Parameter descriptions
ParameterDescription

RequiredParameterValidator.validate(this.getClass(), workItem);

Checks that all parameters marked “required” are present. If they are not, an IllegalArgumentException is thrown.

String sampleParam = (String) workItem.getParameter("SampleParam");

Example of getting a parameter from the WorkItem class. The name is always a string. For example, WorkItem. In the example, SampleParam is always a string but the object associated with it can be many things and require a cast in order to avoid errors.

// complete workitem impl…

Executes the custom Java code when a parameter is received.

results.put("SampleResult", sampleResult);

Passes results to the custom task. The results are placed in the data output areas of the custom task.

manager.completeWorkItem(workItem.getId(), results);

Marks the work item handler as complete. The WorkItemManager controls the state of the work item and is responsible for getting the WorkItem ID and associate the results with the correct custom task.

abortWorkItem()

Aborts the custom Java code. May be left blank if the work item is not designed to be aborted

Note

Red Hat Process Automation Manager includes a limited set of supported custom tasks. Custom tasks that are not included in Red Hat Process Automation Manager are not supported.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.