Search in sources :

Example 1 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class ProcessVariableMapTest method testProcessVariableMapLocal.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testProcessVariableMapLocal() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    businessProcess.startProcessByKey("businessProcessBeanTest");
    VariableMap variables = (VariableMap) getBeanInstance("processVariableMapLocal");
    assertNotNull(variables);
    // /////////////////////////////////////////////////////////////////
    // Put a variable via BusinessProcess and get it via VariableMap //
    // /////////////////////////////////////////////////////////////////
    String aValue = "aValue";
    businessProcess.setVariableLocal(VARNAME_1, Variables.stringValue(aValue));
    // Legacy API
    assertEquals(aValue, variables.get(VARNAME_1));
    // Typed variable API
    TypedValue aTypedValue = variables.getValueTyped(VARNAME_1);
    assertEquals(ValueType.STRING, aTypedValue.getType());
    assertEquals(aValue, aTypedValue.getValue());
    assertEquals(aValue, variables.getValue(VARNAME_1, String.class));
    // Type API with wrong type
    try {
        variables.getValue(VARNAME_1, Integer.class);
        fail("ClassCastException expected!");
    } catch (ClassCastException ex) {
        assertEquals("Cannot cast variable named 'aVariable' with value 'aValue' to type 'class java.lang.Integer'.", ex.getMessage());
    }
    // /////////////////////////////////////////////////////////////////
    // Put a variable via VariableMap and get it via BusinessProcess //
    // /////////////////////////////////////////////////////////////////
    String anotherValue = "anotherValue";
    variables.put(VARNAME_2, Variables.stringValue(anotherValue));
    // Legacy API
    assertEquals(anotherValue, businessProcess.getVariableLocal(VARNAME_2));
    // Typed variable API
    TypedValue anotherTypedValue = businessProcess.getVariableLocalTyped(VARNAME_2);
    assertEquals(ValueType.STRING, anotherTypedValue.getType());
    assertEquals(anotherValue, anotherTypedValue.getValue());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class ProcessVariableTypedTest method testProcessVariableTypeAnnotation.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testProcessVariableTypeAnnotation() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    VariableMap variables = Variables.createVariables().putValue("injectedValue", "camunda");
    businessProcess.startProcessByKey("keyOfTheProcess", variables);
    TypedValue value = getBeanInstance(DeclarativeProcessController.class).getInjectedValue();
    assertNotNull(value);
    assertTrue(value instanceof StringValue);
    assertEquals(ValueType.STRING, value.getType());
    assertEquals("camunda", value.getValue());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) DeclarativeProcessController(org.camunda.bpm.engine.cdi.test.impl.beans.DeclarativeProcessController) StringValue(org.camunda.bpm.engine.variable.value.StringValue) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 3 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class ProcessVariableLocalTypedTest method testProcessVariableLocalTypeAnnotation.

@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testProcessVariableLocalTypeAnnotation() {
    BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
    VariableMap variables = Variables.createVariables().putValue("injectedLocalValue", "camunda");
    businessProcess.startProcessByKey("keyOfTheProcess", variables);
    TypedValue value = getBeanInstance(DeclarativeProcessController.class).getInjectedLocalValue();
    assertNotNull(value);
    assertTrue(value instanceof StringValue);
    assertEquals(ValueType.STRING, value.getType());
    assertEquals("camunda", value.getValue());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) DeclarativeProcessController(org.camunda.bpm.engine.cdi.test.impl.beans.DeclarativeProcessController) StringValue(org.camunda.bpm.engine.variable.value.StringValue) BusinessProcess(org.camunda.bpm.engine.cdi.BusinessProcess) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class StartProcessInterceptor method extractVariables.

private Map<String, Object> extractVariables(StartProcess startProcessAnnotation, InvocationContext ctx) throws Exception {
    VariableMap variables = new VariableMapImpl();
    for (Field field : ctx.getMethod().getDeclaringClass().getDeclaredFields()) {
        if (!field.isAnnotationPresent(ProcessVariable.class) && !field.isAnnotationPresent(ProcessVariableTyped.class)) {
            continue;
        }
        field.setAccessible(true);
        String fieldName = null;
        ProcessVariable processStartVariable = field.getAnnotation(ProcessVariable.class);
        if (processStartVariable != null) {
            fieldName = processStartVariable.value();
        } else {
            ProcessVariableTyped processStartVariableTyped = field.getAnnotation(ProcessVariableTyped.class);
            fieldName = processStartVariableTyped.value();
        }
        if (fieldName == null || fieldName.length() == 0) {
            fieldName = field.getName();
        }
        Object value = field.get(ctx.getTarget());
        variables.put(fieldName, value);
    }
    return variables;
}
Also used : Field(java.lang.reflect.Field) VariableMapImpl(org.camunda.bpm.engine.variable.impl.VariableMapImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessVariable(org.camunda.bpm.engine.cdi.annotation.ProcessVariable) ProcessVariableTyped(org.camunda.bpm.engine.cdi.annotation.ProcessVariableTyped)

Example 5 with VariableMap

use of org.camunda.bpm.engine.variable.VariableMap in project camunda-bpm-platform by camunda.

the class BusinessProcess method startProcessByKey.

public ProcessInstance startProcessByKey(String key, String businessKey, Map<String, Object> variables) {
    assertCommandContextNotActive();
    VariableMap cachedVariables = getAndClearCachedVariableMap();
    cachedVariables.putAll(variables);
    ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey(key, businessKey, cachedVariables);
    if (!instance.isEnded()) {
        setExecution(instance);
    }
    return instance;
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Aggregations

VariableMap (org.camunda.bpm.engine.variable.VariableMap)230 Deployment (org.camunda.bpm.engine.test.Deployment)107 Test (org.junit.Test)59 Task (org.camunda.bpm.engine.task.Task)38 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)32 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)30 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)15 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)13 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)13 HashMap (java.util.HashMap)12 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)9 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)8 RestException (org.camunda.bpm.engine.rest.exception.RestException)8 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)8 Execution (org.camunda.bpm.engine.runtime.Execution)8 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)7 ThrowErrorDelegate (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate)7