use of pro.taskana.Workbasket in project taskana by Taskana.
the class TaskServiceImpl method createTask.
@Override
public Task createTask(Task taskToCreate) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidArgumentException {
LOGGER.debug("entry to createTask(task = {})", taskToCreate);
TaskImpl task = (TaskImpl) taskToCreate;
try {
taskanaEngine.openConnection();
if (task.getId() != "" && task.getId() != null) {
throw new TaskAlreadyExistException(task.getId());
} else {
LOGGER.debug("Task {} cannot be be found, so it can be created.", task.getId());
Workbasket workbasket;
if (task.getWorkbasketSummary().getId() != null) {
workbasket = workbasketService.getWorkbasket(task.getWorkbasketSummary().getId());
} else if (task.getWorkbasketKey() != null) {
workbasket = workbasketService.getWorkbasket(task.getWorkbasketKey(), task.getDomain());
} else {
throw new InvalidArgumentException("Cannot create a task outside a workbasket");
}
task.setWorkbasketSummary(workbasket.asSummary());
task.setDomain(workbasket.getDomain());
workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
String classificationKey = task.getClassificationKey();
if (classificationKey == null || classificationKey.length() == 0) {
throw new InvalidArgumentException("classificationKey of task must not be empty");
}
Classification classification = this.classificationService.getClassification(classificationKey, workbasket.getDomain());
task.setClassificationSummary(classification.asSummary());
validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", "Task");
PrioDurationHolder prioDurationFromAttachments = handleAttachments(task);
standardSettings(task, classification, prioDurationFromAttachments);
this.taskMapper.insert(task);
LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
}
return task;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from createTask(task = {})", task);
}
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class TaskServiceImpl method transfer.
@Override
public Task transfer(String taskId, String destinationWorkbasketId) throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketId = {})", taskId, destinationWorkbasketId);
TaskImpl task = null;
try {
taskanaEngine.openConnection();
task = (TaskImpl) getTask(taskId);
// transfer requires TRANSFER in source and APPEND on destination workbasket
workbasketService.checkAuthorization(destinationWorkbasketId, WorkbasketPermission.APPEND);
workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.TRANSFER);
Workbasket destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketId);
// reset read flag and set transferred flag
task.setRead(false);
task.setTransferred(true);
// transfer task from source to destination workbasket
task.setWorkbasketSummary(destinationWorkbasket.asSummary());
task.setModified(Instant.now());
task.setState(TaskState.READY);
task.setOwner(null);
taskMapper.update(task);
LOGGER.debug("Method transfer() transferred Task '{}' to destination workbasket {}", taskId, destinationWorkbasketId);
return task;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from transfer(). Returning result {} ", task);
}
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class DeleteWorkbasketAccTest method testDeleteWorkbasketNotAuthorized.
@WithAccessId(userName = "elena")
@Test(expected = NotAuthorizedException.class)
public void testDeleteWorkbasketNotAuthorized() throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException {
Workbasket wb = workbasketService.getWorkbasket("TEAMLEAD_2", "DOMAIN_A");
workbasketService.deleteWorkbasket(wb.getId());
workbasketService.getWorkbasket("TEAMLEAD_2", "DOMAIN_A");
fail("NotAuthorizedException was expected.");
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class DeleteWorkbasketAccTest method testDeleteWorkbasketAlsoAsDistributionTarget.
@WithAccessId(userName = "user_1_1", groupNames = { "teamlead_1", "group_1", "businessadmin" })
@Test
public void testDeleteWorkbasketAlsoAsDistributionTarget() throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException {
Workbasket wb = workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
int distTargets = workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000001").size();
// WB deleted
workbasketService.deleteWorkbasket(wb.getId());
try {
workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
fail("There should be no result for a deleted Workbasket.");
} catch (WorkbasketNotFoundException e) {
// Workbasket is deleted
}
int newDistTargets = workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000001").size();
assertThat(newDistTargets, equalTo(3));
assertTrue(newDistTargets < distTargets);
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class DeleteWorkbasketAccTest method testCreateAndDeleteWorkbasket.
@WithAccessId(userName = "user_1_2", groupNames = { "businessadmin" })
@Test
public void testCreateAndDeleteWorkbasket() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, InvalidWorkbasketException, WorkbasketAlreadyExistException, DomainNotFoundException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
int before = workbasketService.createWorkbasketQuery().domainIn("DOMAIN_A").list().size();
Workbasket workbasket = workbasketService.newWorkbasket("NT1234", "DOMAIN_A");
workbasket.setName("TheUltimate");
workbasket.setType(WorkbasketType.GROUP);
workbasket.setOrgLevel1("company");
workbasket = workbasketService.createWorkbasket(workbasket);
try {
workbasketService.deleteWorkbasket(workbasket.getId());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations