use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class TestFilterExpression method test202EvaluateExpressionLinkRefObjectReferenceTypeDefaultsNull.
@Test
public void test202EvaluateExpressionLinkRefObjectReferenceTypeDefaultsNull() throws Exception {
final String TEST_NAME = "test202EvaluateExpressionLinkRefObjectReferenceTypeDefaultsNull";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestFilterExpression.class.getName() + "." + TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
ObjectFilter filter = evaluateExpressionAssertFilter("expression-linkref-object-reference-type-filter-defaults.xml", null, RefFilter.class, task, result);
RefFilter refFilter = (RefFilter) filter;
AssertJUnit.assertNull("Expected NO values in filter, but found " + refFilter.getValues(), refFilter.getValues());
executeFilter(filter, 2, task, result);
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class TestFilterExpression method test120EvaluateExpressionEmployeeTypeAllFilter.
@Test
public void test120EvaluateExpressionEmployeeTypeAllFilter() throws Exception {
final String TEST_NAME = "testEvaluateExpressionEmployeeTypeAllFilter";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestFilterExpression.class.getName() + "." + TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
ObjectFilter filter = evaluateExpressionAssertFilter("expression-employeeType-all-filter.xml", null, AllFilter.class, task, result);
executeFilter(filter, 5, task, result);
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class ProvisioningServiceImpl method searchObjectsIterative.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(final Class<T> type, ObjectQuery query, final Collection<SelectorOptions<GetOperationOptions>> options, final ResultHandler<T> handler, Task task, final OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(parentResult, "Operation result must not be null.");
Validate.notNull(handler, "Handler must not be null.");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Start to search object. Query {}", query != null ? query.debugDump() : "(null)");
}
final OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".searchObjectsIterative");
result.setSummarizeSuccesses(true);
result.setSummarizeErrors(true);
result.setSummarizePartialErrors(true);
result.addParam("query", query);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
ObjectFilter filter = null;
if (query != null) {
filter = ObjectQueryUtil.simplify(query.getFilter());
query = query.cloneEmpty();
query.setFilter(filter);
}
if (InternalsConfig.consistencyChecks && filter != null) {
// We may not have all the definitions here. We will apply the definitions later
filter.checkConsistence(false);
}
if (filter != null && filter instanceof NoneFilter) {
result.recordSuccessIfUnknown();
result.cleanupResult();
LOGGER.trace("Finished searching. Nothing to do. Filter is NONE");
SearchResultMetadata metadata = new SearchResultMetadata();
metadata.setApproxNumberOfAllResults(0);
return metadata;
}
final GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
if (!ShadowType.class.isAssignableFrom(type)) {
ResultHandler<T> internalHandler = (object, objResult) -> handleRepoObject(type, object, options, handler, task, objResult);
Collection<SelectorOptions<GetOperationOptions>> repoOptions = null;
if (GetOperationOptions.isReadOnly(rootOptions)) {
repoOptions = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
}
SearchResultMetadata metadata = null;
try {
// TODO think about strictSequential flag
metadata = getCacheRepositoryService().searchObjectsIterative(type, query, internalHandler, repoOptions, false, result);
result.computeStatus();
result.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
}
result.cleanupResult();
return metadata;
}
final boolean shouldDoRepoSearch = ProvisioningUtil.shouldDoRepoSearch(rootOptions);
final ShadowHandler shadowHandler = new ShadowHandler() {
@Override
public boolean handle(ShadowType shadowType) {
OperationResult handleResult = result.createSubresult(ProvisioningService.class.getName() + ".searchObjectsIterative.handle");
if (shouldDoRepoSearch) {
return handleRepoObject(type, (PrismObject<T>) shadowType.asPrismObject(), options, handler, task, handleResult);
}
if (shadowType == null) {
throw new IllegalArgumentException("Null shadow in call to handler");
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("searchObjectsIterative: processing shadow: {}", SchemaDebugUtil.prettyPrint(shadowType));
}
boolean doContinue;
try {
PrismObject shadow = shadowType.asPrismObject();
validateObject(shadow);
doContinue = handler.handle(shadow, handleResult);
handleResult.computeStatus();
handleResult.recordSuccessIfUnknown();
if (!handleResult.isSuccess() && !handleResult.isHandledError()) {
Collection<? extends ItemDelta> shadowModificationType = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_RESULT, getResourceObjectShadowDefinition(), handleResult.createOperationResultType());
try {
ConstraintsChecker.onShadowModifyOperation(shadowModificationType);
cacheRepositoryService.modifyObject(ShadowType.class, shadowType.getOid(), shadowModificationType, result);
} catch (ObjectNotFoundException ex) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: Not found: " + ex.getMessage(), ex);
} catch (ObjectAlreadyExistsException ex) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: Already exists: " + ex.getMessage(), ex);
} catch (SchemaException ex) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: Schema error: " + ex.getMessage(), ex);
} catch (RuntimeException e) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: " + e.getMessage(), e);
throw e;
}
}
} catch (RuntimeException e) {
result.recordFatalError(e);
throw e;
} finally {
handleResult.computeStatus();
handleResult.recordSuccessIfUnknown();
// AbstractSummarizingResultHandler [lazyman]
if (result.isSuccess()) {
result.getSubresults().clear();
}
result.summarize();
}
return doContinue;
}
};
SearchResultMetadata metadata;
try {
metadata = getShadowCache(Mode.STANDARD).searchObjectsIterative(query, options, shadowHandler, true, task, result);
result.computeStatus();
} catch (ConfigurationException | CommunicationException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
result.cleanupResult();
}
return metadata;
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class AssociationTargetSearchExpressionEvaluator method extendQuery.
@Override
protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext params) throws SchemaException, ExpressionEvaluationException {
RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) params.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDef == null) {
throw new ExpressionEvaluationException("No association target object class definition variable in " + params.getContextDescription() + "; the expression may be used in a wrong place. It is only supposed to create an association.");
}
ObjectFilter resourceFilter = ObjectQueryUtil.createResourceFilter(rAssocTargetDef.getResourceType().getOid(), getPrismContext());
ObjectFilter objectClassFilter = ObjectQueryUtil.createObjectClassFilter(rAssocTargetDef.getObjectClassDefinition().getTypeName(), getPrismContext());
ObjectFilter extendedFilter = AndFilter.createAnd(resourceFilter, objectClassFilter, query.getFilter());
query.setFilter(extendedFilter);
return query;
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class BasePrimaryChangeAspect method resolveReferenceFromFilter.
private <O extends ObjectType, F extends ObjectType> List<ObjectReferenceType> resolveReferenceFromFilter(Class<O> clazz, SearchFilterType filter, String sourceDescription, LensContext<F> lensContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ExpressionEnvironment<F> env = new ExpressionEnvironment<>();
env.setLensContext(lensContext);
env.setCurrentResult(result);
env.setCurrentTask(task);
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(env);
try {
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
ExpressionVariables variables = Utils.getDefaultExpressionVariables(getFocusObjectable(lensContext), null, null, systemConfiguration.asObjectable());
ObjectFilter origFilter = QueryConvertor.parseFilter(filter, clazz, prismContext);
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, mappingFactory.getExpressionFactory(), prismContext, " evaluating approverRef filter expression ", task, result);
if (evaluatedFilter == null) {
throw new SchemaException("Filter could not be evaluated in approverRef in " + sourceDescription + "; original filter = " + origFilter);
}
SearchResultList<PrismObject<O>> targets = repositoryService.searchObjects(clazz, ObjectQuery.createObjectQuery(evaluatedFilter), null, result);
return targets.stream().map(ObjectTypeUtil::createObjectRef).collect(Collectors.toList());
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
}
Aggregations