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());
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Aggregations