Search in sources :

Example 86 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class ReportObjectsListPanel method customProcessNewRowItem.

@Override
protected void customProcessNewRowItem(org.apache.wicket.markup.repeater.Item<SelectableBean<C>> item, IModel<SelectableBean<C>> model) {
    if (model == null || model.getObject() == null || model.getObject().getValue() == null) {
        return;
    }
    VariablesMap variables = getSearchModel().getObject().getFilterVariables(null, getPageBase());
    variables.put(ExpressionConstants.VAR_OBJECT, model.getObject().getValue(), model.getObject().getValue().getClass());
    if (getReport().getObjectCollection() != null && getReport().getObjectCollection().getSubreport() != null && !getReport().getObjectCollection().getSubreport().isEmpty()) {
        Task task = getPageBase().createSimpleTask("evaluate subreports");
        processReferenceVariables(variables);
        VariablesMap subreportsVariables = getPageBase().getReportManager().evaluateSubreportParameters(getReport().asPrismObject(), variables, task, task.getResult());
        variables.putAll(subreportsVariables);
    }
    this.variables.clear();
    for (String key : variables.keySet()) {
        this.variables.put(key, variables.get(key).getValue());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 87 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class FlexibleLabelModel method getExpressionValue.

private String getExpressionValue(ExpressionType expressionType, String contextDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    C object = model.getObject();
    ExpressionFactory expressionFactory = serviceLocator.getExpressionFactory();
    PrismContext prismContext = object.asPrismContainerValue().getPrismContext();
    PrismPropertyDefinition<String> outputDefinition = prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_STRING);
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), contextDesc, task, result);
    VariablesMap variables = new VariablesMap();
    variables.put(ExpressionConstants.VAR_OBJECT, object, object.asPrismContainerValue().getDefinition());
    addAdditionalVariablesMap(variables);
    ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = expression.evaluate(context, result);
    if (outputTriple == null) {
        return "";
    }
    Collection<PrismPropertyValue<String>> outputValues = outputTriple.getNonNegativeValues();
    if (outputValues.isEmpty()) {
        return "";
    }
    if (outputValues.size() > 1) {
        throw new SchemaException("Expression " + contextDesc + " produced more than one value");
    }
    return outputValues.iterator().next().getRealValue();
}
Also used : ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 88 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class PageRepositoryQuery method updateRequestWithMidpointQuery.

private void updateRequestWithMidpointQuery(RepositoryQueryDiagRequest request, QName objectType, String queryText, boolean distinct, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    PrismContext prismContext = getPrismContext();
    if (objectType == null) {
        objectType = ObjectType.COMPLEX_TYPE;
    }
    @SuppressWarnings("unchecked") Class<? extends ObjectType> clazz = (Class<? extends ObjectType>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
    if (clazz == null) {
        throw new SchemaException("Couldn't find compile-time class for object type of " + objectType);
    }
    QueryType queryType = prismContext.parserFor(queryText).language(dataLanguage).parseRealValue(QueryType.class);
    request.setType(clazz);
    ObjectQuery objectQuery = prismContext.getQueryConverter().createObjectQuery(clazz, queryType);
    ObjectQuery queryWithExprEvaluated = ExpressionUtil.evaluateQueryExpressions(objectQuery, new VariablesMap(), MiscSchemaUtil.getExpressionProfile(), getExpressionFactory(), getPrismContext(), "evaluate query expressions", task, result);
    request.setQuery(queryWithExprEvaluated);
    Collection<SelectorOptions<GetOperationOptions>> options = distinct ? createCollection(createDistinct()) : null;
    request.setOptions(options);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 89 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class PageBase method executeResultScriptHook.

private OperationResult executeResultScriptHook(OperationResult result) {
    CompiledGuiProfile adminGuiConfiguration = getCompiledGuiProfile();
    if (adminGuiConfiguration.getFeedbackMessagesHook() == null) {
        return result;
    }
    FeedbackMessagesHookType hook = adminGuiConfiguration.getFeedbackMessagesHook();
    ExpressionType expressionType = hook.getOperationResultHook();
    if (expressionType == null) {
        return result;
    }
    String contextDesc = "operation result (" + result.getOperation() + ") script hook";
    Task task = getPageTask();
    OperationResult topResult = task.getResult();
    try {
        ExpressionFactory factory = getExpressionFactory();
        PrismPropertyDefinition<OperationResultType> outputDefinition = getPrismContext().definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, OperationResultType.COMPLEX_TYPE);
        Expression<PrismPropertyValue<OperationResultType>, PrismPropertyDefinition<OperationResultType>> expression = factory.makeExpression(expressionType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), contextDesc, task, topResult);
        VariablesMap variables = new VariablesMap();
        OperationResultType resultType = result.createOperationResultType();
        variables.put(ExpressionConstants.VAR_INPUT, resultType, OperationResultType.class);
        ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDesc, task);
        PrismValueDeltaSetTriple<PrismPropertyValue<OperationResultType>> outputTriple = expression.evaluate(context, topResult);
        if (outputTriple == null) {
            return null;
        }
        Collection<PrismPropertyValue<OperationResultType>> values = outputTriple.getNonNegativeValues();
        if (values == null || values.isEmpty()) {
            return null;
        }
        if (values.size() > 1) {
            throw new SchemaException("Expression " + contextDesc + " produced more than one value");
        }
        OperationResultType newResultType = values.iterator().next().getRealValue();
        if (newResultType == null) {
            return null;
        }
        return OperationResult.createOperationResult(newResultType);
    } catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
        topResult.recordFatalError(e);
        if (StringUtils.isEmpty(result.getMessage())) {
            topResult.setMessage("Couldn't process operation result script hook.");
        }
        topResult.addSubresult(result);
        LoggingUtils.logUnexpectedException(LOGGER, contextDesc, e);
        if (InternalsConfig.nonCriticalExceptionsAreFatal()) {
            throw new SystemException(e.getMessage(), e);
        } else {
            return topResult;
        }
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)

Example 90 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class RoleCatalogTabPanel method createScopeItem.

private SearchItem createScopeItem(Search search) {
    return new SpecialSearchItem(search) {

        @Override
        public ObjectFilter createFilter(PageBase pageBase, VariablesMap variables) {
            return null;
        }

        @Override
        public SearchSpecialItemPanel createSpecialSearchPanel(String id) {
            return new SearchSpecialItemPanel(id, new PropertyModel(getRoleCatalogStorage(), RoleCatalogStorage.F_ORG_SEARCH_SCOPE)) {

                @Override
                protected WebMarkupContainer initSearchItemField(String id) {
                    DropDownChoicePanel inputPanel = new DropDownChoicePanel(id, getModelValue(), Model.of(Arrays.asList(SearchBoxScopeType.values())), new EnumChoiceRenderer(), false);
                    inputPanel.getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
                    inputPanel.getBaseFormComponent().add(AttributeAppender.append("style", "width: 88px; max-width: 400px !important;"));
                    inputPanel.setOutputMarkupId(true);
                    return inputPanel;
                }

                @Override
                protected IModel<String> createLabelModel() {
                    return getPageBase().createStringResource("abstractRoleMemberPanel.searchScope");
                }

                @Override
                protected IModel<String> createHelpModel() {
                    return getPageBase().createStringResource("abstractRoleMemberPanel.searchScope.tooltip");
                }
            };
        }
    };
}
Also used : SpecialSearchItem(com.evolveum.midpoint.web.component.search.SpecialSearchItem) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) EnumChoiceRenderer(org.apache.wicket.markup.html.form.EnumChoiceRenderer) PropertyModel(org.apache.wicket.model.PropertyModel) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) SearchSpecialItemPanel(com.evolveum.midpoint.web.component.search.SearchSpecialItemPanel)

Aggregations

VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)166 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)48 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)30 Test (org.testng.annotations.Test)28 Task (com.evolveum.midpoint.task.api.Task)23 NotNull (org.jetbrains.annotations.NotNull)23 QName (javax.xml.namespace.QName)15 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)12 Source (com.evolveum.midpoint.repo.common.expression.Source)12 AbstractModelCommonTest (com.evolveum.midpoint.model.common.AbstractModelCommonTest)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)10 Trace (com.evolveum.midpoint.util.logging.Trace)10 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)10 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)8 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)8 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)7