use of pro.taskana.WorkbasketSummary in project taskana by Taskana.
the class DistributionTargetListMapper method toResource.
public Resources<DistributionTargetResource> toResource(String workbasketId, Collection<WorkbasketSummary> distributionTargets) throws WorkbasketNotFoundException, NotAuthorizedException {
List<DistributionTargetResource> resourceList = new ArrayList<>();
for (WorkbasketSummary wb : distributionTargets) {
resourceList.add(distributionTargetMapper.toResource(wb));
}
Resources<DistributionTargetResource> distributionTargetListResource = new Resources<>(resourceList);
distributionTargetListResource.add(linkTo(methodOn(WorkbasketController.class).getDistributionTargets(workbasketId)).withSelfRel());
distributionTargetListResource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(workbasketId)).withRel("workbasket"));
return distributionTargetListResource;
}
use of pro.taskana.WorkbasketSummary in project taskana by Taskana.
the class TaskServiceImpl method transferTasks.
private BulkOperationResults<String, TaskanaException> transferTasks(List<String> taskIds, Workbasket destinationWorkbasket) throws InvalidArgumentException {
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
// check tasks Ids exist and not empty - log and remove
Iterator<String> taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
if (currentTaskId == null || currentTaskId.equals("")) {
bulkLog.addError("", new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed."));
taskIdIterator.remove();
}
}
// query for existing tasks. use taskMapper.findExistingTasks because this method
// returns only the required information.
List<MinimalTaskSummary> taskSummaries = taskMapper.findExistingTasks(taskIds);
// check source WB (read)+transfer
Set<String> workbasketIds = new HashSet<>();
taskSummaries.stream().forEach(t -> workbasketIds.add(t.getWorkbasketId()));
WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
query.setUsedToAugmentTasks(true);
List<WorkbasketSummary> sourceWorkbaskets = query.callerHasPermission(WorkbasketPermission.TRANSFER).idIn(workbasketIds.toArray(new String[0])).list();
taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
MinimalTaskSummary taskSummary = taskSummaries.stream().filter(t -> currentTaskId.equals(t.getTaskId())).findFirst().orElse(null);
if (taskSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "Task with id " + currentTaskId + " was not found."));
taskIdIterator.remove();
} else if (!sourceWorkbaskets.stream().anyMatch(wb -> taskSummary.getWorkbasketId().equals(wb.getId()))) {
bulkLog.addError(currentTaskId, new NotAuthorizedException("The workbasket of this task got not TRANSFER permissions. TaskId=" + currentTaskId));
taskIdIterator.remove();
}
}
// filter taskSummaries and update values
taskSummaries = taskSummaries.stream().filter(ts -> taskIds.contains(ts.getTaskId())).collect(Collectors.toList());
if (!taskSummaries.isEmpty()) {
Instant now = Instant.now();
TaskSummaryImpl updateObject = new TaskSummaryImpl();
updateObject.setRead(false);
updateObject.setTransferred(true);
updateObject.setWorkbasketSummary(destinationWorkbasket.asSummary());
updateObject.setDomain(destinationWorkbasket.getDomain());
updateObject.setModified(now);
updateObject.setState(TaskState.READY);
updateObject.setOwner(null);
taskMapper.updateTransfered(taskIds, updateObject);
}
return bulkLog;
}
use of pro.taskana.WorkbasketSummary 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);
}
}
use of pro.taskana.WorkbasketSummary in project taskana by Taskana.
the class DistributionTargetsAccTest method testGetDistributionTargetsSucceeds.
@WithAccessId(userName = "user_1_1", groupNames = { "teamlead_1" })
@Test
public void testGetDistributionTargetsSucceeds() throws NotAuthorizedException, WorkbasketNotFoundException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
WorkbasketSummary workbasketSummary = workbasketService.createWorkbasketQuery().keyIn("GPK_KSC").single();
List<WorkbasketSummary> retrievedDistributionTargets = workbasketService.getDistributionTargets(workbasketSummary.getKey(), workbasketSummary.getDomain());
assertEquals(4, retrievedDistributionTargets.size());
List<String> expectedTargetIds = new ArrayList<>(Arrays.asList("WBI:100000000000000000000000000000000002", "WBI:100000000000000000000000000000000003", "WBI:100000000000000000000000000000000004", "WBI:100000000000000000000000000000000005"));
for (WorkbasketSummary wbSummary : retrievedDistributionTargets) {
assertTrue(expectedTargetIds.contains(wbSummary.getId()));
}
}
use of pro.taskana.WorkbasketSummary in project taskana by Taskana.
the class DistributionTargetsAccTest method testAddAndRemoveDistributionTargets.
@WithAccessId(userName = "user_2_2", groupNames = { "group_1", "group_2", "businessadmin" })
@Test
public void testAddAndRemoveDistributionTargets() throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
Workbasket workbasket = workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
List<WorkbasketSummary> distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
assertEquals(4, distributionTargets.size());
// add a new distribution target
Workbasket newTarget = workbasketService.getWorkbasket("GPK_B_KSC_2", "DOMAIN_B");
workbasketService.addDistributionTarget(workbasket.getId(), newTarget.getId());
distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
assertEquals(5, distributionTargets.size());
// remove the new target
workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
assertEquals(4, distributionTargets.size());
// remove the new target again Question: should this throw an exception?
workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
assertEquals(4, distributionTargets.size());
}
Aggregations