Search in sources :

Example 1 with ModelEvent

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

the class NotificationFunctionsImpl method getContentAsFormattedList.

public String getContentAsFormattedList(Event event, boolean showSynchronizationItems, boolean showAuxiliaryAttributes) {
    List<ItemPath> hiddenPaths = new ArrayList<>();
    if (!showSynchronizationItems) {
        hiddenPaths.addAll(SYNCHRONIZATION_PATHS);
    }
    if (!showAuxiliaryAttributes) {
        hiddenPaths.addAll(AUXILIARY_PATHS);
    }
    if (event instanceof ResourceObjectEvent) {
        final ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
        final ObjectDelta<ShadowType> shadowDelta = resourceObjectEvent.getShadowDelta();
        if (shadowDelta == null) {
            return "";
        }
        if (shadowDelta.isAdd()) {
            return getResourceObjectAttributesAsFormattedList(shadowDelta.getObjectToAdd().asObjectable(), hiddenPaths, showAuxiliaryAttributes);
        } else if (shadowDelta.isModify()) {
            return getResourceObjectModifiedAttributesAsFormattedList(resourceObjectEvent, shadowDelta, hiddenPaths, showAuxiliaryAttributes);
        } else {
            return "";
        }
    } else if (event instanceof ModelEvent) {
        final ModelEvent modelEvent = (ModelEvent) event;
        ModelContext<FocusType> modelContext = (ModelContext) modelEvent.getModelContext();
        ModelElementContext<FocusType> focusContext = modelContext.getFocusContext();
        ObjectDelta<? extends FocusType> summarizedDelta;
        try {
            summarizedDelta = modelEvent.getSummarizedFocusDeltas();
        } catch (SchemaException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Unable to determine the focus change; focus context = {}", e, focusContext.debugDump());
            return ("(unable to determine the change because of schema exception: " + e.getMessage() + ")\n");
        }
        if (summarizedDelta.isAdd()) {
            return textFormatter.formatObject(summarizedDelta.getObjectToAdd(), hiddenPaths, showAuxiliaryAttributes);
        } else if (summarizedDelta.isModify()) {
            return textFormatter.formatObjectModificationDelta(summarizedDelta, hiddenPaths, showAuxiliaryAttributes, focusContext.getObjectOld(), focusContext.getObjectNew());
        } else {
            return "";
        }
    } else {
        return "";
    }
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent) ModelElementContext(com.evolveum.midpoint.model.api.context.ModelElementContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with ModelEvent

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

the class AccountActivationNotifier method checkApplicability.

@Override
protected boolean checkApplicability(Event event, GeneralNotifierType generalNotifierType, OperationResult result) {
    if (!event.isSuccess()) {
        LOGGER.trace("Operation was not successful, exiting.");
        return false;
    }
    ModelEvent modelEvent = (ModelEvent) event;
    if (modelEvent.getFocusDeltas().isEmpty()) {
        LOGGER.trace("No user deltas in event, exiting.");
        return false;
    }
    List<ShadowType> shadows = getShadowsToActivate(modelEvent);
    if (shadows.isEmpty()) {
        LOGGER.trace("No shadows to activate found in model context. Skip sending notifications.");
        return false;
    }
    LOGGER.trace("Found shadows to activate: {}. Skip sending notifications.", shadows);
    return true;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Example 3 with ModelEvent

use of com.evolveum.midpoint.notifications.api.events.ModelEvent 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)

Example 4 with ModelEvent

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

the class FocusTypeFilterHelper method processEvent.

@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult result) {
    if (eventHandlerType.getFocusType().isEmpty()) {
        return true;
    }
    if (!(event instanceof ModelEvent)) {
        // or should we return false?
        return true;
    }
    ModelEvent modelEvent = (ModelEvent) event;
    logStart(LOGGER, event, eventHandlerType, eventHandlerType.getStatus());
    boolean retval = false;
    for (QName focusType : eventHandlerType.getFocusType()) {
        if (focusType == null) {
            LOGGER.warn("Filtering on null focusType; filter = " + eventHandlerType);
        } else if (modelEvent.hasFocusOfType(focusType)) {
            retval = true;
            break;
        }
    }
    logEnd(LOGGER, event, eventHandlerType, retval);
    return retval;
}
Also used : QName(javax.xml.namespace.QName) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Example 5 with ModelEvent

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

the class GeneralNotifier method processEvent.

@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult parentResult) throws SchemaException {
    OperationResult result = parentResult.createSubresult(GeneralNotifier.class.getName() + ".processEvent");
    logStart(getLogger(), event, eventHandlerType);
    boolean applies = aggregatedEventHandler.processEvent(event, eventHandlerType, notificationManager, task, result);
    if (applies) {
        GeneralNotifierType generalNotifierType = (GeneralNotifierType) eventHandlerType;
        if (!quickCheckApplicability(event, generalNotifierType, result)) {
        // nothing to do -- an appropriate message has to be logged in quickCheckApplicability method
        } else {
            if (!checkApplicability(event, generalNotifierType, result)) {
            // nothing to do -- an appropriate message has to be logged in checkApplicability method
            } else if (generalNotifierType.getTransport().isEmpty()) {
                getLogger().warn("No transports for this notifier, exiting without sending any notifications.");
            } else {
                ExpressionVariables variables = getDefaultVariables(event, result);
                if (event instanceof ModelEvent) {
                    ((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, ENTERING));
                }
                try {
                    for (String transportName : generalNotifierType.getTransport()) {
                        variables.addVariableDefinition(SchemaConstants.C_TRANSPORT_NAME, transportName);
                        Transport transport = notificationManager.getTransport(transportName);
                        List<String> recipientsAddresses = getRecipientsAddresses(event, generalNotifierType, variables, getDefaultRecipient(event, generalNotifierType, result), transportName, transport, task, result);
                        if (!recipientsAddresses.isEmpty()) {
                            String body = getBodyFromExpression(event, generalNotifierType, variables, task, result);
                            String subject = getSubjectFromExpression(event, generalNotifierType, variables, task, result);
                            String from = getFromFromExpression(event, generalNotifierType, variables, task, result);
                            String contentType = getContentTypeFromExpression(event, generalNotifierType, variables, task, result);
                            if (body == null) {
                                body = getBody(event, generalNotifierType, transportName, task, result);
                            }
                            if (subject == null) {
                                subject = generalNotifierType.getSubjectPrefix() != null ? generalNotifierType.getSubjectPrefix() : "";
                                subject += getSubject(event, generalNotifierType, transportName, task, result);
                            }
                            Message message = new Message();
                            message.setBody(body != null ? body : "");
                            if (contentType != null) {
                                message.setContentType(contentType);
                            } else if (generalNotifierType.getContentType() != null) {
                                message.setContentType(generalNotifierType.getContentType());
                            }
                            message.setSubject(subject);
                            if (from != null) {
                                message.setFrom(from);
                            }
                            message.setTo(recipientsAddresses);
                            message.setCc(getCcBccAddresses(generalNotifierType.getCcExpression(), variables, "notification cc-expression", task, result));
                            message.setBcc(getCcBccAddresses(generalNotifierType.getBccExpression(), variables, "notification bcc-expression", task, result));
                            getLogger().trace("Sending notification via transport {}:\n{}", transportName, message);
                            transport.send(message, transportName, event, task, result);
                        } else {
                            getLogger().info("No recipients addresses for transport " + transportName + ", message corresponding to event " + event.getId() + " will not be send.");
                        }
                    }
                } 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) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ArrayList(java.util.ArrayList) List(java.util.List) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Transport(com.evolveum.midpoint.notifications.api.transports.Transport) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Aggregations

ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ProgressInformation (com.evolveum.midpoint.model.api.ProgressInformation)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)2 Message (com.evolveum.midpoint.notifications.api.transports.Message)2 Transport (com.evolveum.midpoint.notifications.api.transports.Transport)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 ModelElementContext (com.evolveum.midpoint.model.api.context.ModelElementContext)1 ResourceObjectEvent (com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent)1 CustomTransport (com.evolveum.midpoint.notifications.impl.api.transports.CustomTransport)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 CustomNotifierType (com.evolveum.midpoint.xml.ns._public.common.common_3.CustomNotifierType)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Date (java.util.Date)1