Search in sources :

Example 21 with Workbasket

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

the class TaskServiceImplTest method testTransferTaskToDestinationWorkbasketUsingSecurityTrue.

@Test
public void testTransferTaskToDestinationWorkbasketUsingSecurityTrue() throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, InvalidWorkbasketException, ClassificationNotFoundException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Workbasket destinationWorkbasket = createWorkbasket("2", "k2");
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "k1", dummyClassification);
    task.setRead(true);
    doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
    doReturn(true).when(taskanaEngineConfigurationMock).isSecurityEnabled();
    doReturn(task).when(cutSpy).getTask(task.getId());
    doReturn(destinationWorkbasket).when(workbasketServiceMock).getWorkbasket(destinationWorkbasket.getId());
    doNothing().when(taskMapperMock).update(any());
    doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
    // doNothing().when(workbasketServiceMock).checkAuthorizationById(any(), WorkbasketAuthorization.TRANSFER);
    Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
    verify(workbasketServiceMock, times(1)).getWorkbasket(destinationWorkbasket.getId());
    verify(taskanaEngineMock, times(0)).getConfiguration();
    verify(taskanaEngineConfigurationMock, times(0)).isSecurityEnabled();
    verify(taskMapperMock, times(1)).update(any());
    verify(taskanaEngineMock, times(1)).returnConnection();
    verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
    assertThat(actualTask.isRead(), equalTo(false));
    assertThat(actualTask.getState(), equalTo(TaskState.READY));
    assertThat(actualTask.isTransferred(), equalTo(true));
    assertThat(actualTask.getWorkbasketKey(), equalTo(destinationWorkbasket.getKey()));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) Workbasket(pro.taskana.Workbasket) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with Workbasket

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

the class TaskServiceImpl method addWorkbasketSummariesToTaskSummaries.

private void addWorkbasketSummariesToTaskSummaries(List<TaskSummaryImpl> taskSummaries) throws NotAuthorizedException {
    LOGGER.debug("entry to addWorkbasketSummariesToTaskSummaries()");
    if (taskSummaries == null || taskSummaries.isEmpty()) {
        return;
    }
    // calculate parameters for workbasket query: workbasket keys
    Set<String> workbasketIdSet = taskSummaries.stream().map(t -> t.getWorkbasketSummary().getId()).collect(Collectors.toSet());
    String[] workbasketIdArray = workbasketIdSet.toArray(new String[0]);
    // perform workbasket query
    LOGGER.debug("addWorkbasketSummariesToTaskSummaries() about to query workbaskets");
    WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
    query.setUsedToAugmentTasks(true);
    List<WorkbasketSummary> workbaskets = query.idIn(workbasketIdArray).list();
    // assign query results to appropriate tasks.
    Iterator<TaskSummaryImpl> taskIterator = taskSummaries.iterator();
    while (taskIterator.hasNext()) {
        TaskSummaryImpl task = taskIterator.next();
        String workbasketId = task.getWorkbasketSummaryImpl().getId();
        // find the appropriate workbasket from the query result
        WorkbasketSummary aWorkbasket = workbaskets.stream().filter(x -> workbasketId != null && workbasketId.equals(x.getId())).findFirst().orElse(null);
        if (aWorkbasket == null) {
            LOGGER.warn("Could not find a Workbasket for task {}.", task.getTaskId());
            taskIterator.remove();
            continue;
        }
        // set the classification on the task object
        task.setWorkbasketSummary(aWorkbasket);
    }
    LOGGER.debug("exit from addWorkbasketSummariesToTaskSummaries()");
}
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) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 23 with Workbasket

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

the class WorkbasketServiceImpl method getDistributionSources.

@Override
public List<WorkbasketSummary> getDistributionSources(String workbasketKey, String domain) throws NotAuthorizedException, WorkbasketNotFoundException {
    LOGGER.debug("entry to getDistributionSources(workbasketKey = {}, domain = {})", workbasketKey, domain);
    List<WorkbasketSummary> result = new ArrayList<>();
    try {
        taskanaEngine.openConnection();
        // check that source workbasket exists
        Workbasket workbasket = getWorkbasket(workbasketKey, domain);
        if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
            checkAuthorization(workbasket.getId(), WorkbasketPermission.READ);
        }
        List<WorkbasketSummaryImpl> distributionSources = workbasketMapper.findDistributionSources(workbasket.getId());
        result.addAll(distributionSources);
        return result;
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result.size();
            LOGGER.debug("exit from getDistributionSources(workbasketId). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 24 with Workbasket

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

the class WorkbasketServiceImpl method createWorkbasket.

@Override
public Workbasket createWorkbasket(Workbasket newWorkbasket) throws InvalidWorkbasketException, NotAuthorizedException, WorkbasketAlreadyExistException, DomainNotFoundException {
    LOGGER.debug("entry to createtWorkbasket(workbasket)", newWorkbasket);
    taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
    WorkbasketImpl workbasket = (WorkbasketImpl) newWorkbasket;
    try {
        taskanaEngine.openConnection();
        Instant now = Instant.now();
        workbasket.setCreated(now);
        workbasket.setModified(now);
        Workbasket existingWorkbasket = workbasketMapper.findByKeyAndDomain(newWorkbasket.getKey(), newWorkbasket.getDomain());
        if (existingWorkbasket != null) {
            LOGGER.error("createWorkbasket failed because Workbasket with key {} and domain {} already exists. Throwing WorkbasketAlreadyExistsException.", newWorkbasket.getKey(), newWorkbasket.getDomain());
            throw new WorkbasketAlreadyExistException(existingWorkbasket);
        }
        if (workbasket.getId() == null || workbasket.getId().isEmpty()) {
            workbasket.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET));
        }
        validateWorkbasket(workbasket);
        workbasketMapper.insert(workbasket);
        LOGGER.debug("Method createWorkbasket() created Workbasket '{}'", workbasket);
        return workbasket;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", workbasket);
    }
}
Also used : WorkbasketAlreadyExistException(pro.taskana.exceptions.WorkbasketAlreadyExistException) Instant(java.time.Instant) Workbasket(pro.taskana.Workbasket)

Example 25 with Workbasket

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

the class WorkbasketController method updateWorkbasket.

@PutMapping(path = "/{workbasketId}")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<WorkbasketResource> updateWorkbasket(@PathVariable(value = "workbasketId") String workbasketId, @RequestBody WorkbasketResource workbasketResource) throws InvalidWorkbasketException, WorkbasketNotFoundException, NotAuthorizedException {
    ResponseEntity<WorkbasketResource> result;
    if (workbasketId.equals(workbasketResource.workbasketId)) {
        Workbasket workbasket = workbasketMapper.toModel(workbasketResource);
        workbasket = workbasketService.updateWorkbasket(workbasket);
        result = ResponseEntity.ok(workbasketMapper.toResource(workbasket));
    } else {
        throw new InvalidWorkbasketException("Target-WB-ID('" + workbasketId + "') is not identical with the WB-ID of to object which should be updated. ID=('" + workbasketResource.getId() + "')");
    }
    return result;
}
Also used : InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) WorkbasketResource(pro.taskana.rest.resource.WorkbasketResource) Workbasket(pro.taskana.Workbasket) PutMapping(org.springframework.web.bind.annotation.PutMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Workbasket (pro.taskana.Workbasket)62 Test (org.junit.Test)47 WithAccessId (pro.taskana.security.WithAccessId)23 AbstractAccTest (acceptance.AbstractAccTest)18 Task (pro.taskana.Task)18 Classification (pro.taskana.Classification)17 WorkbasketService (pro.taskana.WorkbasketService)13 ArrayList (java.util.ArrayList)11 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)10 WorkbasketSummary (pro.taskana.WorkbasketSummary)9 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)9 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)7 Attachment (pro.taskana.Attachment)6 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)6 Instant (java.time.Instant)5 Transactional (org.springframework.transaction.annotation.Transactional)5 WorkbasketResource (pro.taskana.rest.resource.WorkbasketResource)5 Connection (java.sql.Connection)4