How do I add and call a custom Java class inside a jBPM Process?

后端 未结 1 1487
灰色年华
灰色年华 2021-01-22 08:41

I have a local jBPM 7.33 with a simple process. At one point in the process, I need to generate a PDF file.

I want to do it by creating a very basic Java class that is

相关标签:
1条回答
  • 2021-01-22 08:49

    that's what we call it WorkItemHandler , your java class will be a customized jbpm task

    1. First of all install jbpm in eclipse

    2. Create a jBPM project in eclipse (tick Build the project using Maven)

    3. 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 ! ");
      
          }
      
      }
      
    4. Build a jar file of this project.

    5. From the workbench, go to Artifact, upload the jar
      click on this icon, then artifacts

    6. from the settings of your project, go to dependencies, and add from repository the uploaded artifact

    7. 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())

    8. 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"
      ]
    
    1. you can now find this task in "service tasks" of your workflow designer tool (refresh before)
    0 讨论(0)
提交回复
热议问题