use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.
the class ProcessVariableMapTest method testProcessVariableMap.
@Test
public void testProcessVariableMap() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
VariableMap variables = (VariableMap) getBeanInstance("processVariableMap");
assertNotNull(variables);
// /////////////////////////////////////////////////////////////////
// Put a variable via BusinessProcess and get it via VariableMap //
// /////////////////////////////////////////////////////////////////
String aValue = "aValue";
businessProcess.setVariable(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.getVariable(VARNAME_2));
// Typed variable API
TypedValue anotherTypedValue = businessProcess.getVariableTyped(VARNAME_2);
assertEquals(ValueType.STRING, anotherTypedValue.getType());
assertEquals(anotherValue, anotherTypedValue.getValue());
}
use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.
the class StartProcessTest method testStartProcessByKey.
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/StartProcessTest.bpmn20.xml")
public void testStartProcessByKey() {
assertNull(runtimeService.createProcessInstanceQuery().singleResult());
getBeanInstance(DeclarativeProcessController.class).startProcessByKey();
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
assertNotNull(runtimeService.createProcessInstanceQuery().singleResult());
assertEquals("camunda", businessProcess.getVariable("name"));
TypedValue nameTypedValue = businessProcess.getVariableTyped("name");
assertNotNull(nameTypedValue);
assertTrue(nameTypedValue instanceof StringValue);
assertEquals(ValueType.STRING, nameTypedValue.getType());
assertEquals("camunda", nameTypedValue.getValue());
assertEquals("untypedName", businessProcess.getVariable("untypedName"));
TypedValue untypedNameTypedValue = businessProcess.getVariableTyped("untypedName");
assertNotNull(untypedNameTypedValue);
assertTrue(untypedNameTypedValue instanceof StringValue);
assertEquals(ValueType.STRING, untypedNameTypedValue.getType());
assertEquals("untypedName", untypedNameTypedValue.getValue());
assertEquals("typedName", businessProcess.getVariable("typedName"));
TypedValue typedNameTypedValue = businessProcess.getVariableTyped("typedName");
assertNotNull(typedNameTypedValue);
assertTrue(typedNameTypedValue instanceof StringValue);
assertEquals(ValueType.STRING, typedNameTypedValue.getType());
assertEquals("typedName", typedNameTypedValue.getValue());
businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());
businessProcess.completeTask();
}
use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.
the class AbstractVariablesResource method putVariable.
@Override
public void putVariable(String variableName, VariableValueDto variable) {
try {
TypedValue typedValue = variable.toTypedValue(engine, objectMapper);
setVariableEntity(variableName, typedValue);
} catch (RestException e) {
throw new InvalidRequestException(e.getStatus(), e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
} catch (BadUserRequestException e) {
throw new RestException(Status.BAD_REQUEST, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
throw new RestException(Status.INTERNAL_SERVER_ERROR, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
}
}
use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.
the class AbstractVariablesResource method setBinaryVariable.
public void setBinaryVariable(String variableKey, MultipartFormData payload) {
FormPart dataPart = payload.getNamedPart("data");
FormPart objectTypePart = payload.getNamedPart("type");
FormPart valueTypePart = payload.getNamedPart("valueType");
if (objectTypePart != null) {
Object object = null;
if (dataPart.getContentType() != null && dataPart.getContentType().toLowerCase().contains(MediaType.APPLICATION_JSON)) {
object = deserializeJsonObject(objectTypePart.getTextContent(), dataPart.getBinaryContent());
} else {
throw new InvalidRequestException(Status.BAD_REQUEST, "Unrecognized content type for serialized java type: " + dataPart.getContentType());
}
if (object != null) {
setVariableEntity(variableKey, Variables.objectValue(object).create());
}
} else {
String valueTypeName = DEFAULT_BINARY_VALUE_TYPE;
if (valueTypePart != null) {
if (valueTypePart.getTextContent() == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Form part with name 'valueType' must have a text/plain value");
}
valueTypeName = valueTypePart.getTextContent();
}
VariableValueDto valueDto = VariableValueDto.fromFormPart(valueTypeName, dataPart);
try {
TypedValue typedValue = valueDto.toTypedValue(engine, objectMapper);
setVariableEntity(variableKey, typedValue);
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
String errorMessage = String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableKey, e.getMessage());
throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
}
}
}
use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.
the class DecisionDefinitionResourceImpl method createResultEntriesDto.
protected Map<String, VariableValueDto> createResultEntriesDto(DmnDecisionResultEntries entries) {
VariableMap variableMap = Variables.createVariables();
for (String key : entries.keySet()) {
TypedValue typedValue = entries.getEntryTyped(key);
variableMap.putValueTyped(key, typedValue);
}
return VariableValueDto.fromVariableMap(variableMap);
}
Aggregations