Search in sources :

Example 36 with ClassificationSummary

use of pro.taskana.ClassificationSummary 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 37 with ClassificationSummary

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

the class TaskServiceImpl method addClassificationSummariesToAttachmentSummaries.

private void addClassificationSummariesToAttachmentSummaries(List<AttachmentSummaryImpl> attachmentSummaries, List<TaskSummaryImpl> taskSummaries, List<ClassificationSummary> classifications) {
    // prereq: in each attachmentSummary, the classificationSummary.key property is set.
    if (attachmentSummaries == null || attachmentSummaries.isEmpty() || taskSummaries == null || taskSummaries.isEmpty()) {
        return;
    }
    // iterate over all attachment summaries an add the appropriate classification summary to each
    for (AttachmentSummaryImpl att : attachmentSummaries) {
        String classificationId = att.getClassificationSummary().getId();
        ClassificationSummary aClassification = classifications.stream().filter(x -> classificationId != null && classificationId.equals(x.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);
    }
}
Also used : SystemException(pro.taskana.exceptions.SystemException) ClassificationSummary(pro.taskana.ClassificationSummary)

Example 38 with ClassificationSummary

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

the class TaskServiceImpl method addClassificationSummariesToTaskSummaries.

private void addClassificationSummariesToTaskSummaries(List<TaskSummaryImpl> tasks, List<ClassificationSummary> classifications) {
    if (tasks == null || tasks.isEmpty()) {
        return;
    }
    // assign query results to appropriate tasks.
    for (TaskSummaryImpl task : tasks) {
        String classificationId = task.getClassificationSummary().getId();
        ClassificationSummary aClassification = classifications.stream().filter(c -> c.getId().equals(classificationId)).findFirst().orElse(null);
        if (aClassification == null) {
            LOGGER.error("Didnt find a Classification for task ");
            throw new SystemException("Did not find a Classification for task (Id=" + task.getTaskId() + ",classification=" + task.getClassificationSummary().getId() + ")");
        }
        // set the classification on the task object
        task.setClassificationSummary(aClassification);
    }
}
Also used : SystemException(pro.taskana.exceptions.SystemException) ClassificationSummary(pro.taskana.ClassificationSummary)

Example 39 with ClassificationSummary

use of pro.taskana.ClassificationSummary 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 40 with ClassificationSummary

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

the class ClassificationQueryImpl method list.

@Override
public List<ClassificationSummary> list(int offset, int limit) {
    LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
    List<ClassificationSummary> result = null;
    try {
        taskanaEngine.openConnection();
        RowBounds rowBounds = new RowBounds(offset, limit);
        result = taskanaEngine.getSqlSession().selectList(LINK_TO_SUMMARYMAPPER, this, rowBounds);
        return result;
    } catch (Exception e) {
        if (e instanceof PersistenceException) {
            if (e.getMessage().contains("ERRORCODE=-4470")) {
                TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
                ex.setStackTrace(e.getStackTrace());
                throw ex;
            }
        }
        throw e;
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException)

Aggregations

ClassificationSummary (pro.taskana.ClassificationSummary)51 Test (org.junit.Test)38 AbstractAccTest (acceptance.AbstractAccTest)21 Classification (pro.taskana.Classification)20 ClassificationService (pro.taskana.ClassificationService)20 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)14 Connection (java.sql.Connection)7 Attachment (pro.taskana.Attachment)7 Duration (java.time.Duration)5 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)5 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Task (pro.taskana.Task)4 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)4 SystemException (pro.taskana.exceptions.SystemException)4 WithAccessId (pro.taskana.security.WithAccessId)4 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)3 SQLException (java.sql.SQLException)2