Search in sources :

Example 1 with StartProcess

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;
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) StartProcess(org.camunda.bpm.engine.spring.annotations.StartProcess) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Method(java.lang.reflect.Method) AsyncResult(org.springframework.scheduling.annotation.AsyncResult)

Aggregations

Method (java.lang.reflect.Method)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 StartProcess (org.camunda.bpm.engine.spring.annotations.StartProcess)1 AsyncResult (org.springframework.scheduling.annotation.AsyncResult)1