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