use of org.activiti.engine.task.Attachment in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method getAttachments.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.GET, produces = "application/json")
public List<AttachmentResponse> getAttachments(@PathVariable String taskId, HttpServletRequest request) {
List<AttachmentResponse> result = new ArrayList<AttachmentResponse>();
HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
for (Attachment attachment : taskService.getTaskAttachments(task.getId())) {
result.add(restResponseFactory.createAttachmentResponse(attachment));
}
return result;
}
use of org.activiti.engine.task.Attachment 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.task.Attachment 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());
}
Aggregations