Search in sources :

Example 26 with Attachment

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;
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) AttachmentResponse(org.activiti.rest.service.api.engine.AttachmentResponse) Attachment(org.activiti.engine.task.Attachment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with Attachment

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ActivitiException(org.activiti.engine.ActivitiException) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) InputStream(java.io.InputStream) MediaType(org.springframework.http.MediaType) Attachment(org.activiti.engine.task.Attachment) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with Attachment

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());
}
Also used : Task(org.activiti.engine.task.Task) Attachment(org.activiti.engine.task.Attachment) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Attachment (org.activiti.engine.task.Attachment)28 Task (org.activiti.engine.task.Task)17 ByteArrayInputStream (java.io.ByteArrayInputStream)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 HttpGet (org.apache.http.client.methods.HttpGet)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)5 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)4 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)4 Deployment (org.activiti.engine.test.Deployment)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 Item (com.vaadin.data.Item)2 Embedded (com.vaadin.ui.Embedded)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ActivitiException (org.activiti.engine.ActivitiException)2 AttachmentRenderer (org.activiti.explorer.ui.content.AttachmentRenderer)2 HttpPost (org.apache.http.client.methods.HttpPost)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1