Search in sources :

Example 16 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testSaveAttachment.

@Test
public void testSaveAttachment() {
    int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
    if (historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
        // given
        Task task = taskService.newTask();
        taskService.saveTask(task);
        String attachmentType = "someAttachment";
        String processInstanceId = "someProcessInstanceId";
        String attachmentName = "attachmentName";
        String attachmentDescription = "attachmentDescription";
        String url = "http://camunda.org";
        Attachment attachment = taskService.createAttachment(attachmentType, task.getId(), processInstanceId, attachmentName, attachmentDescription, url);
        // when
        attachment.setDescription("updatedDescription");
        attachment.setName("updatedName");
        taskService.saveAttachment(attachment);
        // then
        Attachment fetchedAttachment = taskService.getAttachment(attachment.getId());
        assertEquals(attachment.getId(), fetchedAttachment.getId());
        assertEquals(attachmentType, fetchedAttachment.getType());
        assertEquals(task.getId(), fetchedAttachment.getTaskId());
        assertEquals(processInstanceId, fetchedAttachment.getProcessInstanceId());
        assertEquals("updatedName", fetchedAttachment.getName());
        assertEquals("updatedDescription", fetchedAttachment.getDescription());
        assertEquals(url, fetchedAttachment.getUrl());
        taskService.deleteTask(task.getId(), true);
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test)

Example 17 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class TaskServiceTest method testTaskAttachmentByTaskIdAndAttachmentId.

@Test
public void testTaskAttachmentByTaskIdAndAttachmentId() {
    int historyLevel = processEngineConfiguration.getHistoryLevel().getId();
    if (historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
        // create and save task
        Task task = taskService.newTask();
        taskService.saveTask(task);
        String taskId = task.getId();
        // Fetch the task again and update
        // add attachment
        Attachment attachment = taskService.createAttachment("web page", taskId, "someprocessinstanceid", "weatherforcast", "temperatures and more", "http://weather.com");
        String attachmentId = attachment.getId();
        // get attachment for taskId and attachmentId
        attachment = taskService.getTaskAttachment(taskId, attachmentId);
        assertEquals("weatherforcast", attachment.getName());
        assertEquals("temperatures and more", attachment.getDescription());
        assertEquals("web page", attachment.getType());
        assertEquals(taskId, attachment.getTaskId());
        assertEquals("someprocessinstanceid", attachment.getProcessInstanceId());
        assertEquals("http://weather.com", attachment.getUrl());
        assertNull(taskService.getAttachmentContent(attachment.getId()));
        // delete attachment for taskId and attachmentId
        taskService.deleteTaskAttachment(taskId, attachmentId);
        // check if attachment deleted
        assertNull(taskService.getTaskAttachment(taskId, attachmentId));
        taskService.deleteTask(taskId, true);
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) Attachment(org.camunda.bpm.engine.task.Attachment) Test(org.junit.Test)

Example 18 with Attachment

use of org.camunda.bpm.engine.task.Attachment in project camunda-bpm-platform by camunda.

the class UserOperationLogQueryTest method createLogEntries.

/**
 * start process and operate on userTask to create some log entries for the query tests
 */
private void createLogEntries() {
    ClockUtil.setCurrentTime(yesterday);
    // create a process with a userTask and work with it
    process = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    execution = processEngine.getRuntimeService().createExecutionQuery().processInstanceId(process.getId()).singleResult();
    processTaskId = taskService.createTaskQuery().singleResult().getId();
    // user "icke" works on the process userTask
    identityService.setAuthenticatedUserId("icke");
    // create and remove some links
    taskService.addCandidateUser(processTaskId, "er");
    taskService.deleteCandidateUser(processTaskId, "er");
    taskService.addCandidateGroup(processTaskId, "wir");
    taskService.deleteCandidateGroup(processTaskId, "wir");
    // assign and reassign the userTask
    ClockUtil.setCurrentTime(today);
    taskService.setOwner(processTaskId, "icke");
    taskService.claim(processTaskId, "icke");
    taskService.setAssignee(processTaskId, "er");
    // change priority of task
    taskService.setPriority(processTaskId, 10);
    // add and delete an attachment
    Attachment attachment = taskService.createAttachment("image/ico", processTaskId, process.getId(), "favicon.ico", "favicon", "http://camunda.com/favicon.ico");
    taskService.deleteAttachment(attachment.getId());
    // complete the userTask to finish the process
    taskService.complete(processTaskId);
    assertProcessEnded(process.getId());
    // user "er" works on the process userTask
    identityService.setAuthenticatedUserId("er");
    // create a standalone userTask
    userTask = taskService.newTask();
    userTask.setName("to do");
    taskService.saveTask(userTask);
    // change some properties manually to create an update event
    ClockUtil.setCurrentTime(tomorrow);
    userTask.setDescription("desc");
    userTask.setOwner("icke");
    userTask.setAssignee("er");
    userTask.setDueDate(new Date());
    taskService.saveTask(userTask);
    // complete the userTask
    taskService.complete(userTask.getId());
}
Also used : Attachment(org.camunda.bpm.engine.task.Attachment) Date(java.util.Date)

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