use of org.activiti.rest.service.api.engine.variable.RestVariable in project Activiti by Activiti.
the class HistoricProcessInstanceVariableDataResource method getVariableData.
@RequestMapping(value = "/history/historic-process-instances/{processInstanceId}/variables/{variableName}/data", method = RequestMethod.GET)
@ResponseBody
public byte[] getVariableData(@PathVariable("processInstanceId") String processInstanceId, @PathVariable("variableName") String variableName, HttpServletRequest request, HttpServletResponse response) {
try {
byte[] result = null;
RestVariable variable = getVariableFromRequest(true, processInstanceId, variableName, request);
if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
result = (byte[]) variable.getValue();
response.setContentType("application/octet-stream");
} else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
outputStream.writeObject(variable.getValue());
outputStream.close();
result = buffer.toByteArray();
response.setContentType("application/x-java-serialized-object");
} else {
throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
}
return result;
} catch (IOException ioe) {
// Re-throw IOException
throw new ActivitiException("Unexpected exception getting variable data", ioe);
}
}
use of org.activiti.rest.service.api.engine.variable.RestVariable in project Activiti by Activiti.
the class RestResponseFactory method createBinaryRestVariable.
public RestVariable createBinaryRestVariable(String name, RestVariableScope scope, String type, String taskId, String executionId, String processInstanceId) {
RestUrlBuilder urlBuilder = createUrlBuilder();
RestVariable restVar = new RestVariable();
restVar.setVariableScope(scope);
restVar.setName(name);
restVar.setType(type);
if (taskId != null) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_VARIABLE_DATA, taskId, name));
}
if (executionId != null) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, executionId, name));
}
if (processInstanceId != null) {
restVar.setValueUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, processInstanceId, name));
}
return restVar;
}
use of org.activiti.rest.service.api.engine.variable.RestVariable in project Activiti by Activiti.
the class BaseExecutionVariableResource method getVariableDataByteArray.
protected byte[] getVariableDataByteArray(Execution execution, String variableName, String scope, HttpServletResponse response) {
try {
byte[] result = null;
RestVariable variable = getVariableFromRequest(execution, variableName, scope, true);
if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
result = (byte[]) variable.getValue();
response.setContentType("application/octet-stream");
} else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
outputStream.writeObject(variable.getValue());
outputStream.close();
result = buffer.toByteArray();
response.setContentType("application/x-java-serialized-object");
} else {
throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
}
return result;
} catch (IOException ioe) {
throw new ActivitiException("Error getting variable " + variableName, ioe);
}
}
use of org.activiti.rest.service.api.engine.variable.RestVariable in project Activiti by Activiti.
the class BaseVariableCollectionResource method addGlobalVariables.
protected void addGlobalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
Map<String, Object> rawVariables = runtimeService.getVariables(execution.getId());
List<RestVariable> globalVariables = restResponseFactory.createRestVariables(rawVariables, execution.getId(), variableType, RestVariableScope.GLOBAL);
// since local variables get precedence over global ones at all times.
for (RestVariable var : globalVariables) {
if (!variableMap.containsKey(var.getName())) {
variableMap.put(var.getName(), var);
}
}
}
use of org.activiti.rest.service.api.engine.variable.RestVariable in project Activiti by Activiti.
the class TaskResource method completeTask.
protected void completeTask(Task task, TaskActionRequest actionRequest) {
if (actionRequest.getVariables() != null) {
Map<String, Object> variablesToSet = new HashMap<String, Object>();
for (RestVariable var : actionRequest.getVariables()) {
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
Object actualVariableValue = restResponseFactory.getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
}
taskService.complete(task.getId(), variablesToSet);
} else {
taskService.complete(task.getId());
}
}
Aggregations