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());
}
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());
}
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());
}
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;
}
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;
}
Aggregations