Search in sources :

Example 1 with ModelElementContext

use of com.evolveum.midpoint.model.api.context.ModelElementContext 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)

Aggregations

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 ResourceObjectEvent (com.evolveum.midpoint.notifications.api.events.ResourceObjectEvent)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1