use of org.camunda.bpm.engine.spring.annotations.StartProcess in project camunda-bpm-platform by camunda.
the class ProcessStartingMethodInterceptor method invoke.
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
StartProcess startProcess = AnnotationUtils.getAnnotation(method, StartProcess.class);
String processKey = startProcess.processKey();
Assert.hasText(processKey, "you must provide the name of process to start");
Object result;
try {
result = invocation.proceed();
Map<String, Object> vars = this.processVariablesFromAnnotations(invocation);
String businessKey = this.processBusinessKey(invocation);
log.info("variables for the started process: " + vars.toString());
RuntimeService runtimeService = this.processEngine.getRuntimeService();
ProcessInstance pi;
if (null != businessKey && StringUtils.hasText(businessKey)) {
pi = runtimeService.startProcessInstanceByKey(processKey, businessKey, vars);
log.info("the business key for the started process is '" + businessKey + "' ");
} else {
pi = runtimeService.startProcessInstanceByKey(processKey, vars);
}
String pId = pi.getId();
if (invocation.getMethod().getReturnType().equals(void.class))
return null;
if (shouldReturnProcessInstance(startProcess, invocation, result))
return pi;
if (shouldReturnProcessInstanceId(startProcess, invocation, result))
return pId;
if (shouldReturnAsyncResultWithProcessInstance(startProcess, invocation, result)) {
return new AsyncResult<ProcessInstance>(pi);
}
} catch (Throwable th) {
throw new RuntimeException(th);
}
return result;
}
Aggregations