Search in sources :

Example 16 with NotAuthorizedException

use of pro.taskana.exceptions.NotAuthorizedException in project taskana by Taskana.

the class UpdateWorkbasketAuthorizationsAccTest method testUpdatedAccessItemList.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test
public void testUpdatedAccessItemList() throws InvalidArgumentException, NotAuthorizedException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    final String wbId = "WBI:100000000000000000000000000000000004";
    List<WorkbasketAccessItem> accessItems = workbasketService.getWorkbasketAccessItems(wbId);
    int countBefore = accessItems.size();
    // update some values
    WorkbasketAccessItem item0 = accessItems.get(0);
    item0.setPermAppend(false);
    item0.setPermOpen(false);
    item0.setPermTransfer(false);
    final String updateId0 = item0.getId();
    WorkbasketAccessItem item1 = accessItems.get(1);
    item1.setPermAppend(false);
    item1.setPermOpen(false);
    item1.setPermTransfer(false);
    final String updateId1 = item1.getId();
    workbasketService.setWorkbasketAccessItems(wbId, accessItems);
    List<WorkbasketAccessItem> updatedAccessItems = workbasketService.getWorkbasketAccessItems(wbId);
    int countAfter = updatedAccessItems.size();
    assertThat(countAfter, equalTo(countBefore));
    item0 = updatedAccessItems.stream().filter(i -> i.getId().equals(updateId0)).findFirst().get();
    assertFalse(item0.isPermAppend());
    assertFalse(item0.isPermOpen());
    assertFalse(item0.isPermTransfer());
    item1 = updatedAccessItems.stream().filter(i -> i.getId().equals(updateId1)).findFirst().get();
    assertFalse(item1.isPermAppend());
    assertFalse(item1.isPermOpen());
    assertFalse(item1.isPermTransfer());
}
Also used : NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) WithAccessId(pro.taskana.security.WithAccessId) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) RunWith(org.junit.runner.RunWith) WorkbasketService(pro.taskana.WorkbasketService) CurrentUserContext(pro.taskana.security.CurrentUserContext) Assert.assertThat(org.junit.Assert.assertThat) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SQLException(java.sql.SQLException) JAASRunner(pro.taskana.security.JAASRunner) Task(pro.taskana.Task) Assert.fail(org.junit.Assert.fail) KeyDomain(pro.taskana.KeyDomain) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) IsNot.not(org.hamcrest.core.IsNot.not) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) TaskSummary(pro.taskana.TaskSummary) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) AbstractAccTest(acceptance.AbstractAccTest) Assert.assertTrue(org.junit.Assert.assertTrue) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) Test(org.junit.Test) WorkbasketAccessItemImpl(pro.taskana.impl.WorkbasketAccessItemImpl) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Assert(org.junit.Assert) WorkbasketService(pro.taskana.WorkbasketService) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 17 with NotAuthorizedException

use of pro.taskana.exceptions.NotAuthorizedException in project taskana by Taskana.

the class TaskFilter method inspectParams.

public List<TaskSummary> inspectParams(MultiValueMap<String, String> params) throws NotAuthorizedException, InvalidArgumentException {
    TaskQuery taskQuery = taskService.createTaskQuery();
    // apply filters
    if (params.containsKey(NAME)) {
        String[] names = extractCommaSeperatedFields(params.get(NAME));
        taskQuery.nameIn(names);
    }
    if (params.containsKey(DESCRIPTION)) {
        taskQuery.descriptionLike(params.get(DESCRIPTION).get(0));
    }
    if (params.containsKey(PRIORITY)) {
        String[] prioritesInString = extractCommaSeperatedFields(params.get(PRIORITY));
        int[] priorites = extractPriorities(prioritesInString);
        taskQuery.priorityIn(priorites);
    }
    if (params.containsKey(STATE)) {
        TaskState[] states = extractStates(params);
        taskQuery.stateIn(states);
    }
    if (params.containsKey(CLASSIFICATION_KEY)) {
        String[] classificationKeys = extractCommaSeperatedFields(params.get(CLASSIFICATION_KEY));
        taskQuery.classificationKeyIn(classificationKeys);
    }
    if (params.containsKey(WORKBASKET_ID)) {
        String[] workbaskets = extractCommaSeperatedFields(params.get(WORKBASKET_ID));
        taskQuery.workbasketIdIn(workbaskets);
    }
    if (params.containsKey(OWNER)) {
        String[] owners = extractCommaSeperatedFields(params.get(OWNER));
        taskQuery.ownerIn(owners);
    }
    // objectReference
    if (params.keySet().stream().filter(s -> s.startsWith(POR)).toArray().length > 0) {
        if (params.containsKey(POR_COMPANY)) {
            String[] companies = extractCommaSeperatedFields(params.get(POR_COMPANY));
            taskQuery.primaryObjectReferenceCompanyIn(companies);
        }
        if (params.containsKey(POR_SYSTEM)) {
            String[] systems = extractCommaSeperatedFields(params.get(POR_SYSTEM));
            taskQuery.primaryObjectReferenceSystemIn(systems);
        }
        if (params.containsKey(POR_SYSTEM_INSTANCE)) {
            String[] systemInstances = extractCommaSeperatedFields(params.get(POR_SYSTEM_INSTANCE));
            taskQuery.primaryObjectReferenceSystemInstanceIn(systemInstances);
        }
        if (params.containsKey(POR_TYPE)) {
            String[] types = extractCommaSeperatedFields(params.get(POR_TYPE));
            taskQuery.primaryObjectReferenceTypeIn(types);
        }
        if (params.containsKey(POR_VALUE)) {
            String[] values = extractCommaSeperatedFields(params.get(POR_VALUE));
            taskQuery.primaryObjectReferenceValueIn(values);
        }
    }
    if (params.containsKey(IS_READ)) {
        taskQuery.readEquals(Boolean.getBoolean(params.get(IS_READ).get(0)));
    }
    if (params.containsKey(IS_TRANSFERRED)) {
        taskQuery.transferredEquals(Boolean.getBoolean(params.get(IS_TRANSFERRED).get(0)));
    }
    return taskQuery.list();
}
Also used : TaskService(pro.taskana.TaskService) Arrays(java.util.Arrays) List(java.util.List) Component(org.springframework.stereotype.Component) TaskSummary(pro.taskana.TaskSummary) TaskState(pro.taskana.TaskState) Autowired(org.springframework.beans.factory.annotation.Autowired) MultiValueMap(org.springframework.util.MultiValueMap) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskQuery(pro.taskana.TaskQuery) ArrayList(java.util.ArrayList) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskQuery(pro.taskana.TaskQuery) TaskState(pro.taskana.TaskState)

Example 18 with NotAuthorizedException

use of pro.taskana.exceptions.NotAuthorizedException 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;
}
Also used : Instant(java.time.Instant) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskanaException(pro.taskana.exceptions.TaskanaException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) HashSet(java.util.HashSet) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 19 with NotAuthorizedException

use of pro.taskana.exceptions.NotAuthorizedException 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);
    }
}
Also used : Attachment(pro.taskana.Attachment) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) SystemException(pro.taskana.exceptions.SystemException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) ClassificationSummary(pro.taskana.ClassificationSummary) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 20 with NotAuthorizedException

use of pro.taskana.exceptions.NotAuthorizedException in project taskana by Taskana.

the class TaskServiceImpl method classificationChanged.

BulkOperationResults<String, Exception> classificationChanged(String taskId, String classificationId) throws TaskNotFoundException, NotAuthorizedException, ClassificationNotFoundException {
    LOGGER.debug("entry to classificationChanged(taskId = {} , classificationId = {} )", taskId, classificationId);
    TaskImpl task = null;
    BulkOperationResults<String, Exception> bulkLog = new BulkOperationResults<>();
    try {
        taskanaEngine.openConnection();
        if (taskId == null || taskId.isEmpty() || classificationId == null || classificationId.isEmpty()) {
            return bulkLog;
        }
        task = taskMapper.findById(taskId);
        List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(task.getId());
        if (attachmentImpls == null) {
            attachmentImpls = new ArrayList<>();
        }
        List<Attachment> attachments = augmentAttachmentsByClassification(attachmentImpls, bulkLog);
        task.setAttachments(attachments);
        Classification classification = classificationService.getClassification(classificationId);
        task.setClassificationSummary(classification.asSummary());
        PrioDurationHolder prioDurationFromAttachments = handleAttachmentsOnClassificationUpdate(task);
        updateClassificationRelatedProperties(task, task, prioDurationFromAttachments);
        task.setModified(Instant.now());
        taskMapper.update(task);
        return bulkLog;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from deleteTask(). ");
    }
}
Also used : Classification(pro.taskana.Classification) Attachment(pro.taskana.Attachment) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SystemException(pro.taskana.exceptions.SystemException) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskanaException(pro.taskana.exceptions.TaskanaException)

Aggregations

NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)27 Test (org.junit.Test)15 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)12 ArrayList (java.util.ArrayList)11 AbstractAccTest (acceptance.AbstractAccTest)10 Workbasket (pro.taskana.Workbasket)9 WithAccessId (pro.taskana.security.WithAccessId)9 List (java.util.List)8 WorkbasketService (pro.taskana.WorkbasketService)8 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)8 TaskSummary (pro.taskana.TaskSummary)7 WorkbasketSummary (pro.taskana.WorkbasketSummary)7 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)7 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)7 SQLException (java.sql.SQLException)6 Collectors (java.util.stream.Collectors)5 ClassificationSummary (pro.taskana.ClassificationSummary)5 TaskService (pro.taskana.TaskService)5 TaskNotFoundException (pro.taskana.exceptions.TaskNotFoundException)5 Classification (pro.taskana.Classification)4