Search in sources :

Example 1 with ClassificationNotFoundException

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

the class QueryClassificationAccTest method testGetClassificationsForTypeAndParent.

@Test
public void testGetClassificationsForTypeAndParent() throws SQLException, ClassificationNotFoundException, NotAuthorizedException, InvalidArgumentException {
    ClassificationService classificationService = taskanaEngine.getClassificationService();
    List<ClassificationSummary> classifications = classificationService.createClassificationQuery().typeIn("TASK", "DOCUMENT").parentIdIn("").list();
    assertNotNull(classifications);
    assertEquals(25, classifications.size());
    List<ClassificationSummary> documentTypes = classifications.stream().filter(c -> c.getType().equals("DOCUMENT")).collect(Collectors.toList());
    assertEquals(2, documentTypes.size());
    List<ClassificationSummary> taskTypes = classifications.stream().filter(c -> c.getType().equals("TASK")).collect(Collectors.toList());
    assertEquals(23, taskTypes.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)

Example 2 with ClassificationNotFoundException

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

the class ClassificationServiceImplTest method testGetClassificationThrowingNotFoundException.

@Test(expected = ClassificationNotFoundException.class)
public void testGetClassificationThrowingNotFoundException() throws ClassificationNotFoundException {
    Classification classification = createDummyClassification();
    doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain());
    doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), "");
    try {
        cutSpy.getClassification(classification.getKey(), classification.getDomain());
    } catch (ClassificationNotFoundException e) {
        verify(taskanaEngineImplMock, times(1)).openConnection();
        verify(classificationMapperMock, times(1)).findByKeyAndDomain(classification.getKey(), classification.getDomain());
        verify(classificationMapperMock, times(1)).findByKeyAndDomain(classification.getKey(), "");
        verify(taskanaEngineImplMock, times(1)).returnConnection();
        verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
        throw e;
    }
}
Also used : Classification(pro.taskana.Classification) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) Test(org.junit.Test)

Example 3 with ClassificationNotFoundException

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

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

the class ClassificationServiceImpl method deleteClassification.

@Override
public void deleteClassification(String classificationKey, String domain) throws ClassificationInUseException, ClassificationNotFoundException, NotAuthorizedException {
    LOGGER.debug("entry to deleteClassification(key = {}, domain = {})", classificationKey, domain);
    taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
    try {
        taskanaEngine.openConnection();
        Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain);
        if (classification == null) {
            throw new ClassificationNotFoundException(classificationKey, domain, "The classification " + classificationKey + "wasn't found in the domain " + domain);
        }
        List<AttachmentSummaryImpl> attachments = taskanaEngine.getSqlSession().getMapper(AttachmentMapper.class).findAttachmentSummariesByClassificationId(classification.getId());
        if (!attachments.isEmpty()) {
            throw new ClassificationInUseException("Classification " + classification.getId() + " is used by Attachment " + attachments.get(0).getId());
        }
        if (domain.equals("")) {
            // master mode - delete all associated classifications in every domain.
            List<String> domains = this.classificationMapper.getDomainsForClassification(classificationKey);
            domains.remove("");
            for (String classificationDomain : domains) {
                deleteClassification(classificationKey, classificationDomain);
            }
        }
        TaskServiceImpl taskService = (TaskServiceImpl) taskanaEngine.getTaskService();
        try {
            List<TaskSummary> classificationTasks = taskService.createTaskQuery().classificationKeyIn(classificationKey).list();
            if (classificationTasks.stream().anyMatch(t -> domain.equals(t.getClassificationSummary().getDomain()))) {
                throw new ClassificationInUseException("There are Tasks that belong to this classification or a child classification. Please complete them and try again.");
            }
        } catch (NotAuthorizedToQueryWorkbasketException e) {
            LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
            throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
        }
        List<String> childKeys = this.classificationMapper.getChildrenOfClassification(classification.getId());
        for (String key : childKeys) {
            this.deleteClassification(key, domain);
        }
        this.classificationMapper.deleteClassificationInDomain(classificationKey, domain);
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from deleteClassification()");
    }
}
Also used : ClassificationInUseException(pro.taskana.exceptions.ClassificationInUseException) SystemException(pro.taskana.exceptions.SystemException) Classification(pro.taskana.Classification) TaskSummary(pro.taskana.TaskSummary) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) AttachmentMapper(pro.taskana.mappings.AttachmentMapper)

Example 5 with ClassificationNotFoundException

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

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