Search in sources :

Example 1 with AttachmentMapper

use of pro.taskana.mappings.AttachmentMapper in project taskana by Taskana.

the class CreateTaskAccTest method testCreateExternalTaskWithAttachment.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testCreateExternalTaskWithAttachment() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, ConcurrencyException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("L12010");
    Map<String, String> customAttributesForCreate = createSimpleCustomProperties(27);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", customAttributesForCreate));
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    Task createdTask = taskService.createTask(newTask);
    assertNotNull(createdTask.getId());
    assertThat(createdTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    // verify that the database content is as expected
    TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest((TaskanaEngineImpl) taskanaEngine);
    try {
        SqlSession session = engineProxy.getSqlSession();
        AttachmentMapper mapper = session.getMapper(AttachmentMapper.class);
        engineProxy.openConnection();
        String customProperties = mapper.getCustomAttributesAsString(createdTask.getAttachments().get(0).getId());
        assertTrue(customProperties.contains("\"Property_26\":\"Property Value of Property_26\""));
        assertTrue(customProperties.contains("\"Property_25\":\"Property Value of Property_25\""));
        assertTrue(customProperties.contains("\"Property_21\":\"Property Value of Property_21\""));
        assertTrue(customProperties.contains("\"Property_19\":\"Property Value of Property_19\""));
        assertTrue(customProperties.contains("\"Property_16\":\"Property Value of Property_16\""));
        assertTrue(customProperties.contains("\"Property_12\":\"Property Value of Property_12\""));
        assertTrue(customProperties.contains("\"Property_11\":\"Property Value of Property_11\""));
        assertTrue(customProperties.contains("\"Property_7\":\"Property Value of Property_7\""));
        assertTrue(customProperties.contains("\"Property_6\":\"Property Value of Property_6\""));
    } finally {
        engineProxy.returnConnection();
    }
    Task readTask = taskService.getTask(createdTask.getId());
    assertNotNull(readTask);
    assertThat(readTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    assertNotNull(readTask.getAttachments());
    assertEquals(1, readTask.getAttachments().size());
    assertNotNull(readTask.getAttachments().get(0).getCreated());
    assertNotNull(readTask.getAttachments().get(0).getModified());
    assertEquals(readTask.getAttachments().get(0).getCreated(), readTask.getAttachments().get(0).getModified());
    assertNotNull(readTask.getAttachments().get(0).getClassificationSummary());
    assertNotNull(readTask.getAttachments().get(0).getObjectReference());
    // verify that the map is correctly retrieved from the database
    Map<String, String> customAttributesFromDb = readTask.getAttachments().get(0).getCustomAttributes();
    assertNotNull(customAttributesFromDb);
    assertTrue(customAttributesFromDb.equals(customAttributesForCreate));
}
Also used : Task(pro.taskana.Task) SqlSession(org.apache.ibatis.session.SqlSession) TaskService(pro.taskana.TaskService) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AttachmentMapper(pro.taskana.mappings.AttachmentMapper) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

AbstractAccTest (acceptance.AbstractAccTest)1 SqlSession (org.apache.ibatis.session.SqlSession)1 Test (org.junit.Test)1 Task (pro.taskana.Task)1 TaskService (pro.taskana.TaskService)1 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)1 AttachmentMapper (pro.taskana.mappings.AttachmentMapper)1 WithAccessId (pro.taskana.security.WithAccessId)1