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());
}
}
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;
}
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);
}
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();
}
}
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");
}
}
}
}
Aggregations