Search in sources :

Example 1 with ResourceObjectEvent

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);
}
Also used : ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent)

Example 2 with ResourceObjectEvent

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;
}
Also used : ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 3 with ResourceObjectEvent

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 "";
    }
}
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 4 with ResourceObjectEvent

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();
}
Also used : ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent)

Example 5 with ResourceObjectEvent

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)";
    }
}
Also used : ResourceObjectEvent(com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

ResourceObjectEvent (com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 ResourceOperationDescription (com.evolveum.midpoint.provisioning.api.ResourceOperationDescription)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)1 ModelElementContext (com.evolveum.midpoint.model.api.context.ModelElementContext)1 ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Date (java.util.Date)1