Search in sources :

Example 26 with TaskSummary

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

the class TaskQueryImpl method list.

@Override
public List<TaskSummary> list(int offset, int limit) {
    LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
    List<TaskSummary> result = new ArrayList<>();
    try {
        taskanaEngine.openConnection();
        checkOpenPermissionForSpecifiedWorkbaskets();
        RowBounds rowBounds = new RowBounds(offset, limit);
        List<TaskSummaryImpl> tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
        result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
        return result;
    } catch (PersistenceException e) {
        if (e.getMessage().contains("ERRORCODE=-4470")) {
            TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
        throw e;
    } catch (NotAuthorizedException e) {
        throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException)

Example 27 with TaskSummary

use of pro.taskana.TaskSummary 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 28 with TaskSummary

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

the class TaskController method getTasks.

@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<PagedResources<TaskSummaryResource>> getTasks(@RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException, NotAuthorizedException {
    TaskQuery query = taskService.createTaskQuery();
    query = applyFilterParams(query, params);
    query = applySortingParams(query, params);
    PageMetadata pageMetadata = null;
    List<TaskSummary> taskSummaries = null;
    String page = params.getFirst(PAGING_PAGE);
    String pageSize = params.getFirst(PAGING_PAGE_SIZE);
    if (page != null && pageSize != null) {
        // paging
        long totalElements = query.count();
        pageMetadata = initPageMetadata(pageSize, page, totalElements);
        taskSummaries = query.listPage((int) pageMetadata.getNumber(), (int) pageMetadata.getSize());
    } else if (page == null && pageSize == null) {
        // not paging
        taskSummaries = query.list();
    } else {
        throw new InvalidArgumentException("Paging information is incomplete.");
    }
    TaskSummaryResourcesAssembler taskSummaryResourcesAssembler = new TaskSummaryResourcesAssembler();
    PagedResources<TaskSummaryResource> pagedResources = taskSummaryResourcesAssembler.toResources(taskSummaries, pageMetadata);
    return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
Also used : PageMetadata(org.springframework.hateoas.PagedResources.PageMetadata) TaskSummaryResourcesAssembler(pro.taskana.rest.resource.mapper.TaskSummaryResourcesAssembler) TaskSummaryResource(pro.taskana.rest.resource.TaskSummaryResource) ResponseEntity(org.springframework.http.ResponseEntity) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskQuery(pro.taskana.TaskQuery) TaskSummary(pro.taskana.TaskSummary) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with TaskSummary

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

the class WorkbasketServiceImplTest method testDeleteWorkbasketIsUsed.

@Test(expected = WorkbasketInUseException.class)
public void testDeleteWorkbasketIsUsed() throws NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException, WorkbasketNotFoundException {
    Workbasket wb = createTestWorkbasket("WBI:0", "wb-key");
    List<TaskSummary> usages = Arrays.asList(new TaskSummaryImpl(), new TaskSummaryImpl());
    doReturn(wb).when(cutSpy).getWorkbasket(wb.getId());
    doReturn(sqlSessionMock).when(taskanaEngineImplMock).getSqlSession();
    doReturn(taskMapperMock).when(sqlSessionMock).getMapper(TaskMapper.class);
    doReturn(new Long(1)).when(taskMapperMock).countTasksInWorkbasket(any());
    try {
        cutSpy.deleteWorkbasket(wb.getId());
    } catch (WorkbasketNotFoundException e) {
        verify(taskanaEngineImplMock, times(1)).openConnection();
        verify(cutSpy, times(1)).getWorkbasket(wb.getId());
        verify(taskanaEngineImplMock, times(1)).getTaskService();
        verify(taskServiceMock, times(1)).createTaskQuery();
        verify(taskQueryMock, times(1)).workbasketIdIn(wb.getId());
        verify(taskQueryMock, times(1)).list();
        verify(taskanaEngineImplMock, times(1)).returnConnection();
        verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
        throw e;
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 30 with TaskSummary

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

the class TaskServiceImplIntExplicitTest method should_ReturnList_when_BuilderIsUsed.

@WithAccessId(userName = "Elena", groupNames = { "DummyGroup", "businessadmin" })
@Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException, WorkbasketAlreadyExistException, DomainNotFoundException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    generateSampleAccessItems();
    WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket("k1", "DOMAIN_A");
    workbasket.setName("workbasket");
    Classification classification = classificationService.newClassification("TEST", "DOMAIN_A", "TASK");
    classificationService.createClassification(classification);
    // set id manually for authorization tests
    workbasket.setId("1");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket = (WorkbasketImpl) workbasketService.createWorkbasket(workbasket);
    Task task = taskServiceImpl.newTask(workbasket.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = taskServiceImpl.createTask(task);
    List<TaskSummary> results = taskServiceImpl.createTaskQuery().nameIn("bla", "test").descriptionLike("test").priorityIn(1, 2, 2).stateIn(TaskState.CLAIMED).workbasketKeyDomainIn(new KeyDomain("k1", "DOMAIN_A")).ownerIn("test", "test2", "bla").customAttributeLike("13", "test").classificationKeyIn("pId1", "pId2").primaryObjectReferenceCompanyIn("first comp", "sonstwo gmbh").primaryObjectReferenceSystemIn("sys").primaryObjectReferenceTypeIn("type1", "type2").primaryObjectReferenceSystemInstanceIn("sysInst1", "sysInst2").primaryObjectReferenceValueIn("val1", "val2", "val3").list();
    Assert.assertEquals(0, results.size());
    connection.commit();
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskSummary(pro.taskana.TaskSummary) WorkbasketImpl(pro.taskana.impl.WorkbasketImpl) KeyDomain(pro.taskana.KeyDomain) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

TaskSummary (pro.taskana.TaskSummary)58 Test (org.junit.Test)48 TaskService (pro.taskana.TaskService)47 WithAccessId (pro.taskana.security.WithAccessId)45 AbstractAccTest (acceptance.AbstractAccTest)44 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)17 KeyDomain (pro.taskana.KeyDomain)14 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)14 Instant (java.time.Instant)9 ArrayList (java.util.ArrayList)8 TimeInterval (pro.taskana.TimeInterval)8 Classification (pro.taskana.Classification)5 Task (pro.taskana.Task)5 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)5 NotAuthorizedToQueryWorkbasketException (pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException)5 TaskQuery (pro.taskana.TaskQuery)4 Workbasket (pro.taskana.Workbasket)3 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2