Search in sources :

Example 91 with Classification

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

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

the class ClassificationServiceImpl method updateClassification.

@Override
public Classification updateClassification(Classification classification) throws NotAuthorizedException, ConcurrencyException, ClassificationNotFoundException, InvalidArgumentException {
    LOGGER.debug("entry to updateClassification(Classification = {})", classification);
    taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
    ClassificationImpl classificationImpl = null;
    try {
        taskanaEngine.openConnection();
        classificationImpl = (ClassificationImpl) classification;
        // Check if current object is based on the newest (by modified)
        Classification oldClassification = this.getClassification(classificationImpl.getKey(), classificationImpl.getDomain());
        if (!oldClassification.getModified().equals(classificationImpl.getModified())) {
            throw new ConcurrencyException("The current Classification has been modified while editing. The values can not be updated. Classification=" + classificationImpl.toString());
        }
        classificationImpl.setModified(Instant.now());
        this.initDefaultClassificationValues(classificationImpl);
        // Update classification fields used by tasks
        if (oldClassification.getCategory() != classificationImpl.getCategory()) {
            List<TaskSummary> taskSumamries = taskanaEngine.getTaskService().createTaskQuery().classificationIdIn(oldClassification.getId()).list();
            boolean categoryChanged = !(oldClassification.getCategory() == null ? classification.getCategory() == null : oldClassification.getCategory().equals(classification.getCategory()));
            if (!taskSumamries.isEmpty() && categoryChanged) {
                List<String> taskIds = new ArrayList<>();
                taskSumamries.stream().forEach(ts -> taskIds.add(ts.getTaskId()));
                taskMapper.updateClassificationCategoryOnChange(taskIds, classificationImpl.getCategory());
            }
        }
        // Check if parentId changed and object does exist
        if (!oldClassification.getParentId().equals(classificationImpl.getParentId())) {
            if (classificationImpl.getParentId() != null && !classificationImpl.getParentId().isEmpty()) {
                this.getClassification(classificationImpl.getParentId());
            }
        }
        classificationMapper.update(classificationImpl);
        boolean priorityChanged = oldClassification.getPriority() != classification.getPriority();
        boolean serviceLevelChanged = oldClassification.getServiceLevel() != classification.getServiceLevel();
        if (priorityChanged || serviceLevelChanged) {
            Map<String, String> args = new HashMap<>();
            args.put(TaskUpdateOnClassificationChangeExecutor.CLASSIFICATION_ID, classificationImpl.getId());
            args.put(TaskUpdateOnClassificationChangeExecutor.PRIORITY_CHANGED, String.valueOf(priorityChanged));
            args.put(TaskUpdateOnClassificationChangeExecutor.SERVICE_LEVEL_CHANGED, String.valueOf(serviceLevelChanged));
            Job job = new Job();
            job.setCreated(Instant.now());
            job.setState(Job.State.READY);
            job.setExecutor(TaskUpdateOnClassificationChangeExecutor.class.getName());
            job.setArguments(args);
            taskanaEngine.getSqlSession().getMapper(JobMapper.class).insertJob(job);
        }
        LOGGER.debug("Method updateClassification() updated the classification {}.", classificationImpl);
        return classification;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from updateClassification().");
    }
}
Also used : JobMapper(pro.taskana.mappings.JobMapper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) Classification(pro.taskana.Classification) TaskSummary(pro.taskana.TaskSummary)

Example 93 with Classification

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

the class DeleteClassificationAccTest method testDeleteClassificationInDomain.

@WithAccessId(userName = "dummy", groupNames = { "businessadmin" })
@Test
public void testDeleteClassificationInDomain() throws SQLException, ClassificationNotFoundException, NotAuthorizedException, ClassificationInUseException {
    classificationService.deleteClassification("L140101", "DOMAIN_A");
    Classification classification = classificationService.getClassification("L140101", "DOMAIN_A");
    assertNotNull(classification);
    assertEquals("", classification.getDomain());
}
Also used : Classification(pro.taskana.Classification) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 94 with Classification

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

the class CreateClassificationAccTest method testCreateClassificationOfUnknownType.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test(expected = InvalidArgumentException.class)
public void testCreateClassificationOfUnknownType() throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    Classification classification = classificationService.newClassification("Key3", "DOMAIN_A", "UNKNOWN_TYPE");
    classification = classificationService.createClassification(classification);
}
Also used : Classification(pro.taskana.Classification) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 95 with Classification

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

the class CreateClassificationAccTest method testCreateClassificationInUnknownDomain.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test(expected = DomainNotFoundException.class)
public void testCreateClassificationInUnknownDomain() throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    Classification classification = classificationService.newClassification("Key3", "UNKNOWN_DOMAIN", "TASK");
    classification = classificationService.createClassification(classification);
}
Also used : Classification(pro.taskana.Classification) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

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