I have below requiremnt,
First workflow image:- works fine Second Workflow Image : - But i want to to create ValidateRequest as a separate ServiceTask.How can achieve it ?
@RestController
public class MyTestRestController {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private ValidateRequest validateRequest;
@GetMapping("/order/{id}")
public String test(@PathVariable int id) throws Exception {
Map<String, Object> controlParameters = new HashMap<>();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("hello-world-process",controlParameters);
if (id == 1) {
controlParameters.put("errorFlag", true);
completeTask(processInstance, controlParameters);
throw new IllegalArgumentException(" Illegal Argument ");
}
controlParameters.put("errorFlag", false);
completeTask(processInstance, controlParameters);
return "Hello World";
}
@Service
public class ValidateRequest implements JavaDelegate{
@Override
public void execute(DelegateExecution exec) throws Exception {
// TODO Auto-generated method stub
int id =1;
System.out.println(" Starting ValidateRequest");
Thread.sleep(10000);
if(id==1)
{
throw new IllegalArgumentException(" Illegal Argument 2 " );
}
}
You need to move the code to a class implementing JavaDelegate Preferbaly this should be a Spring bean. See here: https://docs.camunda.org/get-started/spring/service-task/#invoke-a-spring-bean-from-a-bpmn-2-0-service-task
package org.camunda.bpm.getstarted.loanapproval;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
@Component
public class CalculateInterestService implements JavaDelegate {
public void execute(DelegateExecution delegate) {
System.out.println("Spring Bean invoked.");
}
}
Here is a more comprehensive example, showing different ways to manage paramaters for your service in the model: https://github.com/rob2universe/flexible-delegate/blob/main/src/main/java/com/camunda/example/service/LoggerDelegate.java