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