I have a process with several system task. Each task is calling an outside API to do some validation of data in those systems. If the validation fails, i will have to store the errors in an object in the camunda process. The error object will contain a list of ErrorSource (from which external system the error comes from), and each of the ErrorSource will contain a list of errors (string types).
So, how do I create and manipulate the object after each task. And, how is the object persisted if the camunda goes down, etc?
You want to set one or more process variables in your service task. Camunda stores them in the database as part of the respective process instance. Every service task can set process variables. In a Java Delegate:
public class MyServiceTaskDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
HttpConnector http = Connectors.getConnector(HttpConnector.ID);
HttpResponse httpResponse = http.createRequest()
.post()
.url("http://api.example.com/validate")
.contentType("application/json")
.payload(jsonString)
.execute();
String body = httpResponse.getResponse();
// extract error object from body
execution.setVariable("errorObject", errorObject);
}
}
My problem is that I am only able to put String, etc on the process, as you describe. If I try to put an custom object, as the ErrorSource over, I get an error like I have described here:
I have to use delegate expression, because spring boot autowiring doesnt work with java delegate. But, even if I use java delegate or delegate expression, the class I delegate to, is not able to put objects on the process instance.
The java class is set up like this: @Component(“getCaseworkDelegate”)
public class GetCaseworkDelegate implements JavaDelegate {
Int the system task in BPMN, i have added the javaDelegate like this:
<bpmn:serviceTask id=“Task_0ftz2se” name=“Get Casework” camunda:delegateExpression="${getCaseworkDelegate}"> bpmn:incomingSequenceFlow_07l4vts</bpmn:incoming> bpmn:outgoingSequenceFlow_036djz4</bpmn:outgoing>
</bpmn:serviceTask>
Everything works fine, except when i try to add a custom (homemade) object to the process, like this:
TestDTO testDTO = new TestDTO();
execution.setVariable(“TestDTO”, testDTO);