use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.
the class TaskEventsTest method testDeleteAttachmentEvents.
public void testDeleteAttachmentEvents() {
// initially there are no task events
assertTrue(taskService.getTaskEvents(task.getId()).isEmpty());
identityService.setAuthenticatedUserId(JONNY);
Attachment attachment = taskService.createAttachment(IMAGE_PNG, task.getId(), null, IMAGE_NAME, IMAGE_DESC, IMAGE_URL);
ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + 5000));
taskService.deleteAttachment(attachment.getId());
// now there is a task event created
List<Event> events = taskService.getTaskEvents(task.getId());
assertEquals(2, events.size());
Event event = events.get(0);
assertEquals(1, event.getMessageParts().size());
assertEquals(IMAGE_NAME, event.getMessageParts().get(0));
assertEquals(task.getId(), event.getTaskId());
assertEquals(ACTION_DELETE_ATTACHMENT, event.getAction());
assertEquals(IMAGE_NAME, event.getMessage());
assertEquals(null, event.getProcessInstanceId());
assertNotNull(event.getTime().getTime() <= ClockUtil.getCurrentTime().getTime());
assertNoCommentsForTask();
}
use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.
the class TaskAttachmentResourceImpl method getAttachments.
@Override
public List<AttachmentDto> getAttachments() {
if (!isHistoryEnabled()) {
return Collections.emptyList();
}
ensureTaskExists(Status.NOT_FOUND);
List<Attachment> taskAttachments = engine.getTaskService().getTaskAttachments(taskId);
List<AttachmentDto> attachments = new ArrayList<AttachmentDto>();
for (Attachment attachment : taskAttachments) {
attachments.add(AttachmentDto.fromAttachment(attachment));
}
return attachments;
}
use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.
the class TaskAttachmentResourceImpl method addAttachment.
@Override
public AttachmentDto addAttachment(UriInfo uriInfo, MultipartFormData payload) {
ensureHistoryEnabled(Status.FORBIDDEN);
ensureTaskExists(Status.BAD_REQUEST);
FormPart attachmentNamePart = payload.getNamedPart("attachment-name");
FormPart attachmentTypePart = payload.getNamedPart("attachment-type");
FormPart attachmentDescriptionPart = payload.getNamedPart("attachment-description");
FormPart contentPart = payload.getNamedPart("content");
FormPart urlPart = payload.getNamedPart("url");
if (urlPart == null && contentPart == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "No content or url to remote content exists to create the task attachment.");
}
String attachmentName = null;
String attachmentDescription = null;
String attachmentType = null;
if (attachmentNamePart != null) {
attachmentName = attachmentNamePart.getTextContent();
}
if (attachmentDescriptionPart != null) {
attachmentDescription = attachmentDescriptionPart.getTextContent();
}
if (attachmentTypePart != null) {
attachmentType = attachmentTypePart.getTextContent();
}
Attachment attachment = null;
try {
if (contentPart != null) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(contentPart.getBinaryContent());
attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, byteArrayInputStream);
} else if (urlPart != null) {
attachment = engine.getTaskService().createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, urlPart.getTextContent());
}
} catch (ProcessEngineException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e, "Task id is null");
}
URI uri = uriInfo.getBaseUriBuilder().path(rootResourcePath).path(TaskRestService.PATH).path(taskId + "/attachment/" + attachment.getId()).build();
AttachmentDto attachmentDto = AttachmentDto.fromAttachment(attachment);
// GET /
attachmentDto.addReflexiveLink(uri, HttpMethod.GET, "self");
return attachmentDto;
}
use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.
the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceTaskAttachmentByteArray.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskAttachmentByteArray() {
// given
// create case instance
CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase");
Task task = taskService.createTaskQuery().singleResult();
String taskId = task.getId();
taskService.createAttachment("foo", taskId, null, "something", null, new ByteArrayInputStream("someContent".getBytes()));
// assume
List<Attachment> attachments = taskService.getTaskAttachments(taskId);
assertEquals(1, attachments.size());
String contentId = findAttachmentContentId(attachments);
terminateAndCloseCaseInstance(caseInstance.getId(), null);
// when
historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance.getId()));
// then
attachments = taskService.getTaskAttachments(taskId);
assertEquals(0, attachments.size());
verifyByteArraysWereRemoved(contentId);
}
use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.
the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceTaskAttachmentUrl.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskAttachmentUrl() {
// given
// create case instance
String caseInstanceId = caseService.createCaseInstanceByKey("oneTaskCase").getId();
Task task = taskService.createTaskQuery().singleResult();
taskService.createAttachment("foo", task.getId(), null, "something", null, "http://camunda.org");
// assume
List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
assertEquals(1, attachments.size());
terminateAndCloseCaseInstance(caseInstanceId, null);
// when
historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstanceId));
// then
attachments = taskService.getTaskAttachments(task.getId());
assertEquals(0, attachments.size());
}
Aggregations