Search in sources :

Example 86 with Classification

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

the class ClassificationServiceImplTest method testUpdateClassificationParentNotExisting.

@Test(expected = ClassificationNotFoundException.class)
public void testUpdateClassificationParentNotExisting() throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, ConcurrencyException, InvalidArgumentException {
    Instant now = Instant.now();
    ClassificationImpl oldClassification = (ClassificationImpl) createDummyClassification();
    oldClassification.setParentId("SOME ID");
    oldClassification.setCreated(now);
    oldClassification.setModified(now);
    Classification classification = createDummyClassification();
    classification.setParentId("DIFFERENT ID - FOR CHECKING PARENT");
    ((ClassificationImpl) classification).setCreated(oldClassification.getCreated());
    ((ClassificationImpl) classification).setModified(oldClassification.getModified());
    doReturn(oldClassification).when(cutSpy).getClassification(classification.getKey(), classification.getDomain());
    doReturn(null).when(classificationMapperMock).findById(classification.getParentId());
    try {
        cutSpy.updateClassification(classification);
    } catch (ClassificationNotFoundException e) {
        verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any());
        verify(taskanaEngineImplMock, times(2)).openConnection();
        verify(cutSpy, times(1)).getClassification(classification.getKey(), classification.getDomain());
        verify(cutSpy, times(1)).getClassification(classification.getParentId());
        verify(classificationMapperMock, times(1)).findById(classification.getParentId());
        verify(taskanaEngineImplMock, times(2)).returnConnection();
        verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
        throw e;
    }
}
Also used : Instant(java.time.Instant) Classification(pro.taskana.Classification) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) Test(org.junit.Test)

Example 87 with Classification

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

the class ClassificationController method updateClassification.

@PutMapping
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<ClassificationResource> updateClassification(@RequestBody ClassificationResource resource) throws NotAuthorizedException, ClassificationNotFoundException, ConcurrencyException, ClassificationAlreadyExistException, DomainNotFoundException, InvalidArgumentException {
    Classification classification = classificationMapper.toModel(resource);
    classification = classificationService.updateClassification(classification);
    return ResponseEntity.status(HttpStatus.OK).body(classificationMapper.toResource(classification));
}
Also used : Classification(pro.taskana.Classification) PutMapping(org.springframework.web.bind.annotation.PutMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 88 with Classification

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

the class ClassificationDefinitionController method getClassifications.

@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<List<ClassificationResource>> getClassifications(@RequestParam(required = false) String domain) throws ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
    ClassificationQuery query = classificationService.createClassificationQuery();
    List<ClassificationSummary> summaries = domain != null ? query.domainIn(domain).list() : query.list();
    List<ClassificationResource> export = new ArrayList<>();
    for (ClassificationSummary summary : summaries) {
        Classification classification = classificationService.getClassification(summary.getKey(), summary.getDomain());
        export.add(classificationMapper.toResource(classification));
    }
    return new ResponseEntity<>(export, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ClassificationSummary(pro.taskana.ClassificationSummary) ClassificationResource(pro.taskana.rest.resource.ClassificationResource) Classification(pro.taskana.Classification) ArrayList(java.util.ArrayList) ClassificationQuery(pro.taskana.ClassificationQuery) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 89 with Classification

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

the class TaskServiceImpl method createTask.

@Override
public Task createTask(Task taskToCreate) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidArgumentException {
    LOGGER.debug("entry to createTask(task = {})", taskToCreate);
    TaskImpl task = (TaskImpl) taskToCreate;
    try {
        taskanaEngine.openConnection();
        if (task.getId() != "" && task.getId() != null) {
            throw new TaskAlreadyExistException(task.getId());
        } else {
            LOGGER.debug("Task {} cannot be be found, so it can be created.", task.getId());
            Workbasket workbasket;
            if (task.getWorkbasketSummary().getId() != null) {
                workbasket = workbasketService.getWorkbasket(task.getWorkbasketSummary().getId());
            } else if (task.getWorkbasketKey() != null) {
                workbasket = workbasketService.getWorkbasket(task.getWorkbasketKey(), task.getDomain());
            } else {
                throw new InvalidArgumentException("Cannot create a task outside a workbasket");
            }
            task.setWorkbasketSummary(workbasket.asSummary());
            task.setDomain(workbasket.getDomain());
            workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
            String classificationKey = task.getClassificationKey();
            if (classificationKey == null || classificationKey.length() == 0) {
                throw new InvalidArgumentException("classificationKey of task must not be empty");
            }
            Classification classification = this.classificationService.getClassification(classificationKey, workbasket.getDomain());
            task.setClassificationSummary(classification.asSummary());
            validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", "Task");
            PrioDurationHolder prioDurationFromAttachments = handleAttachments(task);
            standardSettings(task, classification, prioDurationFromAttachments);
            this.taskMapper.insert(task);
            LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
        }
        return task;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from createTask(task = {})", task);
    }
}
Also used : TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) Classification(pro.taskana.Classification) Workbasket(pro.taskana.Workbasket)

Example 90 with Classification

use of pro.taskana.Classification 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)

Aggregations

Classification (pro.taskana.Classification)102 Test (org.junit.Test)88 Task (pro.taskana.Task)32 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 AbstractAccTest (acceptance.AbstractAccTest)23 WithAccessId (pro.taskana.security.WithAccessId)21 ClassificationSummary (pro.taskana.ClassificationSummary)20 Workbasket (pro.taskana.Workbasket)18 Connection (java.sql.Connection)14 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)14 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)13 TaskAlreadyExistException (pro.taskana.exceptions.TaskAlreadyExistException)11 ClassificationService (pro.taskana.ClassificationService)10 AttachmentPersistenceException (pro.taskana.exceptions.AttachmentPersistenceException)10 ConcurrencyException (pro.taskana.exceptions.ConcurrencyException)10 InvalidOwnerException (pro.taskana.exceptions.InvalidOwnerException)10 InvalidStateException (pro.taskana.exceptions.InvalidStateException)10 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)10 SystemException (pro.taskana.exceptions.SystemException)10