use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class WorkItemProvider method createTaskQuery.
// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
List<ObjectFilter> remainingClauses = components.getRemainderClauses();
if (!remainingClauses.isEmpty()) {
throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
}
final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
if (workItemIdFilter != null) {
Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
if (filterValues.size() > 1) {
throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
}
taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
}
if (assigneeFilter != null) {
taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
}
if (candidateRolesFilter != null) {
// TODO what about candidate users? (currently these are not supported)
List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
if (!candidateGroups.isEmpty()) {
taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
} else {
// no groups -> no result
return null;
}
}
if (query != null && query.getPaging() != null) {
ObjectPaging paging = query.getPaging();
if (paging.getOrderingInstructions().size() > 1) {
throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
} else if (paging.getOrderingInstructions().size() == 1) {
ItemPath orderBy = paging.getOrderBy();
if (CREATED_PATH.equivalent(orderBy)) {
taskQuery = taskQuery.orderByTaskCreateTime();
} else {
throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
}
switch(paging.getDirection()) {
case DESCENDING:
taskQuery = taskQuery.desc();
break;
case ASCENDING:
default:
taskQuery = taskQuery.asc();
break;
}
}
}
if (includeVariables) {
return taskQuery.includeTaskLocalVariables().includeProcessVariables();
} else {
return taskQuery;
}
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class ProvisioningServiceImpl method countObjects.
public <T extends ObjectType> Integer countObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".countObjects");
result.addParam("objectType", type);
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 (filter != null && filter instanceof NoneFilter) {
result.recordSuccessIfUnknown();
result.cleanupResult();
LOGGER.trace("Finished counting. Nothing to do. Filter is NONE");
return 0;
}
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
if (!ShadowType.class.isAssignableFrom(type) || GetOperationOptions.isNoFetch(rootOptions) || GetOperationOptions.isRaw(rootOptions)) {
int count = getCacheRepositoryService().countObjects(type, query, parentResult);
result.computeStatus();
result.recordSuccessIfUnknown();
result.cleanupResult();
return count;
}
Integer count;
try {
count = getShadowCache(Mode.STANDARD).countObjects(query, 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 count;
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method searchObjects.
@NotNull
@Override
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
Validate.notNull(type, "Object type must not be null.");
Validate.notNull(result, "Operation result must not be null.");
logSearchInputParameters(type, query, false, null);
OperationResult subResult = result.createSubresult(SEARCH_OBJECTS);
subResult.addParam("type", type.getName());
subResult.addParam("query", query);
if (query != null) {
ObjectFilter filter = query.getFilter();
filter = ObjectQueryUtil.simplify(filter);
if (filter instanceof NoneFilter) {
subResult.recordSuccess();
return new SearchResultList(new ArrayList<PrismObject<T>>(0));
} else {
query = replaceSimplifiedFilter(query, filter);
}
}
SqlPerformanceMonitor pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart("searchObjects");
final String operation = "searching";
int attempt = 1;
try {
while (true) {
try {
return objectRetriever.searchObjectsAttempt(type, query, options, subResult);
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, subResult);
pm.registerOperationNewTrial(opHandle, attempt);
}
}
} finally {
pm.registerOperationFinish(opHandle, attempt);
}
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method searchObjectsIterative.
@Override
public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<T> type, ObjectQuery query, ResultHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> options, boolean strictlySequential, OperationResult result) throws SchemaException {
Validate.notNull(type, "Object type must not be null.");
Validate.notNull(handler, "Result handler must not be null.");
Validate.notNull(result, "Operation result must not be null.");
logSearchInputParameters(type, query, true, strictlySequential);
OperationResult subResult = result.createSubresult(SEARCH_OBJECTS_ITERATIVE);
subResult.addParam("type", type.getName());
subResult.addParam("query", query);
if (query != null) {
ObjectFilter filter = query.getFilter();
filter = ObjectQueryUtil.simplify(filter);
if (filter instanceof NoneFilter) {
subResult.recordSuccess();
return null;
} else {
query = replaceSimplifiedFilter(query, filter);
}
}
if (getConfiguration().isIterativeSearchByPaging()) {
if (strictlySequential) {
objectRetriever.searchObjectsIterativeByPagingStrictlySequential(type, query, handler, options, subResult);
} else {
objectRetriever.searchObjectsIterativeByPaging(type, query, handler, options, subResult);
}
return null;
}
// turned off until resolved 'unfinished operation' warning
// SqlPerformanceMonitor pm = getPerformanceMonitor();
// long opHandle = pm.registerOperationStart(SEARCH_OBJECTS_ITERATIVE);
final String operation = "searching iterative";
int attempt = 1;
try {
while (true) {
try {
objectRetriever.searchObjectsIterativeAttempt(type, query, handler, options, subResult);
return null;
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, subResult);
// pm.registerOperationNewTrial(opHandle, attempt);
}
}
} finally {
// pm.registerOperationFinish(opHandle, attempt);
}
}
use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.
the class ReportServiceImpl method parseQuery.
@Override
public ObjectQuery parseQuery(String query, Map<QName, Object> parameters) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
if (StringUtils.isBlank(query)) {
return null;
}
ObjectQuery parsedQuery;
try {
Task task = taskManager.createTaskInstance();
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, task.getResult()));
SearchFilterType filter = prismContext.parserFor(query).parseRealValue(SearchFilterType.class);
LOGGER.trace("filter {}", filter);
ObjectFilter f = QueryConvertor.parseFilter(filter, UserType.class, prismContext);
LOGGER.trace("f {}", f.debugDump());
if (!(f instanceof TypeFilter)) {
throw new IllegalArgumentException("Defined query must contain type. Use 'type filter' in your report query.");
}
ObjectFilter subFilter = ((TypeFilter) f).getFilter();
ObjectQuery q = ObjectQuery.createObjectQuery(subFilter);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinitions(parameters);
q = ExpressionUtil.evaluateQueryExpressions(q, variables, expressionFactory, prismContext, "parsing expression values for report", task, task.getResult());
((TypeFilter) f).setFilter(q.getFilter());
parsedQuery = ObjectQuery.createObjectQuery(f);
LOGGER.trace("query dump {}", parsedQuery.debugDump());
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
// TODO Auto-generated catch block
throw e;
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
return parsedQuery;
}
Aggregations