use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class BaseExecutionVariableResource method getVariableFromRequest.
public RestVariable getVariableFromRequest(Execution execution, String variableName, String scope, boolean includeBinary) {
boolean variableFound = false;
Object value = null;
if (execution == null) {
throw new ActivitiObjectNotFoundException("Could not find an execution", Execution.class);
}
RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
if (variableScope == null) {
// First, check local variables (which have precedence when no scope is supplied)
if (runtimeService.hasVariableLocal(execution.getId(), variableName)) {
value = runtimeService.getVariableLocal(execution.getId(), variableName);
variableScope = RestVariableScope.LOCAL;
variableFound = true;
} else {
if (execution.getParentId() != null) {
value = runtimeService.getVariable(execution.getParentId(), variableName);
variableScope = RestVariableScope.GLOBAL;
variableFound = true;
}
}
} else if (variableScope == RestVariableScope.GLOBAL) {
// Use parent to get variables
if (execution.getParentId() != null) {
value = runtimeService.getVariable(execution.getParentId(), variableName);
variableScope = RestVariableScope.GLOBAL;
variableFound = true;
}
} else if (variableScope == RestVariableScope.LOCAL) {
value = runtimeService.getVariableLocal(execution.getId(), variableName);
variableScope = RestVariableScope.LOCAL;
variableFound = true;
}
if (!variableFound) {
throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class);
} else {
return constructRestVariable(variableName, value, variableScope, execution.getId(), includeBinary);
}
}
use of org.activiti.engine.ActivitiObjectNotFoundException 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.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TaskIdentityLinkResource method getIdentityLink.
protected IdentityLink getIdentityLink(String family, String identityId, String type, String taskId) {
boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
// Perhaps it would be better to offer getting a single identitylink from the API
List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(taskId);
for (IdentityLink link : allLinks) {
boolean rightIdentity = false;
if (isUser) {
rightIdentity = identityId.equals(link.getUserId());
} else {
rightIdentity = identityId.equals(link.getGroupId());
}
if (rightIdentity && link.getType().equals(type)) {
return link;
}
}
throw new ActivitiObjectNotFoundException("Could not find the requested identity link.", IdentityLink.class);
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TaskVariableResource method deleteVariable.
@RequestMapping(value = "/runtime/tasks/{taskId}/variables/{variableName}", method = RequestMethod.DELETE)
public void deleteVariable(@PathVariable("taskId") String taskId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scopeString, HttpServletResponse response) {
Task task = getTaskFromRequest(taskId);
// Determine scope
RestVariableScope scope = RestVariableScope.LOCAL;
if (scopeString != null) {
scope = RestVariable.getScopeFromString(scopeString);
}
if (!hasVariableOnScope(task, variableName, scope)) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a variable '" + variableName + "' in scope " + scope.name().toLowerCase(), VariableInstanceEntity.class);
}
if (scope == RestVariableScope.LOCAL) {
taskService.removeVariableLocal(task.getId(), variableName);
} else {
// Safe to use executionId, as the hasVariableOnScope whould have stopped a global-var update on standalone task
runtimeService.removeVariable(task.getExecutionId(), variableName);
}
response.setStatus(HttpStatus.NO_CONTENT.value());
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class UserInfoResource method getUserInfo.
@RequestMapping(value = "/identity/users/{userId}/info/{key}", method = RequestMethod.GET, produces = "application/json")
public UserInfoResponse getUserInfo(@PathVariable("userId") String userId, @PathVariable("key") String key, HttpServletRequest request) {
User user = getUserFromRequest(userId);
String existingValue = identityService.getUserInfo(user.getId(), key);
if (existingValue == null) {
throw new ActivitiObjectNotFoundException("User info with key '" + key + "' does not exists for user '" + user.getId() + "'.", null);
}
return restResponseFactory.createUserInfoResponse(key, existingValue, user.getId());
}
Aggregations