Search in sources :

Example 31 with TaskSummary

use of pro.taskana.TaskSummary in project taskana by Taskana.

the class UpdateWorkbasketAuthorizationsAccTest method testUpdatedAccessItemLeadsToNotAuthorizedException.

@WithAccessId(userName = "user_1_1", groupNames = { "group_2", "businessadmin" })
@Test
public void testUpdatedAccessItemLeadsToNotAuthorizedException() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
    TaskService taskService = taskanaEngine.getTaskService();
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    String wbKey = "USER_2_1";
    String wbDomain = "DOMAIN_A";
    String groupName = "group_2";
    Task newTask = taskService.newTask(wbKey, wbDomain);
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    Task createdTask = taskService.createTask(newTask);
    List<TaskSummary> tasks = taskService.createTaskQuery().workbasketKeyDomainIn(new KeyDomain(wbKey, wbDomain)).list();
    Assert.assertEquals(1, tasks.size());
    assertThat(createdTask, not(equalTo(null)));
    List<WorkbasketAccessItem> accessItems = workbasketService.getWorkbasketAccessItems("WBI:100000000000000000000000000000000008");
    WorkbasketAccessItem theAccessItem = accessItems.stream().filter(x -> groupName.equals(x.getAccessId())).findFirst().orElse(null);
    Assert.assertTrue(theAccessItem != null);
    theAccessItem.setPermOpen(false);
    workbasketService.updateWorkbasketAccessItem(theAccessItem);
    try {
        taskService.createTaskQuery().workbasketKeyDomainIn(new KeyDomain(wbKey, wbDomain)).list();
        fail("NotAuthorizedToQueryWorkbasketException was expected ");
    } catch (NotAuthorizedToQueryWorkbasketException ignored) {
    // nothing to do
    }
}
Also used : Task(pro.taskana.Task) WorkbasketService(pro.taskana.WorkbasketService) TaskService(pro.taskana.TaskService) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) TaskSummary(pro.taskana.TaskSummary) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) KeyDomain(pro.taskana.KeyDomain) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 32 with TaskSummary

use of pro.taskana.TaskSummary 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 33 with TaskSummary

use of pro.taskana.TaskSummary in project taskana by Taskana.

the class TaskServiceImpl method updateTasks.

@Override
public List<String> updateTasks(ObjectReference selectionCriteria, Map<String, String> customFieldsToUpdate) throws InvalidArgumentException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("entry to updateTasks(selectionCriteria = {}, customFieldsToUpdate = {})", selectionCriteria, customFieldsToUpdate);
    }
    if (customFieldsToUpdate == null || customFieldsToUpdate.isEmpty()) {
        LOGGER.warn("The customFieldsToUpdate argument to updateTasks must not be empty. Throwing InvalidArgumentException.");
        throw new InvalidArgumentException("The customFieldsToUpdate argument to updateTasks must not be empty.");
    }
    validateObjectReference(selectionCriteria, "ObjectReference", "updateTasks call");
    Set<String> allowedKeys = new HashSet<>(Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"));
    try {
        taskanaEngine.openConnection();
        CustomPropertySelector fieldSelector = new CustomPropertySelector();
        TaskImpl newTask = new TaskImpl();
        newTask.setModified(Instant.now());
        for (Map.Entry<String, String> entry : customFieldsToUpdate.entrySet()) {
            String key = entry.getKey();
            if (!allowedKeys.contains(key)) {
                LOGGER.warn("The customFieldsToUpdate argument to updateTasks contains invalid key {}.", key);
                throw new InvalidArgumentException("The customFieldsToUpdate argument to updateTasks contains invalid key " + key);
            } else {
                fieldSelector.setCustomProperty(key, true);
                newTask.setCustomAttribute(key, entry.getValue());
            }
        }
        // use query in order to find only those tasks that are visible to the current user
        List<TaskSummary> taskSummaries = createTaskQuery().primaryObjectReferenceCompanyIn(selectionCriteria.getCompany()).primaryObjectReferenceSystemIn(selectionCriteria.getSystem()).primaryObjectReferenceSystemInstanceIn(selectionCriteria.getSystemInstance()).primaryObjectReferenceTypeIn(selectionCriteria.getType()).primaryObjectReferenceValueIn(selectionCriteria.getValue()).list();
        List<String> taskIds = new ArrayList<>();
        if (!taskSummaries.isEmpty()) {
            taskIds = taskSummaries.stream().map(TaskSummary::getTaskId).collect(Collectors.toList());
            taskMapper.updateTasks(taskIds, newTask, fieldSelector);
            LOGGER.debug("updateTasks() updated the following tasks: {} ", LoggerUtils.listToString(taskIds));
        } else {
            LOGGER.debug("updateTasks() found no tasks for update ");
        }
        return taskIds;
    } finally {
        LOGGER.debug("exit from deleteTasks().");
        taskanaEngine.returnConnection();
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) Map(java.util.Map) HashSet(java.util.HashSet) CustomPropertySelector(pro.taskana.mappings.CustomPropertySelector)

Example 34 with TaskSummary

use of pro.taskana.TaskSummary in project taskana by Taskana.

the class TaskQueryImpl method single.

@Override
public TaskSummary single() {
    LOGGER.debug("entry to single(), this = {}", this);
    TaskSummary result = null;
    try {
        taskanaEngine.openConnection();
        checkOpenPermissionForSpecifiedWorkbaskets();
        TaskSummaryImpl taskSummaryImpl = taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
        if (taskSummaryImpl == null) {
            return null;
        }
        List<TaskSummaryImpl> tasks = new ArrayList<>();
        tasks.add(taskSummaryImpl);
        List<TaskSummary> augmentedList = taskService.augmentTaskSummariesByContainedSummaries(tasks);
        result = augmentedList.get(0);
        return result;
    } catch (NotAuthorizedException e) {
        throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from single(). Returning result {} ", result);
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException)

Example 35 with TaskSummary

use of pro.taskana.TaskSummary in project taskana by Taskana.

the class TaskQueryImpl method list.

@Override
public List<TaskSummary> list() {
    List<TaskSummary> result = new ArrayList<>();
    try {
        LOGGER.debug("entry to list(), this = {}", this);
        taskanaEngine.openConnection();
        checkOpenPermissionForSpecifiedWorkbaskets();
        List<TaskSummaryImpl> tasks = new ArrayList<>();
        tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("mapper returned {} resulting Objects: {} ", tasks.size(), LoggerUtils.listToString(tasks));
        }
        result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
        return result;
    } catch (NotAuthorizedException e) {
        throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException)

Aggregations

TaskSummary (pro.taskana.TaskSummary)58 Test (org.junit.Test)48 TaskService (pro.taskana.TaskService)47 WithAccessId (pro.taskana.security.WithAccessId)45 AbstractAccTest (acceptance.AbstractAccTest)44 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)17 KeyDomain (pro.taskana.KeyDomain)14 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)14 Instant (java.time.Instant)9 ArrayList (java.util.ArrayList)8 TimeInterval (pro.taskana.TimeInterval)8 Classification (pro.taskana.Classification)5 Task (pro.taskana.Task)5 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)5 NotAuthorizedToQueryWorkbasketException (pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException)5 TaskQuery (pro.taskana.TaskQuery)4 Workbasket (pro.taskana.Workbasket)3 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2