Search in sources :

Example 31 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class WorkItemProvider method searchWorkItems.

public SearchResultList<WorkItemType> searchWorkItems(ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    TaskQuery taskQuery = createTaskQuery(query, true, options, result);
    if (taskQuery == null) {
        return new SearchResultList<>(Collections.emptyList());
    }
    Integer offset = query != null ? query.getOffset() : null;
    Integer maxSize = query != null ? query.getMaxSize() : null;
    List<Task> tasks;
    if (offset == null && maxSize == null) {
        tasks = taskQuery.list();
    } else {
        tasks = taskQuery.listPage(defaultIfNull(offset, 0), defaultIfNull(maxSize, Integer.MAX_VALUE));
    }
    // TODO implement based on options
    boolean getAllVariables = true;
    // there's no need to fill-in assignee details ; but candidates are necessary to fill-in; TODO implement based on options (resolve)
    return tasksToWorkItems(tasks, null, false, false, true, getAllVariables, result);
}
Also used : SearchResultList(com.evolveum.midpoint.schema.SearchResultList) Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery)

Example 32 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class ProcessInstanceManager method getProcessInstancesToKeep.

private Set<String> getProcessInstancesToKeep(OperationResult result) throws SchemaException {
    ObjectQuery query = QueryBuilder.queryFor(TaskType.class, prismContext).not().item(TaskType.F_WORKFLOW_CONTEXT, WfContextType.F_PROCESS_INSTANCE_ID).isNull().build();
    SearchResultList<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, query, null, result);
    return tasks.stream().map(t -> t.asObjectable().getWorkflowContext().getProcessInstanceId()).collect(Collectors.toSet());
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) java.util(java.util) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) TaskService(org.activiti.engine.TaskService) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WorkflowManager(com.evolveum.midpoint.wf.api.WorkflowManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) PrismContext(com.evolveum.midpoint.prism.PrismContext) CommonProcessVariableNames(com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoryService(org.activiti.engine.HistoryService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) ActivitiEngine(com.evolveum.midpoint.wf.impl.activiti.ActivitiEngine) Component(org.springframework.stereotype.Component) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 33 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class PipelineData method resolveQuery.

private Collection<ObjectReferenceType> resolveQuery(Class<? extends ObjectType> type, QueryType queryBean, ExecutionContext context, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    ObjectQuery query = context.getQueryConverter().createObjectQuery(type, queryBean);
    SearchResultList<? extends PrismObject<? extends ObjectType>> objects = context.getModelService().searchObjects(type, query, createReadOnlyCollection(), context.getTask(), result);
    return objects.stream().map(o -> ObjectTypeUtil.createObjectRef(o, context.getPrismContext())).collect(Collectors.toList());
}
Also used : GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) java.util(java.util) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DebugUtil(com.evolveum.midpoint.util.DebugUtil) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ValueListType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ValueListType) ScriptingDataUtil(com.evolveum.midpoint.model.impl.scripting.helpers.ScriptingDataUtil) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PipelineItemType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineItemType) ScriptingExpressionEvaluationOptionsType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionEvaluationOptionsType) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) DebugDumpable(com.evolveum.midpoint.util.DebugDumpable) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) Collectors(java.util.stream.Collectors) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 34 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class NodeRetriever method searchNodes.

/**
 * Gets nodes from repository and adds runtime information to them (taken from ClusterStatusInformation).
 */
@NotNull
public SearchResultList<PrismObject<NodeType>> searchNodes(ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    ClusterStatusInformation csi = clusterStatusInformationRetriever.getClusterStatusInformation(options, NodeType.class, true, result);
    List<PrismObject<NodeType>> nodesInRepository;
    try {
        nodesInRepository = repositoryService.searchObjects(NodeType.class, query, options, result);
    } catch (SchemaException e) {
        result.recordFatalError("Couldn't get nodes from repository: " + e.getMessage());
        throw e;
    }
    List<PrismObject<NodeType>> list = new ArrayList<>();
    if (csi != null) {
        for (PrismObject<NodeType> nodeInRepositoryPrism : nodesInRepository) {
            NodeType returnedNode = nodeInRepositoryPrism.asObjectable();
            NodeType nodeRuntimeInfo = csi.findNodeById(returnedNode.getNodeIdentifier());
            if (nodeRuntimeInfo != null) {
                returnedNode.setExecutionState(nodeRuntimeInfo.getExecutionState());
                returnedNode.setErrorState(nodeRuntimeInfo.getErrorState());
                returnedNode.setConnectionResult(nodeRuntimeInfo.getConnectionResult());
            } else {
                // node is in repo, but no information on it is present in CSI
                // (should not occur except for some temporary conditions, because CSI contains info on all nodes from repo)
                returnedNode.setExecutionState(NodeExecutionStateType.COMMUNICATION_ERROR);
                OperationResult r = new OperationResult("connect");
                r.recordFatalError("Node not known at this moment");
                returnedNode.setConnectionResult(r.createOperationResultType());
            }
            list.add(returnedNode.asPrismObject());
        }
    } else {
        list = nodesInRepository;
    }
    LOGGER.trace("searchNodes returning {}", list);
    return new SearchResultList<>(list);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with SearchResultList

use of com.evolveum.midpoint.schema.SearchResultList in project midpoint by Evolveum.

the class ReferenceResolverImpl method resolveFromFilter.

@NotNull
private List<PrismObject<? extends ObjectType>> resolveFromFilter(Class<? extends ObjectType> targetClass, ObjectReferenceType reference, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull Source source, FilterEvaluator filterEvaluator, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    LOGGER.trace("Resolving filter on {} from {}", targetClass.getSimpleName(), source);
    SearchFilterType filterBean = reference.getFilter();
    if (filterBean == null) {
        throw new IllegalArgumentException("The OID and filter are both null in a reference: " + reference);
    }
    ObjectFilter filter = prismContext.getQueryConverter().parseFilter(filterBean, targetClass);
    ObjectFilter evaluatedFilter = filterEvaluator != null ? filterEvaluator.evaluate(filter, result) : filter;
    if (evaluatedFilter == null) {
        throw new SchemaException("The OID is null and filter could not be evaluated in " + reference);
    }
    ObjectQuery query = prismContext.queryFactory().createQuery(evaluatedFilter);
    SearchResultList<? extends PrismObject<? extends ObjectType>> objects;
    switch(source) {
        case REPOSITORY:
            objects = repositoryService.searchObjects(targetClass, query, options, result);
            break;
        case MODEL:
            objects = modelService.searchObjects(targetClass, query, options, task, result);
            break;
        default:
            throw new AssertionError(source);
    }
    // noinspection unchecked
    return (List<PrismObject<? extends ObjectType>>) objects;
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SearchResultList (com.evolveum.midpoint.schema.SearchResultList)45 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)38 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)33 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)31 Test (org.testng.annotations.Test)28 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)27 List (java.util.List)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)26 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)25 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)24 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)23 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)23 MiscUtil (com.evolveum.midpoint.util.MiscUtil)23 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)17 TestUtil (com.evolveum.midpoint.test.util.TestUtil)17 UUID (java.util.UUID)17 BeforeClass (org.testng.annotations.BeforeClass)17 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)14 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)14 SystemException (com.evolveum.midpoint.util.exception.SystemException)10