Search in sources :

Example 26 with Attachment

use of pro.taskana.Attachment in project taskana by Taskana.

the class TaskServiceImpl method addClassificationSummariesToAttachments.

private List<Attachment> addClassificationSummariesToAttachments(TaskImpl task, List<AttachmentImpl> attachmentImpls, List<ClassificationSummary> classifications) {
    if (attachmentImpls == null || attachmentImpls.isEmpty()) {
        return new ArrayList<>();
    }
    List<Attachment> result = new ArrayList<>();
    for (AttachmentImpl att : attachmentImpls) {
        // find the associated task to use the correct domain
        ClassificationSummary aClassification = classifications.stream().filter(c -> c != null & c.getId().equals(att.getClassificationSummary().getId())).findFirst().orElse(null);
        if (aClassification == null) {
            LOGGER.error("Could not find a Classification for attachment {}.", att);
            throw new SystemException("Could not find a Classification for attachment " + att);
        }
        att.setClassificationSummary(aClassification);
        result.add(att);
    }
    return result;
}
Also used : SystemException(pro.taskana.exceptions.SystemException) ClassificationSummary(pro.taskana.ClassificationSummary) ArrayList(java.util.ArrayList) Attachment(pro.taskana.Attachment)

Example 27 with Attachment

use of pro.taskana.Attachment in project taskana by Taskana.

the class QueryTasksAccTest method testQueryForAttachmentInSummary.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1" })
@Test
public void testQueryForAttachmentInSummary() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, TaskNotFoundException, WorkbasketNotFoundException, ConcurrencyException, InvalidWorkbasketException, AttachmentPersistenceException {
    TaskService taskService = taskanaEngine.getTaskService();
    Attachment attachment = createAttachment(// prio 99, SL P2000D
    "DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3));
    Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
    task.addAttachment(attachment);
    taskService.updateTask(task);
    List<TaskSummary> results = taskService.createTaskQuery().idIn("TKI:000000000000000000000000000000000000").list();
    assertThat(results.size(), equalTo(1));
    assertThat(results.get(0).getAttachmentSummaries().size(), equalTo(3));
    AttachmentSummary att = results.get(0).getAttachmentSummaries().get(0);
}
Also used : Task(pro.taskana.Task) TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) Attachment(pro.taskana.Attachment) AttachmentSummary(pro.taskana.AttachmentSummary) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 28 with Attachment

use of pro.taskana.Attachment in project taskana by Taskana.

the class UpdateTaskAttachmentsAccTest method modifyExistingAttachment.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void modifyExistingAttachment() throws TaskNotFoundException, ClassificationNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, InvalidArgumentException, ConcurrencyException, InvalidWorkbasketException, AttachmentPersistenceException, SQLException {
    setUpMethod();
    // setup test
    assertThat(task.getAttachments().size(), equalTo(0));
    task.addAttachment(attachment);
    Attachment attachment2 = createAttachment(// prio 101, SL PT7H
    "L10303", createObjectReference("COMPANY_B", "SYSTEM_C", "INSTANCE_C", "ArchiveId", "ABC45678901234567890123456789012345678901234567890"), "ROHRPOST", "2018-01-15", createSimpleCustomProperties(4));
    task.addAttachment(attachment2);
    task = taskService.updateTask(task);
    task = taskService.getTask(task.getId());
    assertTrue(task.getPriority() == 101);
    assertTrue(task.getDue().equals(task.getPlanned()));
    assertThat(task.getAttachments().size(), equalTo(2));
    List<Attachment> attachments = task.getAttachments();
    boolean rohrpostFound = false;
    boolean emailFound = false;
    for (Attachment att : attachments) {
        String channel = att.getChannel();
        int custAttSize = att.getCustomAttributes().size();
        if ("ROHRPOST".equals(channel)) {
            rohrpostFound = true;
        } else if ("E-MAIL".equals(channel)) {
            emailFound = true;
        } else {
            fail("unexpected attachment detected " + att);
        }
        assertTrue(("ROHRPOST".equals(channel) && custAttSize == 4) || ("E-MAIL".equals(channel) && custAttSize == 3));
    }
    assertTrue(rohrpostFound && emailFound);
    ClassificationSummary newClassificationSummary = taskanaEngine.getClassificationService().getClassification(// Prio 5, SL P16D
    "CLI:100000000000000000000000000000000006").asSummary();
    // modify existing attachment
    for (Attachment att : task.getAttachments()) {
        att.setClassificationSummary(newClassificationSummary);
        if (att.getCustomAttributes().size() == 3) {
            att.setChannel("FAX");
        }
    }
    // modify existing attachment and task classification
    // Prio 99, SL P2000D
    task.setClassificationKey("DOCTYPE_DEFAULT");
    task = taskService.updateTask(task);
    task = taskService.getTask(task.getId());
    assertTrue(task.getPriority() == 99);
    DaysToWorkingDaysConverter converter = DaysToWorkingDaysConverter.initialize(Collections.singletonList(new TimeIntervalColumnHeader(0)), Instant.now());
    long calendarDays = converter.convertWorkingDaysToDays(task.getDue(), 16);
    assertTrue(task.getDue().equals(task.getPlanned().plus(Duration.ofDays(calendarDays))));
    rohrpostFound = false;
    boolean faxFound = false;
    for (Attachment att : task.getAttachments()) {
        String channel = att.getChannel();
        int custAttSize = att.getCustomAttributes().size();
        if ("FAX".equals(channel)) {
            faxFound = true;
        } else if ("ROHRPOST".equals(channel)) {
            rohrpostFound = true;
        } else {
            fail("unexpected attachment detected " + att);
        }
        assertTrue(("ROHRPOST".equals(channel) && custAttSize == 4) || ("FAX".equals(channel) && custAttSize == 3));
    }
    assertTrue(faxFound && rohrpostFound);
}
Also used : DaysToWorkingDaysConverter(pro.taskana.impl.DaysToWorkingDaysConverter) ClassificationSummary(pro.taskana.ClassificationSummary) Attachment(pro.taskana.Attachment) TimeIntervalColumnHeader(pro.taskana.impl.report.impl.TimeIntervalColumnHeader) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

Attachment (pro.taskana.Attachment)28 Test (org.junit.Test)17 Classification (pro.taskana.Classification)9 AbstractAccTest (acceptance.AbstractAccTest)7 ClassificationSummary (pro.taskana.ClassificationSummary)7 WithAccessId (pro.taskana.security.WithAccessId)7 Task (pro.taskana.Task)6 Workbasket (pro.taskana.Workbasket)6 Duration (java.time.Duration)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 AttachmentPersistenceException (pro.taskana.exceptions.AttachmentPersistenceException)4 SystemException (pro.taskana.exceptions.SystemException)4 Instant (java.time.Instant)3 ArrayList (java.util.ArrayList)3 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)3 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)3 AttachmentSummary (pro.taskana.AttachmentSummary)2 TaskService (pro.taskana.TaskService)2 TaskSummary (pro.taskana.TaskSummary)2 WorkbasketSummary (pro.taskana.WorkbasketSummary)2