Search in sources :

Example 16 with Attachment

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

the class AttachmentEventsTest method testAttachmentEntityEventsOnHistoricTaskDelete.

public void testAttachmentEntityEventsOnHistoricTaskDelete() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        Task task = null;
        try {
            task = taskService.newTask();
            taskService.saveTask(task);
            assertNotNull(task);
            // Create link-attachment
            Attachment attachment = taskService.createAttachment("test", task.getId(), null, "attachment name", "description", "http://activiti.org");
            listener.clearEventsReceived();
            // Delete task and historic task
            taskService.deleteTask(task.getId());
            historyService.deleteHistoricTaskInstance(task.getId());
            assertEquals(1, listener.getEventsReceived().size());
            ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
            assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
            assertNull(event.getProcessInstanceId());
            assertNull(event.getExecutionId());
            assertNull(event.getProcessDefinitionId());
            Attachment attachmentFromEvent = (Attachment) event.getEntity();
            assertEquals(attachment.getId(), attachmentFromEvent.getId());
        } finally {
            if (task != null && task.getId() != null) {
                taskService.deleteTask(task.getId());
                historyService.deleteHistoricTaskInstance(task.getId());
            }
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) Attachment(org.activiti.engine.task.Attachment)

Example 17 with Attachment

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

the class AttachmentEventsTest method testAttachmentEntityEventsOnHistoricTaskDeleteInProcessInstance.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testAttachmentEntityEventsOnHistoricTaskDeleteInProcessInstance() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        assertNotNull(task);
        // Create link-attachment
        Attachment attachment = taskService.createAttachment("test", task.getId(), 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 : Task(org.activiti.engine.task.Task) 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)

Example 18 with Attachment

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

the class TaskRelatedContentComponent method refreshTaskAttachments.

public void refreshTaskAttachments() {
    table.removeAllItems();
    if (noContentLabel != null) {
        contentLayout.removeComponent(noContentLabel);
    }
    List<Attachment> attachments = null;
    if (task.getProcessInstanceId() != null) {
        attachments = (taskService.getProcessInstanceAttachments(task.getProcessInstanceId()));
    } else {
        attachments = taskService.getTaskAttachments(task.getId());
    }
    if (!attachments.isEmpty()) {
        addAttachmentsToTable(attachments);
    } else {
        table.setVisible(false);
        noContentLabel = new Label(i18nManager.getMessage(Messages.TASK_NO_RELATED_CONTENT));
        noContentLabel.addStyleName(Reindeer.LABEL_SMALL);
        contentLayout.addComponent(noContentLabel);
    }
}
Also used : Label(com.vaadin.ui.Label) Attachment(org.activiti.engine.task.Attachment)

Example 19 with Attachment

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

the class TaskAttachmentResourceTest method testGetAttachmentUnexistingTaskAndAttachment.

/**
   * Test getting a single attachments for a task, using unexisting task and unexisting attachment.
   * GET runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testGetAttachmentUnexistingTaskAndAttachment() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // Create URL-attachment
        Attachment urlAttachment = taskService.createAttachment("simpleType", task.getId(), null, "Simple attachment", "Simple attachment description", "http://activiti.org");
        taskService.saveAttachment(urlAttachment);
        // Get attachment for unexisting task
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, "unexistingtask", urlAttachment.getId())), HttpStatus.SC_NOT_FOUND));
        // Get attachment for task attachment
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), "unexistingattachment")), HttpStatus.SC_NOT_FOUND));
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) HttpGet(org.apache.http.client.methods.HttpGet) Attachment(org.activiti.engine.task.Attachment)

Example 20 with Attachment

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

the class TaskAttachmentResourceTest method testGetAttachment.

/**
   * Test getting a single attachments for a task.
   * GET runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testGetAttachment() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // Create URL-attachment
        Attachment urlAttachment = taskService.createAttachment("simpleType", task.getId(), null, "Simple attachment", "Simple attachment description", "http://activiti.org");
        taskService.saveAttachment(urlAttachment);
        // Create Binary-attachment
        Attachment binaryAttachment = taskService.createAttachment("binaryType", task.getId(), null, "Binary attachment", "Binary attachment description", new ByteArrayInputStream("This is binary content".getBytes()));
        taskService.saveAttachment(binaryAttachment);
        // Get external url attachment
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())), HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals(urlAttachment.getId(), responseNode.get("id").textValue());
        assertEquals("simpleType", responseNode.get("type").textValue());
        assertEquals("Simple attachment", responseNode.get("name").textValue());
        assertEquals("Simple attachment description", responseNode.get("description").textValue());
        assertEquals("http://activiti.org", responseNode.get("externalUrl").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())));
        assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
        assertTrue(responseNode.get("contentUrl").isNull());
        assertTrue(responseNode.get("processInstanceUrl").isNull());
        assertFalse(responseNode.get("time").isNull());
        // Get binary attachment
        response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())), HttpStatus.SC_OK);
        responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertEquals(binaryAttachment.getId(), responseNode.get("id").textValue());
        assertEquals("binaryType", responseNode.get("type").textValue());
        assertEquals("Binary attachment", responseNode.get("name").textValue());
        assertEquals("Binary attachment description", responseNode.get("description").textValue());
        assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())));
        assertTrue(responseNode.get("contentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), binaryAttachment.getId())));
        assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
        assertTrue(responseNode.get("externalUrl").isNull());
        assertTrue(responseNode.get("processInstanceUrl").isNull());
        assertFalse(responseNode.get("time").isNull());
    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Attachment(org.activiti.engine.task.Attachment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

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