use of pro.taskana.WorkbasketAccessItem in project taskana by Taskana.
the class WorkbasketAccessItemListMapper method toResource.
public Resources<WorkbasketAccessItemResource> toResource(String workbasketId, Collection<WorkbasketAccessItem> accessItems) throws NotAuthorizedException, WorkbasketNotFoundException {
List<WorkbasketAccessItemResource> resourceList = new ArrayList<>();
for (WorkbasketAccessItem accessItem : accessItems) {
resourceList.add(workbasketAccessItemMapper.toResource(accessItem));
}
Resources<WorkbasketAccessItemResource> accessItemListResource = new Resources<>(resourceList);
accessItemListResource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(workbasketId)).withSelfRel());
accessItemListResource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasket(workbasketId)).withRel("workbasket"));
return accessItemListResource;
}
use of pro.taskana.WorkbasketAccessItem in project taskana by Taskana.
the class CreateWorkbasketAccTest method testCreateWorkbasket.
@WithAccessId(userName = "user_1_2", groupNames = { "businessadmin" })
@Test
public void testCreateWorkbasket() 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("Megabasket");
workbasket.setType(WorkbasketType.GROUP);
workbasket.setOrgLevel1("company");
workbasket = workbasketService.createWorkbasket(workbasket);
WorkbasketAccessItem wbai = workbasketService.newWorkbasketAccessItem(workbasket.getId(), "user_1_2");
wbai.setPermRead(true);
workbasketService.createWorkbasketAccessItem(wbai);
int after = workbasketService.createWorkbasketQuery().domainIn("DOMAIN_A").list().size();
assertEquals(before + 1, after);
Workbasket createdWorkbasket = workbasketService.getWorkbasket("NT1234", "DOMAIN_A");
assertNotNull(createdWorkbasket);
assertNotNull(createdWorkbasket.getId());
Workbasket createdWorkbasket2 = workbasketService.getWorkbasket(createdWorkbasket.getId());
assertNotNull(createdWorkbasket);
assertEquals(createdWorkbasket, createdWorkbasket2);
}
use of pro.taskana.WorkbasketAccessItem in project taskana by Taskana.
the class WorkbasketAccessItemQueryImpl method list.
@Override
public List<WorkbasketAccessItem> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<WorkbasketAccessItem> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
RowBounds rowBounds = new RowBounds(offset, limit);
List<WorkbasketAccessItemImpl> foundAccessItms = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
result.addAll(foundAccessItms);
return result;
} catch (PersistenceException e) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
throw e;
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
use of pro.taskana.WorkbasketAccessItem in project taskana by Taskana.
the class WorkbasketServiceImpl method updateWorkbasketAccessItem.
@Override
public WorkbasketAccessItem updateWorkbasketAccessItem(WorkbasketAccessItem workbasketAccessItem) throws InvalidArgumentException, NotAuthorizedException {
LOGGER.debug("entry to updateWorkbasketAccessItem(workbasketAccessItem = {}", workbasketAccessItem);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
WorkbasketAccessItemImpl accessItem = (WorkbasketAccessItemImpl) workbasketAccessItem;
try {
taskanaEngine.openConnection();
WorkbasketAccessItem originalItem = workbasketAccessMapper.findById(accessItem.getId());
if ((originalItem.getAccessId() != null && !originalItem.getAccessId().equals(accessItem.getAccessId())) || (originalItem.getWorkbasketId() != null && !originalItem.getWorkbasketId().equals(accessItem.getWorkbasketId()))) {
throw new InvalidArgumentException("AccessId and WorkbasketId must not be changed in updateWorkbasketAccessItem calls");
}
workbasketAccessMapper.update(accessItem);
LOGGER.debug("Method updateWorkbasketAccessItem() updated workbasketAccessItem {}", accessItem);
return accessItem;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from updateWorkbasketAccessItem(workbasketAccessItem). Returning {}", accessItem);
}
}
use of pro.taskana.WorkbasketAccessItem in project taskana by Taskana.
the class WorkbasketServiceImpl method setWorkbasketAccessItems.
@Override
public void setWorkbasketAccessItems(String workbasketId, List<WorkbasketAccessItem> wbAccessItems) throws InvalidArgumentException, NotAuthorizedException {
LOGGER.debug("entry to setWorkbasketAccessItems(workbasketAccessItems = {})", wbAccessItems.toString());
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
List<WorkbasketAccessItemImpl> newItems = new ArrayList<>();
try {
taskanaEngine.openConnection();
// Check pre-conditions and set ID
if (!wbAccessItems.isEmpty()) {
for (WorkbasketAccessItem workbasketAccessItem : wbAccessItems) {
WorkbasketAccessItemImpl wbAccessItemImpl = (WorkbasketAccessItemImpl) workbasketAccessItem;
if (wbAccessItemImpl.getWorkbasketId() == null) {
LOGGER.error("setWorkbasketAccessItem failed because WorkbasketAccessItem {} has a null workbasketId. Throwing InvalidArgumentException.", workbasketAccessItem);
throw new InvalidArgumentException("Checking the preconditions of the current WorkbasketAccessItem failed - WBID is NULL. WorkbasketAccessItem=" + workbasketAccessItem.toString());
} else if (!wbAccessItemImpl.getWorkbasketId().equals(workbasketId)) {
LOGGER.error("setWorkbasketAccessItem failed because WorkbasketAccessItem {} does not refer to workbasket {}. Throwing InvalidArgumentException.", workbasketAccessItem, workbasketId);
throw new InvalidArgumentException("Checking the preconditions of the current WorkbasketAccessItem failed - the WBID does not match. Target-WBID='" + workbasketId + "' WorkbasketAccessItem=" + workbasketAccessItem.toString());
}
if (wbAccessItemImpl.getId() == null || wbAccessItemImpl.getId().isEmpty()) {
wbAccessItemImpl.setId(IdGenerator.generateWithPrefix(ID_PREFIX_WORKBASKET_AUTHORIZATION));
}
newItems.add(wbAccessItemImpl);
}
// delete all current ones
workbasketAccessMapper.deleteAllAccessItemsForWorkbasketId(workbasketId);
// add all
newItems.stream().forEach(item -> workbasketAccessMapper.insert(item));
}
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from setWorkbasketAccessItems(workbasketAccessItems = {})", wbAccessItems.toString());
}
}
Aggregations