Search in sources :

Example 21 with Attachment

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

the class TaskAttachmentResourceTest method testDeleteAttachment.

/**
   * Test deleting a single attachments for a task
   * DELETE runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testDeleteAttachment() 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);
        // Delete the attachment
        HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId()));
        closeResponse(executeBinaryRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
        // Check if attachment is really deleted
        assertNull(taskService.getAttachment(urlAttachment.getId()));
        // Deleting again should result in 404
        closeResponse(executeBinaryRequest(httpDelete, 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) HttpDelete(org.apache.http.client.methods.HttpDelete) Attachment(org.activiti.engine.task.Attachment)

Example 22 with Attachment

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

the class TaskAttachmentResourceTest method testGetAttachmentContentWithoutContent.

/**
   * Test getting the content for a single attachments for a task, for an attachment without content.
   * GET runtime/tasks/{taskId}/attachments/{attachmentId}/content
   */
public void testGetAttachmentContentWithoutContent() 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 content for non-binary attachment
        closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), urlAttachment.getId())), 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 23 with Attachment

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

the class TaskAttachmentResourceTest method testGetAttachmentContentWithMimeType.

/**
   * Test getting the content for a single attachments for a task, with a mime-type set.
   * GET runtime/tasks/{taskId}/attachments/{attachmentId}/content
   */
public void testGetAttachmentContentWithMimeType() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // Create Binary-attachment
        Attachment binaryAttachment = taskService.createAttachment("application/xml", task.getId(), null, "Binary attachment", "Binary attachment description", new ByteArrayInputStream("<p>This is binary content</p>".getBytes()));
        taskService.saveAttachment(binaryAttachment);
        // Get external url attachment
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), binaryAttachment.getId())), HttpStatus.SC_OK);
        // Check response headers
        assertEquals("application/xml", response.getEntity().getContentType().getValue());
        closeResponse(response);
    } 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)

Example 24 with Attachment

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

the class TaskServiceTest method testTaskAttachments.

public void testTaskAttachments() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        Task task = taskService.newTask();
        task.setOwner("johndoe");
        taskService.saveTask(task);
        String taskId = task.getId();
        identityService.setAuthenticatedUserId("johndoe");
        // Fetch the task again and update
        taskService.createAttachment("web page", taskId, null, "weatherforcast", "temperatures and more", "http://weather.com");
        Attachment attachment = taskService.getTaskAttachments(taskId).get(0);
        assertEquals("weatherforcast", attachment.getName());
        assertEquals("temperatures and more", attachment.getDescription());
        assertEquals("web page", attachment.getType());
        assertEquals(taskId, attachment.getTaskId());
        assertNull(attachment.getProcessInstanceId());
        assertEquals("http://weather.com", attachment.getUrl());
        assertNull(taskService.getAttachmentContent(attachment.getId()));
        // Finally, clean up
        taskService.deleteTask(taskId);
        assertEquals(0, taskService.getTaskComments(taskId).size());
        assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskId(taskId).list().size());
        taskService.deleteTask(taskId, true);
    }
}
Also used : Task(org.activiti.engine.task.Task) Attachment(org.activiti.engine.task.Attachment)

Example 25 with Attachment

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

the class CreateAttachmentPopupWindow method saveAttachment.

protected void saveAttachment() {
    try {
        // Creation and persistence of attachment is done in editor
        Attachment attachment = currentEditor.getAttachment();
        fireEvent(new SubmitEvent(this, SubmitEvent.SUBMITTED, attachment));
        // Finally, close window
        close();
    } catch (InvalidValueException ive) {
    // Validation error, Editor UI will handle this.
    }
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) Attachment(org.activiti.engine.task.Attachment) SubmitEvent(org.activiti.explorer.ui.event.SubmitEvent)

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