Search in sources :

Example 26 with ClassificationSummary

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

the class TaskServiceImpl method augmentAttachmentsByClassification.

private List<Attachment> augmentAttachmentsByClassification(List<AttachmentImpl> attachmentImpls, BulkOperationResults<String, Exception> bulkLog) {
    List<Attachment> result = new ArrayList<>();
    if (attachmentImpls == null || attachmentImpls.isEmpty()) {
        return result;
    }
    Set<String> classificationIds = attachmentImpls.stream().map(t -> t.getClassificationSummary().getId()).collect(Collectors.toSet());
    List<ClassificationSummary> classifications = classificationService.createClassificationQuery().idIn(classificationIds.toArray(new String[0])).list();
    for (AttachmentImpl att : attachmentImpls) {
        ClassificationSummary classificationSummary = classifications.stream().filter(cl -> cl.getId().equals(att.getClassificationSummary().getId())).findFirst().orElse(null);
        if (classificationSummary == null) {
            String id = att.getClassificationSummary().getId();
            bulkLog.addError(att.getClassificationSummary().getId(), new ClassificationNotFoundException(id, "When processing task updates due to change of classification, the classification with id " + id + " was not found."));
        } else {
            att.setClassificationSummary(classificationSummary);
            result.add(att);
        }
    }
    return result;
}
Also used : Arrays(java.util.Arrays) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) IdGenerator(pro.taskana.impl.util.IdGenerator) LoggerFactory(org.slf4j.LoggerFactory) WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) CurrentUserContext(pro.taskana.security.CurrentUserContext) HashSet(java.util.HashSet) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SystemException(pro.taskana.exceptions.SystemException) CustomPropertySelector(pro.taskana.mappings.CustomPropertySelector) Task(pro.taskana.Task) InvalidStateException(pro.taskana.exceptions.InvalidStateException) Duration(java.time.Duration) Map(java.util.Map) TaskState(pro.taskana.TaskState) WorkbasketPermission(pro.taskana.WorkbasketPermission) WorkbasketSummary(pro.taskana.WorkbasketSummary) TimeIntervalColumnHeader(pro.taskana.impl.report.impl.TimeIntervalColumnHeader) ClassificationSummary(pro.taskana.ClassificationSummary) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskanaEngine(pro.taskana.TaskanaEngine) Attachment(pro.taskana.Attachment) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) TaskSummary(pro.taskana.TaskSummary) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) Logger(org.slf4j.Logger) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) Iterator(java.util.Iterator) Set(java.util.Set) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) AttachmentMapper(pro.taskana.mappings.AttachmentMapper) Classification(pro.taskana.Classification) LoggerUtils(pro.taskana.impl.util.LoggerUtils) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) TaskMapper(pro.taskana.mappings.TaskMapper) List(java.util.List) Workbasket(pro.taskana.Workbasket) TaskanaRole(pro.taskana.TaskanaRole) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskanaException(pro.taskana.exceptions.TaskanaException) TaskQuery(pro.taskana.TaskQuery) Collections(java.util.Collections) ClassificationSummary(pro.taskana.ClassificationSummary) ArrayList(java.util.ArrayList) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) Attachment(pro.taskana.Attachment)

Example 27 with ClassificationSummary

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

the class TaskServiceImpl method handleAttachmentsOnTaskUpdate.

private PrioDurationHolder handleAttachmentsOnTaskUpdate(TaskImpl oldTaskImpl, TaskImpl newTaskImpl) throws AttachmentPersistenceException {
    Duration minDuration = MAX_DURATION;
    int maxPrio = Integer.MIN_VALUE;
    // Iterator for removing invalid current values directly. OldAttachments can be ignored.
    Iterator<Attachment> i = newTaskImpl.getAttachments().iterator();
    while (i.hasNext()) {
        Attachment attachment = i.next();
        if (attachment != null) {
            boolean wasAlreadyPresent = false;
            if (attachment.getId() != null) {
                for (Attachment oldAttachment : oldTaskImpl.getAttachments()) {
                    if (oldAttachment != null && attachment.getId().equals(oldAttachment.getId())) {
                        wasAlreadyPresent = true;
                        if (!attachment.equals(oldAttachment)) {
                            AttachmentImpl temp = (AttachmentImpl) attachment;
                            ClassificationSummary classification = attachment.getClassificationSummary();
                            if (classification != null) {
                                PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
                                maxPrio = newPrioDuration.getPrio();
                                minDuration = newPrioDuration.getDuration();
                            }
                            temp.setModified(Instant.now());
                            attachmentMapper.update(temp);
                            LOGGER.debug("TaskService.updateTask() for TaskId={} UPDATED an Attachment={}.", newTaskImpl.getId(), attachment);
                            break;
                        }
                    }
                }
            }
            // ADD, when ID not set or not found in elements
            if (!wasAlreadyPresent) {
                AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
                initAttachment(attachmentImpl, newTaskImpl);
                ClassificationSummary classification = attachment.getClassificationSummary();
                if (classification != null) {
                    PrioDurationHolder newPrioDuration = getNewPrioDuration(maxPrio, minDuration, classification.getPriority(), classification.getServiceLevel());
                    maxPrio = newPrioDuration.getPrio();
                    minDuration = newPrioDuration.getDuration();
                }
                try {
                    attachmentMapper.insert(attachmentImpl);
                    LOGGER.debug("TaskService.updateTask() for TaskId={} INSERTED an Attachment={}.", newTaskImpl.getId(), attachmentImpl);
                } catch (PersistenceException e) {
                    LOGGER.error("TaskService.updateTask() for TaskId={} can NOT INSERT the current Attachment, because it was added fored multiple times and wasn´t persisted before. ID={}", newTaskImpl.getId(), attachmentImpl.getId());
                    throw new AttachmentPersistenceException(attachmentImpl.getId());
                }
            }
        } else {
            i.remove();
        }
    }
    // DELETE, when an Attachment was only represented before
    for (Attachment oldAttachment : oldTaskImpl.getAttachments()) {
        if (oldAttachment != null) {
            boolean isRepresented = false;
            for (Attachment newAttachment : newTaskImpl.getAttachments()) {
                if (newAttachment != null && oldAttachment.getId().equals(newAttachment.getId())) {
                    isRepresented = true;
                    break;
                }
            }
            if (!isRepresented) {
                attachmentMapper.deleteAttachment(oldAttachment.getId());
                LOGGER.debug("TaskService.updateTask() for TaskId={} DELETED an Attachment={}.", newTaskImpl.getId(), oldAttachment);
            }
        }
    }
    if (minDuration != null && MAX_DURATION.equals(minDuration)) {
        minDuration = null;
    }
    return new PrioDurationHolder(minDuration, maxPrio);
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) Duration(java.time.Duration) Attachment(pro.taskana.Attachment) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException)

Example 28 with ClassificationSummary

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

the class ClassificationQueryImpl method single.

@Override
public ClassificationSummary single() {
    LOGGER.debug("entry to single(), this = {}", this);
    ClassificationSummary result = null;
    try {
        taskanaEngine.openConnection();
        result = taskanaEngine.getSqlSession().selectOne(LINK_TO_SUMMARYMAPPER, this);
        return result;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from single(). Returning result {} ", result);
    }
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary)

Example 29 with ClassificationSummary

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

the class ClassificationDefinitionController method importClassifications.

@PostMapping(path = "/import")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> importClassifications(@RequestBody List<ClassificationResource> classificationResources) throws InvalidArgumentException {
    Map<String, String> systemIds = classificationService.createClassificationQuery().list().stream().collect(Collectors.toMap(i -> i.getKey() + "|" + i.getDomain(), ClassificationSummary::getId));
    try {
        for (ClassificationResource classificationResource : classificationResources) {
            if (systemIds.containsKey(classificationResource.key + "|" + classificationResource.domain)) {
                classificationService.updateClassification(classificationMapper.toModel(classificationResource));
            } else {
                classificationResource.classificationId = null;
                classificationService.createClassification(classificationMapper.toModel(classificationResource));
            }
        }
    } catch (NotAuthorizedException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    } catch (ClassificationNotFoundException | DomainNotFoundException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    } catch (ClassificationAlreadyExistException e) {
        TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    // TODO why is this occuring???
    } catch (ConcurrencyException e) {
    }
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) ClassificationService(pro.taskana.ClassificationService) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) ClassificationSummary(pro.taskana.ClassificationSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) MediaType(org.springframework.http.MediaType) Classification(pro.taskana.Classification) ClassificationMapper(pro.taskana.rest.resource.mapper.ClassificationMapper) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) ResponseEntity(org.springframework.http.ResponseEntity) ClassificationQuery(pro.taskana.ClassificationQuery) Transactional(org.springframework.transaction.annotation.Transactional) ResponseEntity(org.springframework.http.ResponseEntity) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with ClassificationSummary

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

the class ClassificationServiceImplIntExplicitTest method testInsertAndClassificationQuery.

@Test
public void testInsertAndClassificationQuery() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "TASK");
    classificationService.createClassification(classification);
    List<ClassificationSummary> list = classificationService.createClassificationQuery().validInDomainEquals(Boolean.TRUE).createdWithin(today()).list();
    Assert.assertEquals(1, list.size());
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

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