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);
}
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;
}
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);
}
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();
}
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)";
}
}
Aggregations