Search in sources :

Example 21 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class TestCertificationBasic method test056SearchDecisionsByAdminStatus.

@Test
public void test056SearchDecisionsByAdminStatus() throws Exception {
    final String TEST_NAME = "test056SearchDecisionsByAdminStatus";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(getUserFromRepo(USER_ADMINISTRATOR_OID));
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCertificationBasic.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ObjectQuery query = QueryBuilder.queryFor(AccessCertificationWorkItemType.class, prismContext).exists(T_PARENT).block().item(F_ACTIVATION, F_ADMINISTRATIVE_STATUS).eq(ENABLED).and().ownerId(campaignOid).endBlock().build();
    List<AccessCertificationWorkItemType> workItems = certificationService.searchOpenWorkItems(query, false, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    display("workItems", workItems);
    assertEquals("Wrong number of certification cases", 1, workItems.size());
    checkWorkItem(workItems, USER_JACK_OID, ROLE_CEO_OID, userJack, campaignOid, ORG_GOVERNOR_OFFICE_OID, ORG_SCUMM_BAR_OID, ENABLED);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 22 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class TestCertificationBasic method test052SearchWorkItemsByTenantRef.

@Test
public void test052SearchWorkItemsByTenantRef() throws Exception {
    final String TEST_NAME = "test052SearchWorkItemsByTenantRef";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(getUserFromRepo(USER_ADMINISTRATOR_OID));
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCertificationBasic.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ObjectQuery query = QueryBuilder.queryFor(AccessCertificationWorkItemType.class, prismContext).exists(T_PARENT).block().item(AccessCertificationCaseType.F_TENANT_REF).ref(ORG_GOVERNOR_OFFICE_OID).and().ownerId(campaignOid).endBlock().build();
    List<AccessCertificationWorkItemType> workItems = certificationService.searchOpenWorkItems(query, false, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    display("workItems", workItems);
    assertEquals("Wrong number of certification cases", 1, workItems.size());
    checkWorkItem(workItems, USER_JACK_OID, ROLE_CEO_OID, userJack, campaignOid, ORG_GOVERNOR_OFFICE_OID, ORG_SCUMM_BAR_OID, ENABLED);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 23 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery 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;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationsHelper(com.evolveum.midpoint.model.impl.scripting.helpers.OperationsHelper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ExpressionHelper(com.evolveum.midpoint.model.impl.scripting.helpers.ExpressionHelper) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) JAXBElement(javax.xml.bind.JAXBElement) Collection(java.util.Collection) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) QueryConvertor(com.evolveum.midpoint.prism.marshaller.QueryConvertor) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) QueryJaxbConvertor(com.evolveum.midpoint.prism.query.QueryJaxbConvertor) Component(org.springframework.stereotype.Component) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SearchExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.SearchExpressionType) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) JAXBElement(javax.xml.bind.JAXBElement) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Example 24 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class CorrelationConfirmationEvaluator method findUsersByCorrelationRule.

private <F extends FocusType> List<PrismObject<F>> findUsersByCorrelationRule(Class<F> focusType, ShadowType currentShadow, ConditionalSearchFilterType conditionalFilter, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    if (!conditionalFilter.containsFilterClause()) {
        LOGGER.warn("Correlation rule for resource '{}' doesn't contain filter clause, " + "returning empty list of users.", resourceType);
        return null;
    }
    ObjectQuery q;
    try {
        q = QueryJaxbConvertor.createObjectQuery(focusType, conditionalFilter, prismContext);
        q = updateFilterWithAccountValues(currentShadow, resourceType, configurationType, q, "Correlation expression", task, result);
        if (q == null) {
            // to null and the processing should be skipped
            return null;
        }
    } catch (SchemaException ex) {
        LoggingUtils.logException(LOGGER, "Couldn't convert query (simplified)\n{}.", ex, SchemaDebugUtil.prettyPrint(conditionalFilter));
        throw new SchemaException("Couldn't convert query.", ex);
    } catch (ObjectNotFoundException ex) {
        LoggingUtils.logException(LOGGER, "Couldn't convert query (simplified)\n{}.", ex, SchemaDebugUtil.prettyPrint(conditionalFilter));
        throw new ObjectNotFoundException("Couldn't convert query.", ex);
    } catch (ExpressionEvaluationException ex) {
        LoggingUtils.logException(LOGGER, "Couldn't convert query (simplified)\n{}.", ex, SchemaDebugUtil.prettyPrint(conditionalFilter));
        throw new ExpressionEvaluationException("Couldn't convert query.", ex);
    }
    List<PrismObject<F>> users;
    try {
        LOGGER.trace("SYNCHRONIZATION: CORRELATION: expression for results in filter\n{}", q.debugDumpLazily());
        users = repositoryService.searchObjects(focusType, q, null, result);
    } catch (RuntimeException ex) {
        LoggingUtils.logException(LOGGER, "Couldn't search users in repository, based on filter (simplified)\n{}.", ex, q.debugDump());
        throw new SystemException("Couldn't search users in repository, based on filter (See logs).", ex);
    }
    return users;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 25 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class FocusValidityScannerTaskHandler method createQuery.

@Override
protected ObjectQuery createQuery(AbstractScannerResultHandler<UserType> handler, TaskRunResult runResult, Task coordinatorTask, OperationResult opResult) throws SchemaException {
    initProcessedOids(coordinatorTask);
    ObjectQuery query = new ObjectQuery();
    ObjectFilter filter;
    PrismObjectDefinition<UserType> focusObjectDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
    XMLGregorianCalendar lastScanTimestamp = handler.getLastScanTimestamp();
    XMLGregorianCalendar thisScanTimestamp = handler.getThisScanTimestamp();
    if (lastScanTimestamp == null) {
        filter = QueryBuilder.queryFor(FocusType.class, prismContext).item(F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp).or().item(F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp).or().exists(F_ASSIGNMENT).block().item(AssignmentType.F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp).or().item(AssignmentType.F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp).endBlock().buildFilter();
    } else {
        filter = QueryBuilder.queryFor(FocusType.class, prismContext).item(F_ACTIVATION, F_VALID_FROM).gt(lastScanTimestamp).and().item(F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp).or().item(F_ACTIVATION, F_VALID_TO).gt(lastScanTimestamp).and().item(F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp).or().exists(F_ASSIGNMENT).block().item(AssignmentType.F_ACTIVATION, F_VALID_FROM).gt(lastScanTimestamp).and().item(AssignmentType.F_ACTIVATION, F_VALID_FROM).le(thisScanTimestamp).or().item(AssignmentType.F_ACTIVATION, F_VALID_TO).gt(lastScanTimestamp).and().item(AssignmentType.F_ACTIVATION, F_VALID_TO).le(thisScanTimestamp).endBlock().buildFilter();
    }
    query.setFilter(filter);
    return query;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)355 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)241 PrismObject (com.evolveum.midpoint.prism.PrismObject)217 Test (org.testng.annotations.Test)159 Task (com.evolveum.midpoint.task.api.Task)150 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)67 QName (javax.xml.namespace.QName)58 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)50 ArrayList (java.util.ArrayList)50 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)38 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)35 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)33 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)30 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)21 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)17 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)16