Search in sources :

Example 96 with ObjectQuery

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());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 97 with ObjectQuery

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());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 98 with ObjectQuery

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());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 99 with ObjectQuery

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;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 100 with ObjectQuery

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;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) TypeFilter(com.evolveum.midpoint.prism.query.TypeFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)697 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)453 Test (org.testng.annotations.Test)335 PrismObject (com.evolveum.midpoint.prism.PrismObject)284 Task (com.evolveum.midpoint.task.api.Task)268 QName (javax.xml.namespace.QName)111 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)78 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)76 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)64 ArrayList (java.util.ArrayList)61 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)58 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)53 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)41 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)41 SystemException (com.evolveum.midpoint.util.exception.SystemException)38 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)37 NotNull (org.jetbrains.annotations.NotNull)35 List (java.util.List)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)32 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)27