Search in sources :

Example 1 with FilterComponents

use of com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents in project midpoint by Evolveum.

the class WorkItemProvider method createTaskQuery.

// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
    List<ObjectFilter> remainingClauses = components.getRemainderClauses();
    if (!remainingClauses.isEmpty()) {
        throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
    }
    final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
    final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
    final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
    final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
    TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
    if (workItemIdFilter != null) {
        Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
        if (filterValues.size() > 1) {
            throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
        }
        taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
    }
    if (assigneeFilter != null) {
        taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
    }
    if (candidateRolesFilter != null) {
        // TODO what about candidate users? (currently these are not supported)
        List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
        if (!candidateGroups.isEmpty()) {
            taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
        } else {
            // no groups -> no result
            return null;
        }
    }
    if (query != null && query.getPaging() != null) {
        ObjectPaging paging = query.getPaging();
        if (paging.getOrderingInstructions().size() > 1) {
            throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
        } else if (paging.getOrderingInstructions().size() == 1) {
            ItemPath orderBy = paging.getOrderBy();
            if (CREATED_PATH.equivalent(orderBy)) {
                taskQuery = taskQuery.orderByTaskCreateTime();
            } else {
                throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
            }
            switch(paging.getDirection()) {
                case DESCENDING:
                    taskQuery = taskQuery.desc();
                    break;
                case ASCENDING:
                default:
                    taskQuery = taskQuery.asc();
                    break;
            }
        }
    }
    if (includeVariables) {
        return taskQuery.includeTaskLocalVariables().includeProcessVariables();
    } else {
        return taskQuery;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FilterComponents(com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) TaskQuery(org.activiti.engine.task.TaskQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)1 FilterComponents (com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 TaskQuery (org.activiti.engine.task.TaskQuery)1