Search in sources :

Example 26 with WorkbasketAccessItem

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;
}
Also used : WorkbasketAccessItemResource(pro.taskana.rest.resource.WorkbasketAccessItemResource) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) ArrayList(java.util.ArrayList) Resources(org.springframework.hateoas.Resources)

Example 27 with WorkbasketAccessItem

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);
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) Workbasket(pro.taskana.Workbasket) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 28 with WorkbasketAccessItem

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));
        }
    }
}
Also used : WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) ArrayList(java.util.ArrayList) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException)

Example 29 with WorkbasketAccessItem

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);
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem)

Example 30 with WorkbasketAccessItem

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());
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) ArrayList(java.util.ArrayList)

Aggregations

WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)31 Test (org.junit.Test)18 WithAccessId (pro.taskana.security.WithAccessId)16 AbstractAccTest (acceptance.AbstractAccTest)11 WorkbasketService (pro.taskana.WorkbasketService)11 ArrayList (java.util.ArrayList)6 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)6 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)5 WorkbasketAccessItemResource (pro.taskana.rest.resource.WorkbasketAccessItemResource)5 Task (pro.taskana.Task)4 Connection (java.sql.Connection)3 KeyDomain (pro.taskana.KeyDomain)3 TaskService (pro.taskana.TaskService)3 TaskSummary (pro.taskana.TaskSummary)3 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)3 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)3 NotAuthorizedToQueryWorkbasketException (pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException)3 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)3 WorkbasketAccessItemImpl (pro.taskana.impl.WorkbasketAccessItemImpl)3 SQLException (java.sql.SQLException)2