Search in sources :

Example 1 with CustomEvent

use of com.evolveum.midpoint.notifications.api.events.CustomEvent in project midpoint by Evolveum.

the class NotifyExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    String subtype = expressionHelper.getArgumentAsString(expression.getParameter(), PARAM_SUBTYPE, input, context, null, PARAM_SUBTYPE, globalResult);
    EventHandlerType handler = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_HANDLER, false, false, PARAM_HANDLER, input, context, EventHandlerType.class, globalResult);
    EventStatusType status = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_STATUS, false, false, PARAM_STATUS, input, context, EventStatusType.class, globalResult);
    EventOperationType operation = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_OPERATION, false, false, PARAM_OPERATION, input, context, EventOperationType.class, globalResult);
    boolean forWholeInput = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_FOR_WHOLE_INPUT, input, context, false, PARAM_SUBTYPE, globalResult);
    if (handler != null) {
        // TODO explain that the reason is that handler is not null
        checkRootAuthorization(globalResult, NAME);
    }
    if (status == null) {
        status = EventStatusType.SUCCESS;
    }
    if (operation == null) {
        operation = EventOperationType.ADD;
    }
    if (notificationManager == null) {
        throw new IllegalStateException("Notification manager is unavailable");
    }
    int eventCount = 0;
    if (forWholeInput) {
        Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, input.getData(), operation, status, context.getChannel());
        notificationManager.processEvent(event, context.getTask(), globalResult);
        eventCount++;
    } else {
        for (PipelineItem item : input.getData()) {
            PrismValue value = item.getValue();
            OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
            context.checkTaskStop();
            Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, value, operation, status, context.getChannel());
            notificationManager.processEvent(event, context.getTask(), result);
            eventCount++;
            operationsHelper.trimAndCloneResult(result, globalResult, context);
        }
    }
    context.println("Produced " + eventCount + " event(s)");
    return input;
}
Also used : CustomEvent(com.evolveum.midpoint.notifications.api.events.CustomEvent) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) EventHandlerType(com.evolveum.midpoint.xml.ns._public.common.common_3.EventHandlerType) EventStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.EventStatusType) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEvent(com.evolveum.midpoint.notifications.api.events.CustomEvent) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EventOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.EventOperationType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Aggregations

PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 CustomEvent (com.evolveum.midpoint.notifications.api.events.CustomEvent)1 Event (com.evolveum.midpoint.notifications.api.events.Event)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 EventHandlerType (com.evolveum.midpoint.xml.ns._public.common.common_3.EventHandlerType)1 EventOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.EventOperationType)1 EventStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.EventStatusType)1