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());
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class UserPictureResource method getUserPicture.
@RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.GET)
public ResponseEntity<byte[]> getUserPicture(@PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
User user = getUserFromRequest(userId);
Picture userPicture = identityService.getUserPicture(user.getId());
if (userPicture == null) {
throw new ActivitiObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class);
}
HttpHeaders responseHeaders = new HttpHeaders();
if (userPicture.getMimeType() != null) {
responseHeaders.set("Content-Type", userPicture.getMimeType());
} else {
responseHeaders.set("Content-Type", "image/jpeg");
}
try {
return new ResponseEntity<byte[]>(IOUtils.toByteArray(userPicture.getInputStream()), responseHeaders, HttpStatus.OK);
} catch (Exception e) {
throw new ActivitiException("Error exporting picture: " + e.getMessage(), e);
}
}
Aggregations