that's what we call it WorkItemHandler
, your java class will be a customized jbpm task
First of all install jbpm in eclipse
Create a jBPM project in eclipse (tick Build the project using Maven)
create a java class that implements WorkItemHandler
. it will be in this format.
package com.example;
import org.kie.api.runtime.process.WorkItem;
import java.util.HashMap;
import java.util.Map;
import org.drools.core.process.instance.WorkItemHandler;
import org.kie.api.runtime.process.WorkItemManager;
public class WorkItemTest implements WorkItemHandler {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
workItem.getParameters().toString();
/**Input Variables***/
String stringVar = (String) workItem.getParameter("stringVar");
/***
*
*
* YOUR CODE
*
*/
String msg = "done";
/**Output Variables in a HashMap***/
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("Result", msg); //("name of variable", value)
manager.completeWorkItem(workItem.getId(), resultMap);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println("Aborted ! ");
}
}
Build a jar file of this project (with maven).
From the workbench, go to Artifact, upload the jar
click on this icon, then artifacts
from the settings of your project, go to dependencies, and add from repository the uploaded artifact
from the settings of your project, go to Deployments / Work Item Handler and add a new work Item Handler : type its name and how to instantiate it (new com.example.WorkItemTest()
)
Finally, go to the Asset "WorkDefinitions" , define your work item (so you can see it in the workflow designer tool) as follow
[
"name" : "WorkItemTest",
"parameters" : [ //inputs
"stringVar " : new StringDataType(),
],
"results" : [ //outputs
"Result" : new ObjectDataType(),
],
"displayName" : "WorkItemTest",
"icon" : "defaultservicenodeicon.png"
]
- you can now find this task in "service tasks" of your workflow designer tool (refresh before)