Search in sources :

Example 6 with ClassificationNotFoundException

use of pro.taskana.exceptions.ClassificationNotFoundException in project taskana by Taskana.

the class ClassificationServiceImplTest method testCreateClassificationParentNotExisting.

@Test(expected = ClassificationNotFoundException.class)
public void testCreateClassificationParentNotExisting() throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, DomainNotFoundException, InvalidArgumentException {
    Classification classification = createDummyClassification();
    classification.setParentId("NOT EXISTING ID");
    doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain());
    doReturn(null).when(classificationMapperMock).findById(classification.getParentId());
    doReturn(true).when(taskanaEngineImplMock).domainExists(any());
    try {
        cutSpy.createClassification(classification);
    } catch (ClassificationNotFoundException e) {
        verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any());
        verify(taskanaEngineImplMock, times(2)).openConnection();
        verify(classificationMapperMock, times(1)).findByKeyAndDomain(classification.getKey(), classification.getDomain());
        verify(cutSpy, times(1)).getClassification(classification.getParentId());
        verify(classificationMapperMock, times(1)).findById(classification.getParentId());
        verify(taskanaEngineImplMock, times(2)).returnConnection();
        verify(taskanaEngineImplMock, times(1)).domainExists(any());
        verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
        throw e;
    }
}
Also used : Classification(pro.taskana.Classification) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) Test(org.junit.Test)

Example 7 with ClassificationNotFoundException

use of pro.taskana.exceptions.ClassificationNotFoundException 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 8 with ClassificationNotFoundException

use of pro.taskana.exceptions.ClassificationNotFoundException 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 9 with ClassificationNotFoundException

use of pro.taskana.exceptions.ClassificationNotFoundException in project taskana by Taskana.

the class ClassificationServiceImpl method getClassification.

@Override
public Classification getClassification(String id) throws ClassificationNotFoundException {
    if (id == null) {
        throw new ClassificationNotFoundException(id, "Classification for id " + id + " was not found.");
    }
    LOGGER.debug("entry to getClassification(id = {})", id);
    Classification result = null;
    try {
        taskanaEngine.openConnection();
        result = classificationMapper.findById(id);
        if (result == null) {
            LOGGER.error("Classification for id {} was not found. Throwing ClassificationNotFoundException", id);
            throw new ClassificationNotFoundException(id, "Classification for id " + id + " was not found");
        }
        return result;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from getClassification(). Returning result {} ", result);
    }
}
Also used : Classification(pro.taskana.Classification) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException)

Example 10 with ClassificationNotFoundException

use of pro.taskana.exceptions.ClassificationNotFoundException in project taskana by Taskana.

the class QueryClassificationAccTest method testGetClassificationsForKeyAndCategories.

@Test
public void testGetClassificationsForKeyAndCategories() throws SQLException, ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException {
    ClassificationService classificationService = taskanaEngine.getClassificationService();
    List<ClassificationSummary> classifications = classificationService.createClassificationQuery().keyIn("T2100", "L10000").categoryIn("EXTERNAL", "MANUAL").list();
    assertNotNull(classifications);
    assertEquals(5, classifications.size());
    List<ClassificationSummary> externCategory = classifications.stream().filter(c -> c.getCategory().equals("EXTERNAL")).collect(Collectors.toList());
    assertEquals(2, externCategory.size());
    List<ClassificationSummary> manualCategory = classifications.stream().filter(c -> c.getCategory().equals("MANUAL")).collect(Collectors.toList());
    assertEquals(3, manualCategory.size());
}
Also used : SQLException(java.sql.SQLException) List(java.util.List) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) Assert.assertNotNull(org.junit.Assert.assertNotNull) ClassificationService(pro.taskana.ClassificationService) AbstractAccTest(acceptance.AbstractAccTest) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Test(org.junit.Test) ClassificationSummary(pro.taskana.ClassificationSummary) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) ClassificationSummary(pro.taskana.ClassificationSummary) ClassificationService(pro.taskana.ClassificationService) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test)

Aggregations

ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)10 Classification (pro.taskana.Classification)8 Test (org.junit.Test)5 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)5 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ClassificationSummary (pro.taskana.ClassificationSummary)4 ClassificationService (pro.taskana.ClassificationService)3 ConcurrencyException (pro.taskana.exceptions.ConcurrencyException)3 SystemException (pro.taskana.exceptions.SystemException)3 AbstractAccTest (acceptance.AbstractAccTest)2 SQLException (java.sql.SQLException)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 TaskSummary (pro.taskana.TaskSummary)2