Search in sources :

Example 11 with Attachment

use of org.activiti.engine.task.Attachment in project Activiti by Activiti.

the class HistoricTaskDetailPanel method populateRelatedContent.

protected void populateRelatedContent(Table table, List<Attachment> attachments) {
    if (!attachments.isEmpty()) {
        table.setVisible(true);
    }
    for (Attachment attachment : attachments) {
        AttachmentRenderer renderer = attachmentRendererManager.getRenderer(attachment);
        Item attachmentItem = table.addItem(attachment.getId());
        // Simple renderer that just shows a popup window with the attachment
        RelatedContentComponent relatedContentComponent = new RelatedContentComponent() {

            public void showAttachmentDetail(Attachment attachment) {
                AttachmentDetailPopupWindow popup = new AttachmentDetailPopupWindow(attachment);
                ExplorerApp.get().getViewManager().showPopupWindow(popup);
            }
        };
        attachmentItem.getItemProperty("name").setValue(renderer.getOverviewComponent(attachment, relatedContentComponent));
        attachmentItem.getItemProperty("type").setValue(new Embedded(null, renderer.getImage(attachment)));
    }
    table.setPageLength(table.size());
}
Also used : Item(com.vaadin.data.Item) AttachmentDetailPopupWindow(org.activiti.explorer.ui.content.AttachmentDetailPopupWindow) RelatedContentComponent(org.activiti.explorer.ui.content.RelatedContentComponent) Attachment(org.activiti.engine.task.Attachment) Embedded(com.vaadin.ui.Embedded) AttachmentRenderer(org.activiti.explorer.ui.content.AttachmentRenderer)

Example 12 with Attachment

use of org.activiti.engine.task.Attachment in project Activiti by Activiti.

the class TaskAttachmentCollectionResource method createBinaryAttachment.

protected AttachmentResponse createBinaryAttachment(MultipartHttpServletRequest request, Task task, HttpServletResponse response) {
    String name = null;
    String description = null;
    String type = null;
    Map<String, String[]> paramMap = request.getParameterMap();
    for (String parameterName : paramMap.keySet()) {
        if (paramMap.get(parameterName).length > 0) {
            if (parameterName.equalsIgnoreCase("name")) {
                name = paramMap.get(parameterName)[0];
            } else if (parameterName.equalsIgnoreCase("description")) {
                description = paramMap.get(parameterName)[0];
            } else if (parameterName.equalsIgnoreCase("type")) {
                type = paramMap.get(parameterName)[0];
            }
        }
    }
    if (name == null) {
        throw new ActivitiIllegalArgumentException("Attachment name is required.");
    }
    if (request.getFileMap().size() == 0) {
        throw new ActivitiIllegalArgumentException("Attachment content is required.");
    }
    MultipartFile file = request.getFileMap().values().iterator().next();
    if (file == null) {
        throw new ActivitiIllegalArgumentException("Attachment content is required.");
    }
    try {
        Attachment createdAttachment = taskService.createAttachment(type, task.getId(), task.getProcessInstanceId(), name, description, file.getInputStream());
        response.setStatus(HttpStatus.CREATED.value());
        return restResponseFactory.createAttachmentResponse(createdAttachment);
    } catch (Exception e) {
        throw new ActivitiException("Error creating attachment response", e);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Attachment(org.activiti.engine.task.Attachment) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 13 with Attachment

use of org.activiti.engine.task.Attachment in project Activiti by Activiti.

the class TaskAttachmentResource method getAttachment.

@RequestMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}", method = RequestMethod.GET, produces = "application/json")
public AttachmentResponse getAttachment(@PathVariable("taskId") String taskId, @PathVariable("attachmentId") String attachmentId, HttpServletRequest request) {
    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 + "'.", Comment.class);
    }
    return restResponseFactory.createAttachmentResponse(attachment);
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) Attachment(org.activiti.engine.task.Attachment) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Attachment

use of org.activiti.engine.task.Attachment in project Activiti by Activiti.

the class TaskServiceTest method testTaskAttachmentWithProcessInstanceId.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskAttachmentWithProcessInstanceId() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        String processInstanceId = processInstance.getId();
        taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", "http://weather.com");
        Attachment attachment = taskService.getProcessInstanceAttachments(processInstanceId).get(0);
        assertEquals("weatherforcast", attachment.getName());
        assertEquals("temperatures and more", attachment.getDescription());
        assertEquals("web page", attachment.getType());
        assertEquals(processInstanceId, attachment.getProcessInstanceId());
        assertNull(attachment.getTaskId());
        assertEquals("http://weather.com", attachment.getUrl());
        assertNull(taskService.getAttachmentContent(attachment.getId()));
        // Finally, clean up
        taskService.deleteAttachment(attachment.getId());
        // TODO: Bad API design. Need to fix attachment/comment properly
        ((TaskServiceImpl) taskService).deleteComments(null, processInstanceId);
    }
}
Also used : TaskServiceImpl(org.activiti.engine.impl.TaskServiceImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Attachment(org.activiti.engine.task.Attachment) Deployment(org.activiti.engine.test.Deployment)

Example 15 with Attachment

use of org.activiti.engine.task.Attachment in project Activiti by Activiti.

the class AttachmentEventsTest method testAttachmentEntityEventsOnHistoricProcessInstanceDelete.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testAttachmentEntityEventsOnHistoricProcessInstanceDelete() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        // Create link-attachment
        Attachment attachment = taskService.createAttachment("test", null, processInstance.getId(), "attachment name", "description", "http://activiti.org");
        listener.clearEventsReceived();
        runtimeService.deleteProcessInstance(processInstance.getId(), null);
        historyService.deleteHistoricProcessInstance(processInstance.getId());
        assertEquals(1, listener.getEventsReceived().size());
        ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
        assertEquals(processInstance.getId(), event.getProcessInstanceId());
        assertEquals(processInstance.getId(), event.getExecutionId());
        assertEquals(processInstance.getProcessDefinitionId(), event.getProcessDefinitionId());
        Attachment attachmentFromEvent = (Attachment) event.getEntity();
        assertEquals(attachment.getId(), attachmentFromEvent.getId());
    }
}
Also used : ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Attachment(org.activiti.engine.task.Attachment) Deployment(org.activiti.engine.test.Deployment)

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