use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TaskVariableDataResource method getVariableData.
@RequestMapping(value = "/runtime/tasks/{taskId}/variables/{variableName}/data", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public byte[] getVariableData(@PathVariable("taskId") String taskId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request, HttpServletResponse response) {
try {
byte[] result = null;
RestVariable variable = getVariableFromRequest(taskId, 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) {
// Re-throw IOException
throw new ActivitiException("Unexpected error getting variable data", ioe);
}
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TaskVariableBaseResource method getVariableFromRequest.
public RestVariable getVariableFromRequest(String taskId, String variableName, String scope, boolean includeBinary) {
boolean variableFound = false;
Object value = null;
RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
if (variableScope == null) {
// First, check local variables (which have precedence when no scope is supplied)
if (taskService.hasVariableLocal(taskId, variableName)) {
value = taskService.getVariableLocal(taskId, variableName);
variableScope = RestVariableScope.LOCAL;
variableFound = true;
} else {
// Revert to execution-variable when not present local on the task
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task.getExecutionId() != null && runtimeService.hasVariable(task.getExecutionId(), variableName)) {
value = runtimeService.getVariable(task.getExecutionId(), variableName);
variableScope = RestVariableScope.GLOBAL;
variableFound = true;
}
}
} else if (variableScope == RestVariableScope.GLOBAL) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task.getExecutionId() != null && runtimeService.hasVariable(task.getExecutionId(), variableName)) {
value = runtimeService.getVariable(task.getExecutionId(), variableName);
variableFound = true;
}
} else if (variableScope == RestVariableScope.LOCAL) {
if (taskService.hasVariableLocal(taskId, variableName)) {
value = taskService.getVariableLocal(taskId, variableName);
variableFound = true;
}
}
if (!variableFound) {
throw new ActivitiObjectNotFoundException("Task '" + taskId + "' doesn't have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class);
} else {
return restResponseFactory.createRestVariable(variableName, value, variableScope, taskId, RestResponseFactory.VARIABLE_TASK, includeBinary);
}
}
Aggregations