Search in sources :

Example 1 with Attachment

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

the class TaskRelatedContentComponent method addAttachmentsToTable.

protected void addAttachmentsToTable(List<Attachment> attachments) {
    for (Attachment attachment : attachments) {
        AttachmentRenderer renderer = attachmentRendererManager.getRenderer(attachment);
        Item attachmentItem = table.addItem(attachment.getId());
        attachmentItem.getItemProperty("name").setValue(renderer.getOverviewComponent(attachment, this));
        attachmentItem.getItemProperty("type").setValue(new Embedded(null, renderer.getImage(attachment)));
        Embedded deleteButton = new Embedded(null, Images.DELETE);
        deleteButton.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
        deleteButton.addListener((ClickListener) new DeleteClickedListener(attachment));
        attachmentItem.getItemProperty("delete").setValue(deleteButton);
    }
    if (!table.getItemIds().isEmpty()) {
        table.setVisible(true);
    }
    table.setPageLength(table.size());
}
Also used : Item(com.vaadin.data.Item) Attachment(org.activiti.engine.task.Attachment) Embedded(com.vaadin.ui.Embedded) AttachmentRenderer(org.activiti.explorer.ui.content.AttachmentRenderer)

Example 2 with Attachment

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

the class TaskAttachmentResourceTest method testCreateAttachment.

/**
   * Test creating a single attachments for a task
   * POST runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testCreateAttachment() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "Simple attachment");
        requestNode.put("description", "Simple attachment description");
        requestNode.put("type", "simpleType");
        requestNode.put("externalUrl", "http://activiti.org");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId()));
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        // Check if attachment is created
        List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
        assertEquals(1, attachments.size());
        Attachment urlAttachment = attachments.get(0);
        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());
    } 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 : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Attachment(org.activiti.engine.task.Attachment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with Attachment

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

the class TaskAttachmentResourceTest method testGetAttachmentForCompletedTask.

/**
   * Test getting a single attachments for a task.
   * GET runtime/tasks/{taskId}/attachments/{attachmentId}
   */
public void testGetAttachmentForCompletedTask() 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);
        taskService.complete(task.getId());
        // 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());
    } finally {
        // Clean adhoc-tasks even if test fails
        List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().list();
        for (HistoricTaskInstance task : tasks) {
            taskService.deleteTask(task.getId(), true);
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) 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)

Example 4 with Attachment

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

the class TaskAttachmentResourceTest method testGetAttachmentContent.

/**
   * Test getting the content for a single attachments for a task.
   * GET runtime/tasks/{taskId}/attachments/{attachmentId}/content
   */
public void testGetAttachmentContent() throws Exception {
    try {
        Task task = taskService.newTask();
        taskService.saveTask(task);
        // 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_DATA, task.getId(), binaryAttachment.getId())), HttpStatus.SC_OK);
        // Check response body
        String responseBodyString = IOUtils.toString(response.getEntity().getContent());
        assertEquals("This is binary content", responseBodyString);
        // Check response headers
        assertEquals("application/octet-stream", 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 5 with Attachment

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

the class TaskAttachmentResourceTest method testGetAttachments.

/**
   * Test getting all attachments for a task.
   * GET runtime/tasks/{taskId}/attachments
   */
public void testGetAttachments() 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);
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId())), HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertTrue(responseNode.isArray());
        assertEquals(2, responseNode.size());
    } 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)29 Task (org.activiti.engine.task.Task)18 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