Search in sources :

Example 31 with ClassificationSummary

use of pro.taskana.ClassificationSummary 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 32 with ClassificationSummary

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

the class ClassificationServiceImplIntExplicitTest method testDefaultSettingsWithClassificationQuery.

@Test
public void testDefaultSettingsWithClassificationQuery() throws NotAuthorizedException, SQLException, ClassificationAlreadyExistException, ClassificationNotFoundException, InvalidArgumentException, ConcurrencyException, DomainNotFoundException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    Classification classification = this.createNewClassificationWithUniqueKey("DOMAIN_A", "TASK");
    classification = classificationService.createClassification(classification);
    Classification classification1 = this.createNewClassificationWithUniqueKey("DOMAIN_A", "TASK");
    classification1 = classificationService.createClassification(classification1);
    classification1.setParentId(classification.getId());
    classification1 = classificationService.updateClassification(classification1);
    List<ClassificationSummary> list = classificationService.createClassificationQuery().parentIdIn("").list();
    Assert.assertEquals(3, list.size());
    list = classificationService.createClassificationQuery().list();
    Assert.assertEquals(4, list.size());
    connection.commit();
    list = classificationService.createClassificationQuery().validInDomainEquals(true).list();
    Assert.assertEquals(2, list.size());
    list = classificationService.createClassificationQuery().createdWithin(today()).list();
    Assert.assertEquals(4, list.size());
    list = classificationService.createClassificationQuery().domainIn("DOMAIN_C").validInDomainEquals(false).list();
    Assert.assertEquals(0, list.size());
    list = classificationService.createClassificationQuery().keyIn(classification1.getKey()).list();
    Assert.assertEquals(2, list.size());
    list = classificationService.createClassificationQuery().parentIdIn(classification.getId()).list();
    Assert.assertEquals(1, list.size());
    assertThat(list.get(0).getKey(), equalTo(classification1.getKey()));
    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 33 with ClassificationSummary

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

the class ClassificationServiceImplIntAutoCommitTest method testFindWithClassificationMapperCustomAndCategory.

@Test
public void testFindWithClassificationMapperCustomAndCategory() throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    Classification classification1 = this.createDummyClassificationWithUniqueKey("", "TASK");
    classification1.setDescription("DESC1");
    classification1.setCategory("EXTERNAL");
    classificationService.createClassification(classification1);
    Classification classification2 = this.createDummyClassificationWithUniqueKey("", "TASK");
    classification2.setDescription("DESC1");
    classification2.setCustom1("custom1");
    classification2.setCategory("EXTERNAL");
    classificationService.createClassification(classification2);
    Classification classification3 = this.createDummyClassificationWithUniqueKey("", "TASK");
    classification3.setCustom1("custom2");
    classification3.setCustom2("custom1");
    classification3.setCategory("MANUAL");
    classificationService.createClassification(classification3);
    Classification classification4 = this.createDummyClassificationWithUniqueKey("", "TASK");
    classification4.setDescription("description2");
    classification4.setCustom8("custom2");
    classification4.setCategory("EXTERNAL");
    classificationService.createClassification(classification4);
    List<ClassificationSummary> list = classificationService.createClassificationQuery().descriptionLike("DESC1").custom1In("custom1").list();
    Assert.assertEquals(1, list.size());
    list = classificationService.createClassificationQuery().custom1In("custom2").list();
    Assert.assertEquals(1, list.size());
    list = classificationService.createClassificationQuery().descriptionLike("DESC1").categoryIn("EXTERNAL").list();
    Assert.assertEquals(2, list.size());
}
Also used : ClassificationSummary(pro.taskana.ClassificationSummary) Classification(pro.taskana.Classification) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

Example 34 with ClassificationSummary

use of pro.taskana.ClassificationSummary 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 35 with ClassificationSummary

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

the class TaskServiceImpl method getTask.

@Override
public Task getTask(String id) throws TaskNotFoundException, NotAuthorizedException {
    LOGGER.debug("entry to getTaskById(id = {})", id);
    TaskImpl resultTask = null;
    try {
        taskanaEngine.openConnection();
        resultTask = taskMapper.findById(id);
        if (resultTask != null) {
            WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
            query.setUsedToAugmentTasks(true);
            String workbasketId = resultTask.getWorkbasketSummary().getId();
            List<WorkbasketSummary> workbaskets = query.idIn(workbasketId).list();
            if (workbaskets.isEmpty()) {
                String currentUser = CurrentUserContext.getUserid();
                LOGGER.error("The current user {} has no read permission for workbasket {}.", currentUser, workbasketId);
                throw new NotAuthorizedException("The current user " + currentUser + " has no read permission for workbasket " + workbasketId);
            } else {
                resultTask.setWorkbasketSummary(workbaskets.get(0));
            }
            List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(resultTask.getId());
            if (attachmentImpls == null) {
                attachmentImpls = new ArrayList<>();
            }
            List<ClassificationSummary> classifications;
            try {
                classifications = findClassificationForTaskImplAndAttachments(resultTask, attachmentImpls);
            } catch (NotAuthorizedException e1) {
                LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
                throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
            }
            List<Attachment> attachments = addClassificationSummariesToAttachments(resultTask, attachmentImpls, classifications);
            resultTask.setAttachments(attachments);
            String classificationId = resultTask.getClassificationSummary().getId();
            ClassificationSummary classification = classifications.stream().filter(c -> c.getId().equals(classificationId)).findFirst().orElse(null);
            if (classification == null) {
                LOGGER.error("Could not find a Classification for task {} ", resultTask);
                throw new SystemException("Could not find a Classification for task " + resultTask.getId());
            }
            resultTask.setClassificationSummary(classification);
            return resultTask;
        } else {
            LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
            throw new TaskNotFoundException(id, "Task with id " + id + " was not found");
        }
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from getTaskById(). Returning result {} ", resultTask);
    }
}
Also used : Attachment(pro.taskana.Attachment) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) SystemException(pro.taskana.exceptions.SystemException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) ClassificationSummary(pro.taskana.ClassificationSummary) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Aggregations

ClassificationSummary (pro.taskana.ClassificationSummary)51 Test (org.junit.Test)38 AbstractAccTest (acceptance.AbstractAccTest)21 Classification (pro.taskana.Classification)20 ClassificationService (pro.taskana.ClassificationService)20 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)14 Connection (java.sql.Connection)7 Attachment (pro.taskana.Attachment)7 Duration (java.time.Duration)5 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)5 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Task (pro.taskana.Task)4 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)4 SystemException (pro.taskana.exceptions.SystemException)4 WithAccessId (pro.taskana.security.WithAccessId)4 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)3 SQLException (java.sql.SQLException)2