use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class ExecutionVariableResource method deleteVariable.
@RequestMapping(value = "/runtime/executions/{executionId}/variables/{variableName}", method = RequestMethod.DELETE)
public void deleteVariable(@PathVariable("executionId") String executionId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletResponse response) {
Execution execution = getExecutionFromRequest(executionId);
// Determine scope
RestVariableScope variableScope = RestVariableScope.LOCAL;
if (scope != null) {
variableScope = RestVariable.getScopeFromString(scope);
}
if (!hasVariableOnScope(execution, variableName, variableScope)) {
throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable '" + variableName + "' in scope " + variableScope.name().toLowerCase(), VariableInstanceEntity.class);
}
if (variableScope == RestVariableScope.LOCAL) {
runtimeService.removeVariableLocal(execution.getId(), variableName);
} else {
// Safe to use parentId, as the hasVariableOnScope would have stopped a global-var update on a root-execution
runtimeService.removeVariable(execution.getParentId(), variableName);
}
response.setStatus(HttpStatus.NO_CONTENT.value());
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class ProcessInstanceVariableResource method deleteVariable.
@RequestMapping(value = "/runtime/process-instances/{processInstanceId}/variables/{variableName}", method = RequestMethod.DELETE)
public void deleteVariable(@PathVariable("processInstanceId") String processInstanceId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletResponse response) {
Execution execution = getProcessInstanceFromRequest(processInstanceId);
// Determine scope
RestVariableScope variableScope = RestVariableScope.LOCAL;
if (scope != null) {
variableScope = RestVariable.getScopeFromString(scope);
}
if (!hasVariableOnScope(execution, variableName, variableScope)) {
throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable '" + variableName + "' in scope " + variableScope.name().toLowerCase(), VariableInstanceEntity.class);
}
if (variableScope == RestVariableScope.LOCAL) {
runtimeService.removeVariableLocal(execution.getId(), variableName);
} else {
// Safe to use parentId, as the hasVariableOnScope would have stopped a global-var update on a root-execution
runtimeService.removeVariable(execution.getParentId(), variableName);
}
response.setStatus(HttpStatus.NO_CONTENT.value());
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TaskAttachmentContentResource method getAttachmentContent.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}/content", method = RequestMethod.GET)
public ResponseEntity<byte[]> getAttachmentContent(@PathVariable("taskId") String taskId, @PathVariable("attachmentId") String attachmentId, HttpServletResponse response) {
HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
Attachment attachment = taskService.getAttachment(attachmentId);
if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have an attachment with id '" + attachmentId + "'.", Attachment.class);
}
InputStream attachmentStream = taskService.getAttachmentContent(attachmentId);
if (attachmentStream == null) {
throw new ActivitiObjectNotFoundException("Attachment with id '" + attachmentId + "' doesn't have content associated with it.", Attachment.class);
}
HttpHeaders responseHeaders = new HttpHeaders();
MediaType mediaType = null;
if (attachment.getType() != null) {
try {
mediaType = MediaType.valueOf(attachment.getType());
responseHeaders.set("Content-Type", attachment.getType());
} catch (Exception e) {
// ignore if unknown media type
}
}
if (mediaType == null) {
responseHeaders.set("Content-Type", "application/octet-stream");
}
try {
return new ResponseEntity<byte[]>(IOUtils.toByteArray(attachmentStream), responseHeaders, HttpStatus.OK);
} catch (Exception e) {
throw new ActivitiException("Error creating attachment data", e);
}
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TaskAttachmentResource method deleteAttachment.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}", method = RequestMethod.DELETE)
public void deleteAttachment(@PathVariable("taskId") String taskId, @PathVariable("attachmentId") String attachmentId, HttpServletResponse response) {
Task task = getTaskFromRequest(taskId);
Attachment attachment = taskService.getAttachment(attachmentId);
if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have an attachment with id '" + attachmentId + "'.", Comment.class);
}
taskService.deleteAttachment(attachmentId);
response.setStatus(HttpStatus.NO_CONTENT.value());
}
use of org.activiti.engine.ActivitiObjectNotFoundException in project Activiti by Activiti.
the class TaskCommentResource method getComment.
@RequestMapping(value = "/runtime/tasks/{taskId}/comments/{commentId}", method = RequestMethod.GET, produces = "application/json")
public CommentResponse getComment(@PathVariable("taskId") String taskId, @PathVariable("commentId") String commentId, HttpServletRequest request) {
HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
Comment comment = taskService.getComment(commentId);
if (comment == null || !task.getId().equals(comment.getTaskId())) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
}
return restResponseFactory.createRestComment(comment);
}
Aggregations