use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class SearchTest method notBusinessRoleTypeSearchTest.
@Test
public void notBusinessRoleTypeSearchTest() throws Exception {
ObjectQuery query = QueryBuilder.queryFor(RoleType.class, prismContext).not().item(RoleType.F_ROLE_TYPE).eq("business").build();
OperationResult result = new OperationResult("search");
List<PrismObject<RoleType>> roles = repositoryService.searchObjects(RoleType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find two roles", 2, roles.size());
int judge = roles.get(0).getName().getOrig().startsWith("J") ? 0 : 1;
assertEquals("Wrong role1 name", "Judge", roles.get(judge).getName().getOrig());
assertEquals("Wrong role2 name", "Admin-owned role", roles.get(1 - judge).getName().getOrig());
}
use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class SearchTest method testExtensionReference.
@Test
public void testExtensionReference() throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext).item(ObjectType.F_EXTENSION, new QName("referenceType")).ref("12345678-1234-1234-1234-123456789012").build();
OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> cases = repositoryService.searchObjects(GenericObjectType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find 1 object", 1, cases.size());
}
use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class SearchTest method testExtensionReferenceNotMatching.
@Test
public void testExtensionReferenceNotMatching() throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext).item(ObjectType.F_EXTENSION, new QName("referenceType")).ref("12345678-1234-1234-1234-123456789xxx").build();
OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> cases = repositoryService.searchObjects(GenericObjectType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find no object", 0, cases.size());
}
use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.
the class TaskManagerQuartzImpl method listSubtasksForTask.
public List<PrismObject<TaskType>> listSubtasksForTask(String taskIdentifier, OperationResult result) throws SchemaException {
if (StringUtils.isEmpty(taskIdentifier)) {
return new ArrayList<>();
}
ObjectQuery query = QueryBuilder.queryFor(TaskType.class, prismContext).item(TaskType.F_PARENT).eq(taskIdentifier).build();
List<PrismObject<TaskType>> list;
try {
list = repositoryService.searchObjects(TaskType.class, query, null, result);
result.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException e) {
result.recordFatalError(e);
throw e;
}
return list;
}
use of com.evolveum.midpoint.prism.query.ObjectQuery 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