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()));
}
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()");
}
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));
}
}
}
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);
}
}
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;
}
Aggregations