Search in sources :

Example 56 with Classification

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

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

the class ClassificationController method createClassification.

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

Example 58 with Classification

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

Example 59 with Classification

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

the class ClassificationServiceImplIntExplicitTest method testFindWithClassificationMapperPriorityTypeAndParent.

@Test
public void testFindWithClassificationMapperPriorityTypeAndParent() throws SQLException, ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    Classification classification = this.createNewClassificationWithUniqueKey("", "TASK");
    classification.setPriority(Integer.decode("5"));
    classificationService.createClassification(classification);
    Classification classification1 = this.createNewClassificationWithUniqueKey("", "TASK");
    classification1.setPriority(Integer.decode("3"));
    classification1.setParentId(classification.getId());
    classificationService.createClassification(classification1);
    Classification classification2 = this.createNewClassificationWithUniqueKey("", "DOCUMENT");
    classification2.setPriority(Integer.decode("5"));
    classification2.setParentId(classification.getId());
    classificationService.createClassification(classification2);
    Classification classification3 = this.createNewClassificationWithUniqueKey("", "TASK");
    classification3.setPriority(Integer.decode("5"));
    classification3.setParentId(classification1.getId());
    classificationService.createClassification(classification3);
    List<ClassificationSummary> list = classificationService.createClassificationQuery().parentIdIn(classification.getId()).list();
    Assert.assertEquals(2, list.size());
    list = classificationService.createClassificationQuery().typeIn("TASK").priorityIn(Integer.decode("5")).list();
    Assert.assertEquals(2, list.size());
    list = classificationService.createClassificationQuery().priorityIn(Integer.decode("5")).typeIn("TASK").parentIdIn(classification1.getId()).list();
    Assert.assertEquals(1, list.size());
    connection.commit();
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

Example 60 with Classification

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

the class ClassificationServiceImplIntExplicitTest method testModifiedClassification.

@Test
public void testModifiedClassification() throws SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, ConcurrencyException, DomainNotFoundException, InvalidArgumentException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "TASK");
    connection.commit();
    classification = classificationService.createClassification(classification);
    String updatedDescription = "TEST SOMETHING";
    classification.setDescription(updatedDescription);
    classification = classificationService.updateClassification(classification);
    connection.commit();
    classification = classificationService.getClassification(classification.getKey(), classification.getDomain());
    assertThat(classification.getDescription(), equalTo(updatedDescription));
}
Also used : Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

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