Search in sources :

Example 1 with SearchResultList

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

the class TestActivitiQuery method test100SearchByMoreAssignees.

@Test
public void test100SearchByMoreAssignees() throws Exception {
    final String TEST_NAME = "test100SearchByMoreAssignees";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // should start approval process
    assignRole(userJackOid, roleRole1aOid, task, result);
    assertNotAssignedRole(userJackOid, roleRole1aOid, task, result);
    {
        SearchResultList<WorkItemType> itemsAll = modelService.searchContainers(WorkItemType.class, null, null, task, result);
        assertEquals("Wrong # of total work items", 1, itemsAll.size());
    }
    {
        ObjectQuery query2 = QueryBuilder.queryFor(WorkItemType.class, prismContext).item(WorkItemType.F_ASSIGNEE_REF).ref(userLead1Oid).build();
        SearchResultList<WorkItemType> items2 = modelService.searchContainers(WorkItemType.class, query2, null, task, result);
        assertEquals("Wrong # of work items found using single-assignee query", 1, items2.size());
    }
    {
        List<PrismReferenceValue> refs = new ArrayList<>();
        refs.add(prv("oid-number-1"));
        refs.add(prv(userLead1Oid));
        refs.add(prv("oid-number-3"));
        ObjectQuery query3 = QueryBuilder.queryFor(WorkItemType.class, prismContext).item(WorkItemType.F_ASSIGNEE_REF).ref(refs).build();
        SearchResultList<WorkItemType> items3 = modelService.searchContainers(WorkItemType.class, query3, null, task, result);
        assertEquals("Wrong # of work items found using multi-assignee query", 1, items3.size());
    }
}
Also used : SearchResultList(com.evolveum.midpoint.schema.SearchResultList) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ArrayList(java.util.ArrayList) List(java.util.List) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType) Test(org.testng.annotations.Test)

Example 2 with SearchResultList

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

the class AbstractLdapTest method doSearch.

protected SearchResultList<PrismObject<ShadowType>> doSearch(final String TEST_NAME, ObjectQuery query, GetOperationOptions rootOptions, int expectedSize, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    final List<PrismObject<ShadowType>> foundObjects = new ArrayList<PrismObject<ShadowType>>(expectedSize);
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            //				LOGGER.trace("Found {}", object);
            String name = object.asObjectable().getName().getOrig();
            for (PrismObject<ShadowType> foundShadow : foundObjects) {
                if (!allowDuplicateSearchResults() && foundShadow.asObjectable().getName().getOrig().equals(name)) {
                    AssertJUnit.fail("Duplicate name " + name);
                }
            }
            foundObjects.add(object);
            return true;
        }
    };
    Collection<SelectorOptions<GetOperationOptions>> options = null;
    if (rootOptions != null) {
        options = SelectorOptions.createCollection(rootOptions);
    }
    rememberConnectorOperationCount();
    rememberConnectorSimulatedPagingSearchCount();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    display("Searching shadows, options=" + options + ", query", query);
    SearchResultMetadata searchResultMetadata = modelService.searchObjectsIterative(ShadowType.class, query, handler, options, task, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess(result);
    if (expectedSize != foundObjects.size()) {
        if (foundObjects.size() < 10) {
            display("Found objects", foundObjects);
            AssertJUnit.fail("Unexpected number of accounts. Expected " + expectedSize + ", found " + foundObjects.size() + ": " + foundObjects);
        } else {
            AssertJUnit.fail("Unexpected number of accounts. Expected " + expectedSize + ", found " + foundObjects.size() + " (too many to display)");
        }
    }
    SearchResultList<PrismObject<ShadowType>> resultList = new SearchResultList<>(foundObjects, searchResultMetadata);
    return resultList;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Example 3 with SearchResultList

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

the class TaskManagerQuartzImpl method searchTasks.

public SearchResultList<PrismObject<TaskType>> searchTasks(ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    // returns null if noFetch is set
    ClusterStatusInformation clusterStatusInformation = getClusterStatusInformation(options, TaskType.class, true, result);
    List<PrismObject<TaskType>> tasksInRepository;
    try {
        tasksInRepository = repositoryService.searchObjects(TaskType.class, query, options, result);
    } catch (SchemaException e) {
        result.recordFatalError("Couldn't get tasks from repository: " + e.getMessage(), e);
        throw e;
    }
    boolean retrieveNextRunStartTime = SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NEXT_RUN_START_TIMESTAMP), options);
    boolean retrieveRetryTime = SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NEXT_RETRY_TIMESTAMP), options);
    boolean retrieveNodeAsObserved = SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NODE_AS_OBSERVED), options);
    List<PrismObject<TaskType>> retval = new ArrayList<>();
    for (PrismObject<TaskType> taskInRepository : tasksInRepository) {
        TaskType taskInResult = addTransientTaskInformation(taskInRepository, clusterStatusInformation, retrieveNextRunStartTime, retrieveRetryTime, retrieveNodeAsObserved, result);
        retval.add(taskInResult.asPrismObject());
    }
    result.computeStatus();
    return new SearchResultList(retval);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with SearchResultList

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

the class WorkflowManagerImpl method searchContainers.

@SuppressWarnings("unchecked")
@Override
public <T extends Containerable> SearchResultList<T> searchContainers(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) throws SchemaException {
    OperationResult result = parentResult.createSubresult(DOT_INTERFACE + ".searchContainers");
    result.addParams(new String[] { "type", "query" }, type, query);
    result.addCollectionOfSerializablesAsParam("options", options);
    try {
        if (!WorkItemType.class.equals(type)) {
            throw new UnsupportedOperationException("searchContainers is available only for work items");
        }
        return (SearchResultList<T>) workItemProvider.searchWorkItems(query, options, result);
    } catch (SchemaException | RuntimeException e) {
        result.recordFatalError("Couldn't count items: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 5 with SearchResultList

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

the class ExecutionHelper method checkDependentCases.

/**
 * We need to check
 * 1) if there are any executable cases that depend on this one
 * 2) if we can close the parent (root)
 */
public void checkDependentCases(String rootOid, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    CaseType rootCase = repositoryService.getObject(CaseType.class, rootOid, null, result).asObjectable();
    if (CaseTypeUtil.isClosed(rootCase)) {
        return;
    }
    List<CaseType> subcases = miscHelper.getSubcases(rootOid, result);
    LOGGER.debug("Subcases:");
    for (CaseType subcase : subcases) {
        LOGGER.debug(" - {}: state={}, closeTS={}", subcase, subcase.getState(), subcase.getCloseTimestamp());
    }
    List<String> openOids = subcases.stream().filter(c -> !CaseTypeUtil.isClosed(c)).map(ObjectType::getOid).collect(Collectors.toList());
    LOGGER.debug("open cases OIDs: {}", openOids);
    if (openOids.isEmpty()) {
        closeCaseInRepository(rootCase, result);
    } else {
        ObjectQuery query = prismContext.queryFor(TaskType.class).item(TaskType.F_OBJECT_REF).ref(openOids.toArray(new String[0])).and().item(TaskType.F_EXECUTION_STATE).eq(TaskExecutionStateType.WAITING).build();
        SearchResultList<PrismObject<TaskType>> waitingTasks = repositoryService.searchObjects(TaskType.class, query, null, result);
        LOGGER.debug("Waiting tasks: {}", waitingTasks);
        for (PrismObject<TaskType> waitingTask : waitingTasks) {
            String waitingCaseOid = waitingTask.asObjectable().getObjectRef().getOid();
            assert waitingCaseOid != null;
            List<CaseType> waitingCaseList = subcases.stream().filter(c -> waitingCaseOid.equals(c.getOid())).collect(Collectors.toList());
            assert waitingCaseList.size() == 1;
            Set<String> prerequisiteOids = waitingCaseList.get(0).getPrerequisiteRef().stream().map(ObjectReferenceType::getOid).collect(Collectors.toSet());
            Collection<String> openPrerequisites = CollectionUtils.intersection(prerequisiteOids, openOids);
            LOGGER.trace("prerequisite OIDs = {}; intersection with open OIDs = {}", prerequisiteOids, openPrerequisites);
            if (openPrerequisites.isEmpty()) {
                LOGGER.trace("All prerequisites are fulfilled, going to release the task {}", waitingTask);
                try {
                    taskManager.unpauseTask(taskManager.createTaskInstance(waitingTask, result), result);
                } catch (PreconditionViolationException e) {
                    LoggingUtils.logException(LOGGER, "Race condition when unpausing the task. " + "It may or may not be unpaused now. Continuing.", e);
                }
            } else {
                LOGGER.trace("...task is not released and continues waiting for those cases");
            }
        }
    }
}
Also used : CaseTypeUtil(com.evolveum.midpoint.schema.util.cases.CaseTypeUtil) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) WorkItemHelper(com.evolveum.midpoint.cases.impl.engine.helpers.WorkItemHelper) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Duration(javax.xml.datatype.Duration) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AuthorizationHelper(com.evolveum.midpoint.cases.impl.helpers.AuthorizationHelper) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) TriggerHelper(com.evolveum.midpoint.cases.impl.engine.helpers.TriggerHelper) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) CaseMiscHelper(com.evolveum.midpoint.cases.impl.helpers.CaseMiscHelper) Collection(java.util.Collection) Set(java.util.Set) ExpressionEvaluationHelper(com.evolveum.midpoint.wf.impl.processes.common.ExpressionEvaluationHelper) 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) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) List(java.util.List) Component(org.springframework.stereotype.Component) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PrimaryChangeProcessor(com.evolveum.midpoint.wf.impl.processors.primary.PrimaryChangeProcessor) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) StageComputeHelper(com.evolveum.midpoint.wf.impl.processes.common.StageComputeHelper) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Clock(com.evolveum.midpoint.common.Clock) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException)

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