Search in sources :

Example 11 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class TestCertificationBasic method test040SearchCasesFilteredSortedPaged.

@Test
public void test040SearchCasesFilteredSortedPaged() throws Exception {
    final String TEST_NAME = "test040SearchCasesFilteredSortedPaged";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(getUserFromRepo(USER_BOB_OID));
    // GIVEN
    Task task = taskManager.createTaskInstance(TestCertificationBasic.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    Collection<SelectorOptions<GetOperationOptions>> resolveNames = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
    ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).item(AccessCertificationCaseType.F_OBJECT_REF).ref(userAdministrator.getOid()).desc(AccessCertificationCaseType.F_TARGET_REF, PrismConstants.T_OBJECT_REFERENCE, ObjectType.F_NAME).offset(2).maxSize(2).build();
    List<AccessCertificationCaseType> caseList = modelService.searchContainers(AccessCertificationCaseType.class, query, resolveNames, task, result);
    // THEN
    // Cases for administrator are (ordered by name, descending):
    //  - Superuser
    //  - ERoot
    //  - COO
    //  - CEO
    // so paging (2, 2) should return the last two
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    display("caseList", caseList);
    assertEquals("Wrong number of certification cases", 2, caseList.size());
    checkCase(caseList, USER_ADMINISTRATOR_OID, ROLE_COO_OID, userAdministrator, campaignOid);
    checkCase(caseList, USER_ADMINISTRATOR_OID, ROLE_CEO_OID, userAdministrator, campaignOid);
    assertEquals("Wrong target OID in case #0", ROLE_COO_OID, caseList.get(0).getTargetRef().getOid());
    assertEquals("Wrong target OID in case #1", ROLE_CEO_OID, caseList.get(1).getTargetRef().getOid());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 12 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions 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 13 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class DeleteAllPanel method countShadows.

private void countShadows(boolean isAccountShadow) {
    DeleteAllDto dto = model.getObject();
    Task task = getPagebase().createSimpleTask(OPERATION_SEARCH_ITERATIVE_TASK);
    OperationResult result = new OperationResult(OPERATION_SEARCH_ITERATIVE_TASK);
    Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
    GetOperationOptions opt = GetOperationOptions.createRaw();
    options.add(SelectorOptions.create(ItemPath.EMPTY_PATH, opt));
    try {
        ObjectFilter filter = QueryBuilder.queryFor(ShadowType.class, getPagebase().getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).buildFilter();
        if (isAccountShadow) {
            ObjectQuery query = ObjectQuery.createObjectQuery(filter);
            dto.setAccountShadowCount(getPagebase().getModelService().countObjects(ShadowType.class, query, options, task, result));
            dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getAccountShadowCount());
        } else {
            ObjectQuery query = ObjectQuery.createObjectQuery(NotFilter.createNot(filter));
            dto.setNonAccountShadowCount(getPagebase().getModelService().countObjects(ShadowType.class, query, options, task, result));
            dto.setObjectsToDelete(dto.getObjectsToDelete() + dto.getNonAccountShadowCount());
        }
    } catch (Exception ex) {
        result.computeStatus(getString("deleteAllDialog.message.countSearchProblem"));
        LoggingUtils.logUnexpectedException(LOGGER, getString("deleteAllDialog.message.countSearchProblem"), ex);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 14 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class ModelRestService method getValuePolicyForUser.

@GET
@Path("/users/{id}/policy")
public Response getValuePolicyForUser(@PathParam("id") String oid, @Context MessageContext mc) {
    LOGGER.debug("getValuePolicyForUser start");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_GET);
    Response response;
    try {
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
        PrismObject<UserType> user = model.getObject(UserType.class, oid, options, task, parentResult);
        CredentialsPolicyType policy = modelInteraction.getCredentialsPolicy(user, task, parentResult);
        response = RestServiceUtil.createResponse(Response.Status.OK, policy, parentResult);
    //			ResponseBuilder builder = Response.ok();
    //			builder.entity(policy);
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    LOGGER.debug("getValuePolicyForUser finish");
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with SelectorOptions

use of com.evolveum.midpoint.schema.SelectorOptions in project midpoint by Evolveum.

the class ModelRestService method compare.

@POST
@Path("/rpc/compare")
//	@Produces({"text/html", "application/xml"})
@Consumes({ "application/xml" })
public <T extends ObjectType> Response compare(PrismObject<T> clientObject, @QueryParam("readOptions") List<String> restReadOptions, @QueryParam("compareOptions") List<String> restCompareOptions, @QueryParam("ignoreItems") List<String> restIgnoreItems, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult result = task.getResult().createSubresult(OPERATION_COMPARE);
    Response response;
    try {
        ResponseBuilder builder;
        List<ItemPath> ignoreItemPaths = ItemPath.fromStringList(restIgnoreItems);
        final GetOperationOptions getOpOptions = GetOperationOptions.fromRestOptions(restReadOptions);
        Collection<SelectorOptions<GetOperationOptions>> readOptions = getOpOptions != null ? SelectorOptions.createCollection(getOpOptions) : null;
        ModelCompareOptions compareOptions = ModelCompareOptions.fromRestOptions(restCompareOptions);
        CompareResultType compareResult = modelService.compareObject(clientObject, readOptions, compareOptions, ignoreItemPaths, task, result);
        response = RestServiceUtil.createResponse(Response.Status.OK, compareResult, result);
    //			builder = Response.ok();
    //			builder.entity(compareResult);
    //
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(result, ex);
    }
    result.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)127 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)106 Task (com.evolveum.midpoint.task.api.Task)82 Test (org.testng.annotations.Test)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)34 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)31 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)31 PrismObject (com.evolveum.midpoint.prism.PrismObject)28 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)28 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ArrayList (java.util.ArrayList)19 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)17 QName (javax.xml.namespace.QName)17 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)16 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)16 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)14 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)14 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12