Search in sources :

Example 31 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class ResourceManager method evaluateExpression.

private <T> void evaluateExpression(PrismProperty<T> configurationProperty, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    PrismPropertyDefinition<T> propDef = configurationProperty.getDefinition();
    String shortDesc = "connector configuration property " + configurationProperty + " in " + resource;
    List<PrismPropertyValue<T>> extraValues = new ArrayList<>();
    for (PrismPropertyValue<T> configurationPropertyValue : configurationProperty.getValues()) {
        ExpressionWrapper expressionWrapper = configurationPropertyValue.getExpression();
        if (expressionWrapper == null) {
            return;
        }
        Object expressionObject = expressionWrapper.getExpression();
        if (!(expressionObject instanceof ExpressionType)) {
            throw new IllegalStateException("Expected that expression in " + configurationPropertyValue + " will be ExpressionType, but it was " + expressionObject);
        }
        ExpressionType expressionType = (ExpressionType) expressionWrapper.getExpression();
        Expression<PrismPropertyValue<T>, PrismPropertyDefinition<T>> expression = expressionFactory.makeExpression(expressionType, propDef, shortDesc, task, result);
        ExpressionVariables variables = new ExpressionVariables();
        // TODO: populate variables
        ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
        PrismValueDeltaSetTriple<PrismPropertyValue<T>> expressionOutputTriple = expression.evaluate(expressionContext);
        Collection<PrismPropertyValue<T>> expressionOutputValues = expressionOutputTriple.getNonNegativeValues();
        if (expressionOutputValues != null && !expressionOutputValues.isEmpty()) {
            Iterator<PrismPropertyValue<T>> iterator = expressionOutputValues.iterator();
            PrismPropertyValue<T> firstValue = iterator.next();
            configurationPropertyValue.setValue(firstValue.getValue());
            while (iterator.hasNext()) {
                extraValues.add(iterator.next());
            }
        }
    }
    for (PrismPropertyValue<T> extraValue : extraValues) {
        configurationProperty.add(extraValue);
    }
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ArrayList(java.util.ArrayList) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 32 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class BaseHandler method getDefaultVariables.

protected ExpressionVariables getDefaultVariables(Event event, OperationResult result) {
    ExpressionVariables expressionVariables = new ExpressionVariables();
    Map<QName, Object> variables = new HashMap<QName, Object>();
    event.createExpressionVariables(variables, result);
    expressionVariables.addVariableDefinitions(variables);
    return expressionVariables;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) QName(javax.xml.namespace.QName)

Example 33 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class BaseHelper method getDefaultVariables.

protected ExpressionVariables getDefaultVariables(Event event, OperationResult result) {
    ExpressionVariables expressionVariables = new ExpressionVariables();
    Map<QName, Object> variables = new HashMap<QName, Object>();
    event.createExpressionVariables(variables, result);
    expressionVariables.addVariableDefinitions(variables);
    return expressionVariables;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName)

Example 34 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class CustomNotifier method getDefaultVariables.

@Override
protected ExpressionVariables getDefaultVariables(Event event, OperationResult result) {
    ExpressionVariables variables = super.getDefaultVariables(event, result);
    variables.addVariableDefinition(SchemaConstants.C_TEXT_FORMATTER, textFormatter);
    return variables;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

Example 35 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class CustomNotifier method processEvent.

@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult parentResult) throws SchemaException {
    OperationResult result = parentResult.createSubresult(CustomNotifier.class.getName() + ".processEvent");
    logStart(getLogger(), event, eventHandlerType);
    boolean applies = aggregatedEventHandler.processEvent(event, eventHandlerType, notificationManager, task, result);
    if (applies) {
        CustomNotifierType config = (CustomNotifierType) eventHandlerType;
        ExpressionVariables variables = getDefaultVariables(event, result);
        if (event instanceof ModelEvent) {
            ((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, ENTERING));
        }
        List<String> transports = new ArrayList<>(config.getTransport());
        if (transports.isEmpty()) {
            transports.add(customTransport.getName());
        }
        try {
            for (String transportName : config.getTransport()) {
                variables.addVariableDefinition(SchemaConstants.C_TRANSPORT_NAME, transportName);
                Transport transport = notificationManager.getTransport(transportName);
                Message message = getMessageFromExpression(config, variables, task, result);
                if (message != null) {
                    getLogger().trace("Sending notification via transport {}:\n{}", transportName, message);
                    transport.send(message, transportName, event, task, result);
                } else {
                    getLogger().debug("No message for transport {}, won't send anything", transportName);
                }
            }
        } finally {
            if (event instanceof ModelEvent) {
                ((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, result));
            }
        }
    }
    logEnd(getLogger(), event, eventHandlerType, applies);
    result.computeStatusIfUnknown();
    // not-applicable notifiers do not stop processing of other notifiers
    return true;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ProgressInformation(com.evolveum.midpoint.model.api.ProgressInformation) Message(com.evolveum.midpoint.notifications.api.transports.Message) ArrayList(java.util.ArrayList) CustomNotifierType(com.evolveum.midpoint.xml.ns._public.common.common_3.CustomNotifierType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Transport(com.evolveum.midpoint.notifications.api.transports.Transport) CustomTransport(com.evolveum.midpoint.notifications.impl.api.transports.CustomTransport) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Aggregations

ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)65 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)17 QName (javax.xml.namespace.QName)15 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 Test (org.testng.annotations.Test)10 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)9 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)9 Task (com.evolveum.midpoint.task.api.Task)8 ArrayList (java.util.ArrayList)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)6 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)5 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)5 SystemException (com.evolveum.midpoint.util.exception.SystemException)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)4