Search in sources :

Example 21 with Attachment

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

the class TaskAttachmentTest method testRemoveAttachment.

@Test
public void testRemoveAttachment() {
    // Testing normal way
    Attachment attachment1 = createAttachment("ID1", "taskId1");
    Attachment attachment2 = createAttachment("ID2", "taskId1");
    cut.addAttachment(attachment1);
    cut.addAttachment(attachment2);
    Attachment actual = cut.removeAttachment(attachment2.getId());
    assertThat(cut.getAttachments().size(), equalTo(1));
    assertThat(actual, equalTo(attachment2));
}
Also used : Attachment(pro.taskana.Attachment) Test(org.junit.Test)

Example 22 with Attachment

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

the class TaskServiceImpl method getTask.

@Override
public Task getTask(String id) throws TaskNotFoundException, NotAuthorizedException {
    LOGGER.debug("entry to getTaskById(id = {})", id);
    TaskImpl resultTask = null;
    try {
        taskanaEngine.openConnection();
        resultTask = taskMapper.findById(id);
        if (resultTask != null) {
            WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
            query.setUsedToAugmentTasks(true);
            String workbasketId = resultTask.getWorkbasketSummary().getId();
            List<WorkbasketSummary> workbaskets = query.idIn(workbasketId).list();
            if (workbaskets.isEmpty()) {
                String currentUser = CurrentUserContext.getUserid();
                LOGGER.error("The current user {} has no read permission for workbasket {}.", currentUser, workbasketId);
                throw new NotAuthorizedException("The current user " + currentUser + " has no read permission for workbasket " + workbasketId);
            } else {
                resultTask.setWorkbasketSummary(workbaskets.get(0));
            }
            List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(resultTask.getId());
            if (attachmentImpls == null) {
                attachmentImpls = new ArrayList<>();
            }
            List<ClassificationSummary> classifications;
            try {
                classifications = findClassificationForTaskImplAndAttachments(resultTask, attachmentImpls);
            } catch (NotAuthorizedException e1) {
                LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
                throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
            }
            List<Attachment> attachments = addClassificationSummariesToAttachments(resultTask, attachmentImpls, classifications);
            resultTask.setAttachments(attachments);
            String classificationId = resultTask.getClassificationSummary().getId();
            ClassificationSummary classification = classifications.stream().filter(c -> c.getId().equals(classificationId)).findFirst().orElse(null);
            if (classification == null) {
                LOGGER.error("Could not find a Classification for task {} ", resultTask);
                throw new SystemException("Could not find a Classification for task " + resultTask.getId());
            }
            resultTask.setClassificationSummary(classification);
            return resultTask;
        } else {
            LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
            throw new TaskNotFoundException(id, "Task with id " + id + " was not found");
        }
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from getTaskById(). Returning result {} ", resultTask);
    }
}
Also used : Attachment(pro.taskana.Attachment) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) SystemException(pro.taskana.exceptions.SystemException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) ClassificationSummary(pro.taskana.ClassificationSummary) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 23 with Attachment

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

the class TaskServiceImpl method classificationChanged.

BulkOperationResults<String, Exception> classificationChanged(String taskId, String classificationId) throws TaskNotFoundException, NotAuthorizedException, ClassificationNotFoundException {
    LOGGER.debug("entry to classificationChanged(taskId = {} , classificationId = {} )", taskId, classificationId);
    TaskImpl task = null;
    BulkOperationResults<String, Exception> bulkLog = new BulkOperationResults<>();
    try {
        taskanaEngine.openConnection();
        if (taskId == null || taskId.isEmpty() || classificationId == null || classificationId.isEmpty()) {
            return bulkLog;
        }
        task = taskMapper.findById(taskId);
        List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(task.getId());
        if (attachmentImpls == null) {
            attachmentImpls = new ArrayList<>();
        }
        List<Attachment> attachments = augmentAttachmentsByClassification(attachmentImpls, bulkLog);
        task.setAttachments(attachments);
        Classification classification = classificationService.getClassification(classificationId);
        task.setClassificationSummary(classification.asSummary());
        PrioDurationHolder prioDurationFromAttachments = handleAttachmentsOnClassificationUpdate(task);
        updateClassificationRelatedProperties(task, task, prioDurationFromAttachments);
        task.setModified(Instant.now());
        taskMapper.update(task);
        return bulkLog;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from deleteTask(). ");
    }
}
Also used : Classification(pro.taskana.Classification) Attachment(pro.taskana.Attachment) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SystemException(pro.taskana.exceptions.SystemException) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskanaException(pro.taskana.exceptions.TaskanaException)

Example 24 with Attachment

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

the class TaskServiceImpl method handleAttachmentsOnClassificationUpdate.

private PrioDurationHolder handleAttachmentsOnClassificationUpdate(Task task) {
    Duration minDuration = MAX_DURATION;
    int maxPrio = Integer.MIN_VALUE;
    // Iterator for removing invalid current values directly. OldAttachments can be ignored.
    Iterator<Attachment> i = task.getAttachments().iterator();
    while (i.hasNext()) {
        Attachment attachment = i.next();
        if (attachment != null) {
            ClassificationSummary classification = attachment.getClassificationSummary();
            if (classification != null) {
                PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
                maxPrio = newPrioDuration.getPrio();
                minDuration = newPrioDuration.getDuration();
            }
        }
    }
    if (minDuration != null && MAX_DURATION.equals(minDuration)) {
        minDuration = null;
    }
    return new PrioDurationHolder(minDuration, maxPrio);
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) Duration(java.time.Duration) Attachment(pro.taskana.Attachment)

Example 25 with Attachment

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

the class TaskServiceImpl method standardSettings.

private void standardSettings(TaskImpl task, Classification classification, PrioDurationHolder prioDurationFromAttachments) {
    Instant now = Instant.now();
    task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
    task.setState(TaskState.READY);
    task.setCreated(now);
    task.setModified(now);
    task.setRead(false);
    task.setTransferred(false);
    String creator = CurrentUserContext.getUserid();
    if (taskanaEngine.getConfiguration().isSecurityEnabled()) {
        if (creator == null) {
            throw new SystemException("TaskanaSecurity is enabled, but the current UserId is NULL while creating a Task.");
        }
    }
    task.setCreator(creator);
    if (task.getPlanned() == null) {
        task.setPlanned(now);
    }
    // if no business process id is provided, a unique id is created.
    if (task.getBusinessProcessId() == null) {
        task.setBusinessProcessId(IdGenerator.generateWithPrefix(ID_PREFIX_BUSINESS_PROCESS));
    }
    if (classification != null) {
        PrioDurationHolder finalPrioDuration = getNewPrioDuration(prioDurationFromAttachments.getPrio(), prioDurationFromAttachments.getDuration(), classification.getPriority(), classification.getServiceLevel());
        Duration finalDuration = finalPrioDuration.getDuration();
        if (finalDuration != null && !MAX_DURATION.equals(finalDuration)) {
            long days = converter.convertWorkingDaysToDays(task.getPlanned(), finalDuration.toDays());
            Instant due = task.getPlanned().plus(Duration.ofDays(days));
            task.setDue(due);
        }
        task.setPriority(finalPrioDuration.getPrio());
    }
    if (task.getName() == null) {
        task.setName(classification.getName());
    }
    if (task.getDescription() == null) {
        task.setDescription(classification.getDescription());
    }
    // insert Attachments if needed
    List<Attachment> attachments = task.getAttachments();
    if (attachments != null) {
        for (Attachment attachment : attachments) {
            AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
            attachmentImpl.setId(IdGenerator.generateWithPrefix(ID_PREFIX_ATTACHMENT));
            attachmentImpl.setTaskId(task.getId());
            attachmentImpl.setCreated(now);
            attachmentImpl.setModified(now);
            attachmentMapper.insert(attachmentImpl);
        }
    }
}
Also used : SystemException(pro.taskana.exceptions.SystemException) Instant(java.time.Instant) Duration(java.time.Duration) Attachment(pro.taskana.Attachment)

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