Search in sources :

Example 1 with LocalizableMessageType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizableMessageType in project midpoint by Evolveum.

the class StateConstraintEvaluator method evaluateForObject.

private <AH extends AssignmentHolderType> EvaluatedStateTrigger evaluateForObject(JAXBElement<StatePolicyConstraintType> constraintElement, PolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    StatePolicyConstraintType constraint = constraintElement.getValue();
    int count = (constraint.getFilter() != null ? 1 : 0) + (constraint.getExpression() != null ? 1 : 0) + (constraint.getMessageExpression() != null ? 1 : 0) + (constraint.getExecuteScript() != null ? 1 : 0);
    if (count != 1) {
        throw new SchemaException("Exactly one of filter, expression, messageExpression, executeScript element must be present.");
    }
    PrismObject<AH> object = ctx.getObject();
    if (object == null) {
        return null;
    }
    if (constraint.getFilter() != null) {
        ObjectFilter filter = prismContext.getQueryConverter().parseFilter(constraint.getFilter(), object.asObjectable().getClass());
        if (!filter.match(object.getValue(), matchingRuleRegistry)) {
            return null;
        }
    }
    if (constraint.getExecuteScript() != null) {
        VariablesMap variables = new VariablesMap();
        variables.put(VAR_OBJECT, object, object.getDefinition());
        variables.put(VAR_RULE_EVALUATION_CONTEXT, ctx, PolicyRuleEvaluationContext.class);
        ExecutionContext resultingContext;
        try {
            resultingContext = scriptingExpressionEvaluator.evaluateExpressionPrivileged(constraint.getExecuteScript(), variables, ctx.task, result);
        } catch (ScriptExecutionException e) {
            // TODO
            throw new SystemException(e);
        }
        PipelineData output = resultingContext.getFinalOutput();
        LOGGER.trace("Scripting expression returned {} item(s); console output is:\n{}", output != null ? output.getData().size() : null, resultingContext.getConsoleOutput());
        List<PipelineItem> items = output != null ? output.getData() : emptyList();
        if (items.isEmpty()) {
            return null;
        }
    // TODO retrieve localization messages from output
    }
    if (constraint.getMessageExpression() != null) {
        LocalizableMessageType messageBean = evaluatorHelper.evaluateLocalizableMessageType(constraint.getMessageExpression(), evaluatorHelper.createVariablesMap(ctx, constraintElement), "message expression in object state constraint " + constraint.getName() + " (" + ctx.state + ")", ctx.task, result);
        if (messageBean == null) {
            return null;
        } else {
            LocalizableMessage message = LocalizationUtil.toLocalizableMessage(messageBean);
            return new EvaluatedStateTrigger(OBJECT_STATE, constraint, message, message);
        }
    }
    if (constraint.getExpression() != null) {
        if (!evaluatorHelper.evaluateBoolean(constraint.getExpression(), evaluatorHelper.createVariablesMap(ctx, constraintElement), "expression in object state constraint " + constraint.getName() + " (" + ctx.state + ")", ctx.task, result)) {
            return null;
        }
    }
    return new EvaluatedStateTrigger(OBJECT_STATE, constraint, createMessage(OBJECT_CONSTRAINT_KEY_PREFIX, constraintElement, ctx, false, result), createShortMessage(OBJECT_CONSTRAINT_KEY_PREFIX, constraintElement, ctx, false, result));
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) LocalizableMessageType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizableMessageType) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) StatePolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.StatePolicyConstraintType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) EvaluatedStateTrigger(com.evolveum.midpoint.model.api.context.EvaluatedStateTrigger) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) SystemException(com.evolveum.midpoint.util.exception.SystemException) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 2 with LocalizableMessageType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizableMessageType in project midpoint by Evolveum.

the class InformationPanel method initLayout.

private void initLayout() {
    Label titleLabel = new Label(ID_TITLE, new LocalizableMessageModel(new IModel<LocalizableMessageType>() {

        @Override
        public LocalizableMessageType getObject() {
            InformationType info = getModelObject();
            if (info == null || info.getTitle() == null && info.getLocalizableTitle() == null) {
                return new SingleLocalizableMessageType().fallbackMessage("ApprovalStageDefinitionType.additionalInformation");
            }
            return getLocalizableMessageOrDefault(info.getLocalizableTitle(), info.getTitle());
        }
    }, this));
    titleLabel.add(new VisibleBehaviour(() -> getModelObject() != null));
    add(titleLabel);
    ListView<InformationPartType> list = new ListView<InformationPartType>(ID_PARTS, new PropertyModel<>(getModel(), InformationType.F_PART.getLocalPart())) {

        @Override
        protected void populateItem(ListItem<InformationPartType> item) {
            InformationPartType part = item.getModelObject();
            Label label = new Label(ID_PART, part != null ? WebComponentUtil.resolveLocalizableMessage(getLocalizableMessageOrDefault(part.getLocalizableText(), part.getText()), InformationPanel.this) : "");
            if (Boolean.TRUE.equals(part.isHasMarkup())) {
                label.setEscapeModelStrings(false);
            }
            item.add(label);
        }
    };
    add(list);
}
Also used : IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) LocalizableMessageModel(com.evolveum.midpoint.web.component.util.LocalizableMessageModel) ListItem(org.apache.wicket.markup.html.list.ListItem) InformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.InformationType) InformationPartType(com.evolveum.midpoint.xml.ns._public.common.common_3.InformationPartType) SingleLocalizableMessageType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleLocalizableMessageType)

Example 3 with LocalizableMessageType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizableMessageType in project midpoint by Evolveum.

the class TestPrismSerialization method testSerializeExecuteCredentialResetResponseType.

@Test
public void testSerializeExecuteCredentialResetResponseType() throws Exception {
    PrismContext prismContext = getPrismContext();
    SingleLocalizableMessage localizableMessage = new SingleLocalizableMessage("execute.reset.credential.bad.request", null, "Failed to execute reset password. Bad request.");
    LocalizableMessageType localizableMessageBean = LocalizationUtil.createLocalizableMessageType(localizableMessage);
    ExecuteCredentialResetResponseType response = new ExecuteCredentialResetResponseType();
    response.setMessage(localizableMessageBean);
    QName fakeQName = new QName(PrismConstants.NS_TYPES, "object");
    prismContext.adopt(response);
    String xml = prismContext.xmlSerializer().serializeAnyData(response, fakeQName);
    System.out.println(xml);
}
Also used : PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) QName(javax.xml.namespace.QName) ExecuteCredentialResetResponseType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteCredentialResetResponseType) SingleLocalizableMessage(com.evolveum.midpoint.util.SingleLocalizableMessage) Test(org.testng.annotations.Test)

Aggregations

PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 EvaluatedStateTrigger (com.evolveum.midpoint.model.api.context.EvaluatedStateTrigger)1 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)1 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 PrismTestUtil.getPrismContext (com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext)1 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)1 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)1 SingleLocalizableMessage (com.evolveum.midpoint.util.SingleLocalizableMessage)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ScriptExecutionException (com.evolveum.midpoint.util.exception.ScriptExecutionException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 LocalizableMessageModel (com.evolveum.midpoint.web.component.util.LocalizableMessageModel)1 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)1 ExecuteCredentialResetResponseType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteCredentialResetResponseType)1 InformationPartType (com.evolveum.midpoint.xml.ns._public.common.common_3.InformationPartType)1 InformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.InformationType)1 LocalizableMessageType (com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizableMessageType)1 SingleLocalizableMessageType (com.evolveum.midpoint.xml.ns._public.common.common_3.SingleLocalizableMessageType)1 StatePolicyConstraintType (com.evolveum.midpoint.xml.ns._public.common.common_3.StatePolicyConstraintType)1