Domanda

We are modelling processes with bpm and executing said bpm with the camunda engine in a Spring environment. In one scenario I'd like to execute custom Java code in between two user tasks. My conclusion from reading much of the camunda documentation is, that I'm best off with the Service-Task concept.

I'd like to do two things, one is to store more than one process-variable with the service task and two is to dynamically define, which process variables map to which input parameter of the Service-Task

To my knowledge Camunda offers two ways of integrating Java Code with service tasks:

1.) Declare a Spring-Bean implementing the JavaDelegate interface. (The method gets a DelegateExecution as parameter). This one would allow me to store as many result-variables as I like but I see no option of defining a mapping process-variable -> input-variable.

2.) Declare a generic Spring bean to be accessible by camunda and define the method of that bean to be executed by the system task. This allows me top specify the process-variable -> input-variable pattern via bpm-definition but stores at most one result-variable.

So, is there a way to achieve both?

Clarification

To clarify my requirements, on occasion my system-tasks might detect an inconsistent state (in database or process variables). I would like the tasks to store an error-code (similar to error codes of programs "exit(1)") in the process variables so that following user tasks get the chance to correct the error. This error-code might as well be stored in a fixed location in the process variables, however I want to be able to put at least one "real result" in a designated location.

È stato utile?

Soluzione

You should be able to implement the behavior in a Spring bean that uses the current execution to read and update the variables.

You would wire the spring bean named myErrorHandler with a service task like this

<serviceTask id="checkError"
             camunda:expression="#{myErrorHandler.checkError(execution)}" />

The execution variable is available in the expression per default and points to an instance of DelegateExecution that gives you access to the current process variables.

The implementation of the Spring bean may look as follows:

@Component
public class MyErrorHandler {

  /**
   * Actual error handler invoked as service
   */
  public void checkError(DelegateExecution execution) {

    execution.getVariables(); // Map<String, Object> of variables

    execution.setVariable("errorCode", 500); // update variable
  }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top