use of pro.taskana.Workbasket in project taskana by Taskana.
the class CreateWorkbasketAccTest method testCreateWorkbasketWithMissingRequiredField.
@WithAccessId(userName = "dummy", groupNames = { "businessadmin" })
@Test
public void testCreateWorkbasketWithMissingRequiredField() throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketAlreadyExistException, DomainNotFoundException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
Workbasket workbasket = workbasketService.newWorkbasket(null, "novatec");
workbasket.setName("Megabasket");
workbasket.setType(WorkbasketType.GROUP);
workbasket.setOrgLevel1("company");
try {
// missing key
workbasketService.createWorkbasket(workbasket);
fail("InvalidWorkbasketException was expected");
} catch (InvalidWorkbasketException e) {
}
workbasket = workbasketService.newWorkbasket("key", "novatec");
workbasket.setType(WorkbasketType.GROUP);
workbasket.setOrgLevel1("company");
try {
// missing name
workbasketService.createWorkbasket(workbasket);
fail("InvalidWorkbasketException was expected");
} catch (InvalidWorkbasketException e) {
}
workbasket = workbasketService.newWorkbasket("key", "novatec");
workbasket.setName("Megabasket");
workbasket.setOrgLevel1("company");
try {
// missing type
workbasketService.createWorkbasket(workbasket);
fail("InvalidWorkbasketException was expected");
} catch (InvalidWorkbasketException e) {
}
workbasket = workbasketService.newWorkbasket("key", null);
workbasket.setName("Megabasket");
workbasket.setType(WorkbasketType.GROUP);
workbasket.setOrgLevel1("company");
try {
// missing domain
workbasketService.createWorkbasket(workbasket);
fail("InvalidWorkbasketException was expected");
} catch (InvalidWorkbasketException e) {
}
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class WorkbasketServiceImpl method getDistributionTargets.
@Override
public List<WorkbasketSummary> getDistributionTargets(String workbasketKey, String domain) throws NotAuthorizedException, WorkbasketNotFoundException {
LOGGER.debug("entry to getDistributionTargets(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> distributionTargets = workbasketMapper.findByDistributionTargets(workbasket.getId());
result.addAll(distributionTargets);
return result;
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result.size();
LOGGER.debug("exit from getDistributionTargets(workbasketId). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class WorkbasketServiceImpl method deleteWorkbasket.
@Override
public void deleteWorkbasket(String workbasketId) throws NotAuthorizedException, WorkbasketNotFoundException, WorkbasketInUseException, InvalidArgumentException {
LOGGER.debug("entry to deleteWorkbasket(workbasketId = {})", workbasketId);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
try {
taskanaEngine.openConnection();
if (workbasketId == null || workbasketId.isEmpty()) {
throw new InvalidArgumentException("The WorkbasketId can´t be NULL or EMPTY for deleteWorkbasket()");
}
// check if the workbasket does exist and is empty (Task)
Workbasket wb = this.getWorkbasket(workbasketId);
long numTasksInWorkbasket = taskanaEngine.getSqlSession().getMapper(TaskMapper.class).countTasksInWorkbasket(workbasketId).longValue();
if (numTasksInWorkbasket > 0) {
throw new WorkbasketInUseException("Workbasket is used on tasks and can´t be deleted. WorkbasketId=" + workbasketId);
}
// delete workbasket and sub-tables
distributionTargetMapper.deleteAllDistributionTargetsBySourceId(wb.getId());
distributionTargetMapper.deleteAllDistributionTargetsByTargetId(wb.getId());
workbasketAccessMapper.deleteAllAccessItemsForWorkbasketId(wb.getId());
workbasketMapper.delete(workbasketId);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteWorkbasket(workbasketId = {})", workbasketId);
}
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class WorkbasketServiceImpl method getWorkbasket.
@Override
public Workbasket getWorkbasket(String workbasketKey, String domain) throws WorkbasketNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to getWorkbasketByKey(workbasketKey = {})", workbasketKey);
Workbasket result = null;
try {
taskanaEngine.openConnection();
result = workbasketMapper.findByKeyAndDomain(workbasketKey, domain);
if (result == null) {
LOGGER.error("Method getWorkbasketByKey() didn't find workbasket with key {}. Throwing WorkbasketNotFoundException", workbasketKey);
throw new WorkbasketNotFoundException(workbasketKey, domain, "Workbasket with key " + workbasketKey + " and domain " + domain + " was not found.");
}
if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
this.checkAuthorization(workbasketKey, domain, WorkbasketPermission.READ);
}
return result;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
}
}
use of pro.taskana.Workbasket in project taskana by Taskana.
the class DistributionTargetSerializer method serialize.
@Override
public void serialize(List<Workbasket> workbaskets, JsonGenerator gen, SerializerProvider provider) throws IOException {
List<String> ids = new ArrayList<>();
for (Workbasket item : workbaskets) {
ids.add(item.getId());
}
gen.writeObject(ids);
}
Aggregations