Search in sources :

Example 6 with ProcessEngineCdiException

use of org.camunda.bpm.engine.cdi.ProcessEngineCdiException in project camunda-bpm-platform by camunda.

the class CompleteTaskInterceptor method invoke.

@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception {
    try {
        Object result = ctx.proceed();
        CompleteTask completeTaskAnnotation = ctx.getMethod().getAnnotation(CompleteTask.class);
        boolean endConversation = completeTaskAnnotation.endConversation();
        businessProcess.completeTask(endConversation);
        return result;
    } catch (InvocationTargetException e) {
        throw new ProcessEngineCdiException("Error while completing task: " + e.getCause().getMessage(), e.getCause());
    }
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) CompleteTask(org.camunda.bpm.engine.cdi.annotation.CompleteTask) InvocationTargetException(java.lang.reflect.InvocationTargetException) AroundInvoke(javax.interceptor.AroundInvoke)

Example 7 with ProcessEngineCdiException

use of org.camunda.bpm.engine.cdi.ProcessEngineCdiException in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetCachedLocalVariableMap.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testGetCachedLocalVariableMap() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedLocalVariableMap());
    // set a variable - this should fail before the process is started
    try {
        businessProcess.setVariableLocal("aVariableName", "aVariableValue");
        fail("exception expected!");
    } catch (ProcessEngineCdiException e) {
        assertEquals("Cannot set a local cached variable: neither a Task nor an Execution is associated.", e.getMessage());
    }
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getCachedLocalVariableMap());
    // set a variable
    businessProcess.setVariableLocal("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getCachedLocalVariableMap());
    // getting the variable cache does not empty it:
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getCachedLocalVariableMap());
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with ProcessEngineCdiException

use of org.camunda.bpm.engine.cdi.ProcessEngineCdiException in project camunda-bpm-platform by camunda.

the class BusinessProcessBeanTest method testGetVariableLocalCache.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
@SuppressWarnings("deprecation")
public void testGetVariableLocalCache() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    // initially the variable cache is empty
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableLocalCache());
    // set a variable - this should fail before the process is started
    try {
        businessProcess.setVariableLocal("aVariableName", "aVariableValue");
        fail("exception expected!");
    } catch (ProcessEngineCdiException e) {
        assertEquals("Cannot set a local cached variable: neither a Task nor an Execution is associated.", e.getMessage());
    }
    businessProcess.startProcessByKey("businessProcessBeanTest");
    // now the variable cache is empty again:
    assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableLocalCache());
    // set a variable
    businessProcess.setVariableLocal("anotherVariableName", "aVariableValue");
    // now the variable is set
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableLocalCache());
    // getting the variable cache does not empty it:
    assertEquals(Collections.singletonMap("anotherVariableName", "aVariableValue"), businessProcess.getVariableLocalCache());
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 9 with ProcessEngineCdiException

use of org.camunda.bpm.engine.cdi.ProcessEngineCdiException in project camunda-bpm-platform by camunda.

the class DefaultContextAssociationManager method setExecution.

@Override
public void setExecution(Execution execution) {
    if (execution == null) {
        throw new ProcessEngineCdiException("Cannot associate with execution: null");
    }
    ensureCommandContextNotActive();
    ScopedAssociation scopedAssociation = getScopedAssociation();
    Execution associatedExecution = scopedAssociation.getExecution();
    if (associatedExecution != null && !associatedExecution.getId().equals(execution.getId())) {
        throw new ProcessEngineCdiException("Cannot associate " + execution + ", already associated with " + associatedExecution + ". Disassociate first!");
    }
    if (log.isLoggable(Level.FINE)) {
        log.fine("Associating " + execution + " (@" + scopedAssociation.getClass().getAnnotations()[0].annotationType().getSimpleName() + ")");
    }
    scopedAssociation.setExecution(execution);
}
Also used : ProcessEngineCdiException(org.camunda.bpm.engine.cdi.ProcessEngineCdiException) Execution(org.camunda.bpm.engine.runtime.Execution)

Aggregations

ProcessEngineCdiException (org.camunda.bpm.engine.cdi.ProcessEngineCdiException)9 BusinessProcess (org.camunda.bpm.engine.cdi.BusinessProcess)7 Deployment (org.camunda.bpm.engine.test.Deployment)7 Test (org.junit.Test)7 Task (org.camunda.bpm.engine.task.Task)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AroundInvoke (javax.interceptor.AroundInvoke)1 CompleteTask (org.camunda.bpm.engine.cdi.annotation.CompleteTask)1 Execution (org.camunda.bpm.engine.runtime.Execution)1