use of com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent in project midpoint by Evolveum.
the class AccountOperationListener method executeNotifyAny.
private void executeNotifyAny(OperationStatus status, ResourceOperationDescription operationDescription, Task task, OperationResult result) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("AccountOperationListener.notify (" + status + ") called with operationDescription = " + operationDescription.debugDump());
}
if (operationDescription.getObjectDelta() == null) {
LOGGER.warn("Object delta is null, exiting the change listener.");
return;
}
if (operationDescription.getCurrentShadow() == null) {
LOGGER.warn("Current shadow is null, exiting the change listener.");
return;
}
// for the time being, we deal only with accounts here
if (operationDescription.getObjectDelta().getObjectTypeClass() == null || !ShadowType.class.isAssignableFrom(operationDescription.getObjectDelta().getObjectTypeClass())) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Object that was changed was not an account, exiting the operation listener (class = " + operationDescription.getObjectDelta().getObjectTypeClass() + ")");
}
return;
}
ResourceObjectEvent request = createRequest(status, operationDescription, task, result);
notificationManager.processEvent(request, task, result);
}
use of com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent in project midpoint by Evolveum.
the class AccountOperationListener method createRequest.
private ResourceObjectEvent createRequest(OperationStatus status, ResourceOperationDescription operationDescription, Task task, OperationResult result) {
ResourceObjectEvent event = new ResourceObjectEvent(lightweightIdentifierGenerator);
event.setAccountOperationDescription(operationDescription);
event.setOperationStatus(status);
// fortunately there's 1:1 mapping
event.setChangeType(operationDescription.getObjectDelta().getChangeType());
String accountOid = operationDescription.getObjectDelta().getOid();
PrismObject<UserType> user = findRequestee(accountOid, task, result, operationDescription.getObjectDelta().isDelete());
if (user != null) {
event.setRequestee(new SimpleObjectRefImpl(notificationsUtil, user.asObjectable()));
}
if (task != null && task.getOwner() != null) {
event.setRequester(new SimpleObjectRefImpl(notificationsUtil, task.getOwner()));
} else {
LOGGER.warn("No owner for task " + task + ", therefore no requester will be set for event " + event.getId());
}
if (task != null && task.getChannel() != null) {
event.setChannel(task.getChannel());
} else if (operationDescription.getSourceChannel() != null) {
event.setChannel(operationDescription.getSourceChannel());
}
return event;
}
use of com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent 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 "";
}
}
use of com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent in project midpoint by Evolveum.
the class AccountPasswordNotifier method getBody.
@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
StringBuilder body = new StringBuilder();
ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
body.append("Password for account ");
String name = resourceObjectEvent.getShadowName();
if (name != null) {
body.append(name).append(" ");
}
body.append("on ").append(resourceObjectEvent.getResourceName());
body.append(" is: ").append(resourceObjectEvent.getPlaintextPassword());
return body.toString();
}
use of com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent in project midpoint by Evolveum.
the class SimpleResourceObjectNotifier method getSubject.
@Override
protected String getSubject(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
ResourceOperationDescription rod = resourceObjectEvent.getAccountOperationDescription();
ObjectDelta<ShadowType> delta = (ObjectDelta<ShadowType>) rod.getObjectDelta();
String objectTypeDescription = resourceObjectEvent.isShadowKind(ShadowKindType.ACCOUNT) ? "Account" : "Resource object";
if (delta.isAdd()) {
return objectTypeDescription + " creation notification";
} else if (delta.isModify()) {
return objectTypeDescription + " modification notification";
} else if (delta.isDelete()) {
return objectTypeDescription + " deletion notification";
} else {
return "(unknown resource object operation)";
}
}
Aggregations