Search in sources :

Example 6 with ModelEvent

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

the class NotificationChangeHook method emitModelEvent.

private void emitModelEvent(@NotNull ModelContext<?> context, @NotNull Task task, @NotNull OperationResult result) {
    PrismObject<?> object = getObject(context);
    if (object == null) {
        LOGGER.trace("Focus context object is null, not sending the notification.");
        return;
    }
    ModelEvent event = createModelEvent(object, context, task);
    notificationManager.processEvent(event, task, result);
}
Also used : ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Example 7 with ModelEvent

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

the class NotificationChangeHook method createModelEvent.

@NotNull
private ModelEvent createModelEvent(PrismObject<?> object, ModelContext<?> modelContext, Task task) {
    ModelEvent event = new ModelEvent(lightweightIdentifierGenerator, modelContext);
    setCommonEventProperties(object, task, modelContext, event);
    // TODO is this correct? it's not quite clear how we work with channel info in task / modelContext
    String channel = task.getChannel();
    if (channel == null) {
        channel = modelContext.getChannel();
    }
    event.setChannel(channel);
    return event;
}
Also used : ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ModelEvent

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

the class UserPasswordNotifier method getBody.

@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
    ModelEvent modelEvent = (ModelEvent) event;
    List<ObjectDelta<FocusType>> deltas = modelEvent.getFocusDeltas();
    return "Password for user " + notificationsUtil.getObjectType(event.getRequestee(), false, result).getName() + " is: " + getPasswordFromDeltas(deltas);
}
Also used : ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Example 9 with ModelEvent

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

the class SimpleFocalObjectNotifier method getBody.

@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) throws SchemaException {
    final ModelEvent modelEvent = (ModelEvent) event;
    String typeName = modelEvent.getFocusTypeName();
    String typeNameLower = typeName.toLowerCase();
    boolean techInfo = Boolean.TRUE.equals(generalNotifierType.isShowTechnicalInformation());
    ModelContext<FocusType> modelContext = (ModelContext) modelEvent.getModelContext();
    ModelElementContext<FocusType> focusContext = modelContext.getFocusContext();
    PrismObject<FocusType> focus = focusContext.getObjectNew() != null ? focusContext.getObjectNew() : focusContext.getObjectOld();
    FocusType userType = focus.asObjectable();
    String oid = focusContext.getOid();
    String fullName;
    if (userType instanceof UserType) {
        fullName = PolyString.getOrig(((UserType) userType).getFullName());
    } else if (userType instanceof AbstractRoleType) {
        fullName = PolyString.getOrig(((AbstractRoleType) userType).getDisplayName());
    } else {
        // TODO (currently it's not possible to get here)
        fullName = "";
    }
    if (fullName == null) {
        // "null" is not nice in notifications
        fullName = "";
    }
    ObjectDelta<FocusType> delta = ObjectDelta.summarize(modelEvent.getFocusDeltas());
    StringBuilder body = new StringBuilder();
    String status = modelEvent.getStatusAsText();
    String attemptedTo = event.isSuccess() ? "" : "(attempted to be) ";
    body.append("Notification about ").append(typeNameLower).append("-related operation (status: ").append(status).append(")\n\n");
    body.append(typeName).append(": ").append(fullName).append(" (").append(userType.getName()).append(", oid ").append(oid).append(")\n");
    body.append("Notification created on: ").append(new Date()).append("\n\n");
    final boolean watchAuxiliaryAttributes = isWatchAuxiliaryAttributes(generalNotifierType);
    if (delta.isAdd()) {
        body.append("The ").append(typeNameLower).append(" record was ").append(attemptedTo).append("created with the following data:\n");
        body.append(modelEvent.getContentAsFormattedList(false, watchAuxiliaryAttributes));
    } else if (delta.isModify()) {
        body.append("The ").append(typeNameLower).append(" record was ").append(attemptedTo).append("modified. Modified attributes are:\n");
        body.append(modelEvent.getContentAsFormattedList(false, watchAuxiliaryAttributes));
    } else if (delta.isDelete()) {
        body.append("The ").append(typeNameLower).append(" record was ").append(attemptedTo).append("removed.\n");
    }
    body.append("\n");
    if (!event.isSuccess()) {
        body.append("More information about the status of the request was displayed and/or is present in log files.\n\n");
    }
    functions.addRequesterAndChannelInformation(body, event, result);
    if (techInfo) {
        body.append("----------------------------------------\n");
        body.append("Technical information:\n\n");
        body.append(modelContext.debugDump(2));
    }
    return body.toString();
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent) Date(java.util.Date) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext)

Example 10 with ModelEvent

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

the class SimpleFocalObjectNotifier method getSubject.

@Override
protected String getSubject(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
    final ModelEvent modelEvent = (ModelEvent) event;
    String typeName = modelEvent.getFocusTypeName();
    if (event.isAdd()) {
        return typeName + " creation notification";
    } else if (event.isModify()) {
        return typeName + " modification notification";
    } else if (event.isDelete()) {
        return typeName + " deletion notification";
    } else {
        return "(unknown " + typeName.toLowerCase() + " operation)";
    }
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Aggregations

ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)11 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 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 List (java.util.List)1