use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class TestCertificationBasic method test040SearchCasesFilteredSortedPaged.
@Test
public void test040SearchCasesFilteredSortedPaged() throws Exception {
final String TEST_NAME = "test040SearchCasesFilteredSortedPaged";
TestUtil.displayTestTile(this, TEST_NAME);
login(getUserFromRepo(USER_BOB_OID));
// GIVEN
Task task = taskManager.createTaskInstance(TestCertificationBasic.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
TestUtil.displayWhen(TEST_NAME);
Collection<SelectorOptions<GetOperationOptions>> resolveNames = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).item(AccessCertificationCaseType.F_OBJECT_REF).ref(userAdministrator.getOid()).desc(AccessCertificationCaseType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME).offset(2).maxSize(2).build();
List<AccessCertificationCaseType> caseList = modelService.searchContainers(AccessCertificationCaseType.class, query, resolveNames, task, result);
// THEN
// Cases for administrator are (ordered by name, descending):
// - Superuser
// - ERoot
// - COO
// - CEO
// so paging (2, 2) should return the last two
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
display("caseList", caseList);
assertEquals("Wrong number of certification cases", 2, caseList.size());
checkCase(caseList, USER_ADMINISTRATOR_OID, ROLE_COO_OID, userAdministrator, campaignOid);
checkCase(caseList, USER_ADMINISTRATOR_OID, ROLE_CEO_OID, userAdministrator, campaignOid);
assertEquals("Wrong target OID in case #0", ROLE_COO_OID, caseList.get(0).getTargetRef().getOid());
assertEquals("Wrong target OID in case #1", ROLE_CEO_OID, caseList.get(1).getTargetRef().getOid());
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class SearchEvaluator method evaluate.
public <T extends ObjectType> PipelineData evaluate(SearchExpressionType searchExpression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
Validate.notNull(searchExpression.getType());
boolean noFetch = expressionHelper.getArgumentAsBoolean(searchExpression.getParameter(), PARAM_NO_FETCH, input, context, false, "search", globalResult);
@SuppressWarnings({ "unchecked", "raw" }) Class<T> objectClass = (Class<T>) ObjectTypes.getObjectTypeFromTypeQName(searchExpression.getType()).getClassDefinition();
ObjectQuery objectQuery = null;
if (searchExpression.getQuery() != null) {
try {
objectQuery = QueryJaxbConvertor.createObjectQuery(objectClass, searchExpression.getQuery(), prismContext);
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't parse object query due to schema exception", e);
}
} else if (searchExpression.getSearchFilter() != null) {
// todo resolve variable references in the filter
objectQuery = new ObjectQuery();
try {
ObjectFilter filter = QueryConvertor.parseFilter(searchExpression.getSearchFilter(), objectClass, prismContext);
objectQuery.setFilter(filter);
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't parse object filter due to schema exception", e);
}
}
final String variableName = searchExpression.getVariable();
final PipelineData oldVariableValue = variableName != null ? context.getVariable(variableName) : null;
final PipelineData outputData = PipelineData.createEmpty();
final MutableBoolean atLeastOne = new MutableBoolean(false);
ResultHandler<T> handler = (object, parentResult) -> {
context.checkTaskStop();
atLeastOne.setValue(true);
if (searchExpression.getScriptingExpression() != null) {
if (variableName != null) {
context.setVariable(variableName, PipelineData.create(object.getValue()));
}
JAXBElement<?> childExpression = searchExpression.getScriptingExpression();
try {
outputData.addAllFrom(scriptingExpressionEvaluator.evaluateExpression((ScriptingExpressionType) childExpression.getValue(), PipelineData.create(object.getValue()), context, globalResult));
globalResult.setSummarizeSuccesses(true);
globalResult.summarize();
} catch (ScriptExecutionException e) {
// todo think about this
if (context.isContinueOnAnyError()) {
LoggingUtils.logUnexpectedException(LOGGER, "Exception when evaluating item from search result list.", e);
} else {
throw new SystemException(e);
}
}
} else {
outputData.addValue(object.getValue());
}
return true;
};
try {
Collection<SelectorOptions<GetOperationOptions>> options = operationsHelper.createGetOptions(searchExpression.getOptions(), noFetch);
modelService.searchObjectsIterative(objectClass, objectQuery, handler, options, context.getTask(), globalResult);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
// TODO continue on any error?
throw new ScriptExecutionException("Couldn't execute searchObjects operation: " + e.getMessage(), e);
}
if (atLeastOne.isFalse()) {
String matching = objectQuery != null ? "matching " : "";
// temporary hack, this will be configurable
context.println("Warning: no " + matching + searchExpression.getType().getLocalPart() + " object found");
}
if (variableName != null) {
context.setVariable(variableName, oldVariableValue);
}
return outputData;
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class DeleteAllPanel method countShadows.
private void countShadows(boolean isAccountShadow) {
DeleteAllDto dto = model.getObject();
Task task = getPagebase().createSimpleTask(OPERATION_SEARCH_ITERATIVE_TASK);
OperationResult result = new OperationResult(OPERATION_SEARCH_ITERATIVE_TASK);
Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
GetOperationOptions opt = GetOperationOptions.createRaw();
options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, opt));
try {
ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, getPagebase().getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).buildFilter();
if (isAccountShadow) {
ObjectQuery query = ObjectQuery.createObjectQuery(filter);
dto.setAccountShadowCount(getPagebase().getModelService().countObjects(ShadowType.class, query, options, task, result));
dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getAccountShadowCount());
} else {
ObjectQuery query = ObjectQuery.createObjectQuery(NotFilter.createNot(filter));
dto.setNonAccountShadowCount(getPagebase().getModelService().countObjects(ShadowType.class, query, options, task, result));
dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getNonAccountShadowCount());
}
} catch (Exception ex) {
result.computeStatus(getString("deleteAllDialog.message.countSearchProblem"));
LoggingUtils.logUnexpectedException(LOGGER, getString("deleteAllDialog.message.countSearchProblem"), ex);
}
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ModelRestService method getValuePolicyForUser.
@GET
@Path("/users/{id}/policy")
public Response getValuePolicyForUser(@PathParam("id") String oid, @Context MessageContext mc) {
LOGGER.debug("getValuePolicyForUser start");
Task task = RestServiceUtil.initRequest(mc);
OperationResult parentResult = task.getResult().createSubresult(OPERATION_GET);
Response response;
try {
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
PrismObject<UserType> user = model.getObject(UserType.class, oid, options, task, parentResult);
CredentialsPolicyType policy = modelInteraction.getCredentialsPolicy(user, task, parentResult);
response = RestServiceUtil.createResponse(Response.Status.OK, policy, parentResult);
// ResponseBuilder builder = Response.ok();
// builder.entity(policy);
// response = builder.build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(parentResult, ex);
}
parentResult.computeStatus();
finishRequest(task);
LOGGER.debug("getValuePolicyForUser finish");
return response;
}
use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.
the class ModelRestService method compare.
@POST
@Path("/rpc/compare")
// @Produces({"text/html", "application/xml"})
@Consumes({ "application/xml" })
public <T extends ObjectType> Response compare(PrismObject<T> clientObject, @QueryParam("readOptions") List<String> restReadOptions, @QueryParam("compareOptions") List<String> restCompareOptions, @QueryParam("ignoreItems") List<String> restIgnoreItems, @Context MessageContext mc) {
Task task = RestServiceUtil.initRequest(mc);
OperationResult result = task.getResult().createSubresult(OPERATION_COMPARE);
Response response;
try {
ResponseBuilder builder;
List<ItemPath> ignoreItemPaths = ItemPath.fromStringList(restIgnoreItems);
final GetOperationOptions getOpOptions = GetOperationOptions.fromRestOptions(restReadOptions);
Collection<SelectorOptions<GetOperationOptions>> readOptions = getOpOptions != null ? SelectorOptions.createCollection(getOpOptions) : null;
ModelCompareOptions compareOptions = ModelCompareOptions.fromRestOptions(restCompareOptions);
CompareResultType compareResult = modelService.compareObject(clientObject, readOptions, compareOptions, ignoreItemPaths, task, result);
response = RestServiceUtil.createResponse(Response.Status.OK, compareResult, result);
// builder = Response.ok();
// builder.entity(compareResult);
//
// response = builder.build();
} catch (Exception ex) {
response = RestServiceUtil.handleException(result, ex);
}
result.computeStatus();
finishRequest(task);
return response;
}
Aggregations