Search in sources :

Example 11 with Attachment

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();
}
Also used : Event(org.camunda.bpm.engine.task.Event) Attachment(org.camunda.bpm.engine.task.Attachment) Date(java.util.Date)

Example 12 with Attachment

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;
}
Also used : AttachmentDto(org.camunda.bpm.engine.rest.dto.task.AttachmentDto) ArrayList(java.util.ArrayList) Attachment(org.camunda.bpm.engine.task.Attachment)

Example 13 with Attachment

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;
}
Also used : AttachmentDto(org.camunda.bpm.engine.rest.dto.task.AttachmentDto) FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) ByteArrayInputStream(java.io.ByteArrayInputStream) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Attachment(org.camunda.bpm.engine.task.Attachment) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 14 with Attachment

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);
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ByteArrayInputStream(java.io.ByteArrayInputStream) Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with Attachment

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());
}
Also used : Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Attachment (org.camunda.bpm.engine.task.Attachment)18 Test (org.junit.Test)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Task (org.camunda.bpm.engine.task.Task)6 Deployment (org.camunda.bpm.engine.test.Deployment)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)2 AttachmentDto (org.camunda.bpm.engine.rest.dto.task.AttachmentDto)2 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Matchers.anyString (org.mockito.Matchers.anyString)2 JsonPath (com.jayway.restassured.path.json.JsonPath)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)1 FormPart (org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart)1