Search in sources :

Example 1 with SuggestNotificationType

use of org.bedework.caldav.util.notifications.suggest.SuggestNotificationType in project bw-calendar-engine by Bedework.

the class Notifier method processSuggested.

private ProcessMessageResult processSuggested(final SysEvent msg) {
    try {
        final SysCode sysCode = msg.getSysCode();
        String targetPrincipal = null;
        SuggestBaseNotificationType sbnt = null;
        if (sysCode == SysCode.SUGGESTED) {
            final EntitySuggestedEvent ese = (EntitySuggestedEvent) msg;
            final SuggestNotificationType snt = new SuggestNotificationType();
            snt.setUid(Uid.getUid());
            snt.setHref(ese.getHref());
            snt.setSuggesterHref(ese.getAuthPrincipalHref());
            snt.setSuggesteeHref(ese.getTargetPrincipalHref());
            targetPrincipal = ese.getTargetPrincipalHref();
            sbnt = snt;
        } else if (sysCode == SysCode.SUGGESTED_RESPONSE) {
            final EntitySuggestedResponseEvent esre = (EntitySuggestedResponseEvent) msg;
            final SuggestResponseNotificationType srnt = new SuggestResponseNotificationType();
            srnt.setUid(Uid.getUid());
            srnt.setHref(esre.getHref());
            srnt.setSuggesteeHref(esre.getAuthPrincipalHref());
            srnt.setSuggesterHref(esre.getTargetPrincipalHref());
            srnt.setAccepted(esre.getAccepted());
            targetPrincipal = srnt.getSuggesterHref();
            sbnt = srnt;
        }
        if (sbnt == null) {
            return ProcessMessageResult.IGNORED;
        }
        try {
            getSvci(targetPrincipal);
            /* See if we have any notifications for this entity
           *
           * SCHEMA: If we could store the entire encoded path in the name we
           * could just do a get
           */
            NotificationType storedNote = null;
            for (final NotificationType n : getNotes().getMatching(sbnt.getElementName())) {
                if ((n == null) || (n.getNotification() == null)) {
                    // Bad notiifcation?
                    continue;
                }
                final SuggestBaseNotificationType ns = (SuggestBaseNotificationType) n.getNotification();
                if (sbnt.getHref().equals(ns.getHref())) {
                    // Suggested resource
                    storedNote = n;
                    break;
                }
            }
            if (storedNote == null) {
                // save this one
                sbnt.setName(getEncodedUuid());
                final NotificationType n = new NotificationType();
                n.setNotification(sbnt);
                getNotes().add(n);
                return ProcessMessageResult.PROCESSED;
            }
            return ProcessMessageResult.IGNORED;
        } finally {
            closeSvci(getSvc());
        }
    } catch (final CalFacadeStaleStateException csse) {
        if (debug) {
            trace("Stale state exception");
        }
        return ProcessMessageResult.STALE_STATE;
    } catch (final Throwable t) {
        rollback(getSvc());
        error(t);
    } finally {
        try {
            closeSvci(getSvc());
        } catch (final Throwable ignored) {
        }
    }
    return ProcessMessageResult.FAILED;
}
Also used : CalFacadeStaleStateException(org.bedework.calfacade.exc.CalFacadeStaleStateException) EntitySuggestedEvent(org.bedework.sysevents.events.publicAdmin.EntitySuggestedEvent) AdminNotificationType(org.bedework.caldav.util.notifications.admin.AdminNotificationType) BaseNotificationType(org.bedework.caldav.util.notifications.BaseNotificationType) SuggestResponseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) ApprovalResponseNotificationType(org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType) SuggestNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestNotificationType) AwaitingApprovalNotificationType(org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType) SuggestResponseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType) SysCode(org.bedework.sysevents.events.SysEventBase.SysCode) SuggestNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestNotificationType) EntitySuggestedResponseEvent(org.bedework.sysevents.events.publicAdmin.EntitySuggestedResponseEvent)

Aggregations

BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)1 NotificationType (org.bedework.caldav.util.notifications.NotificationType)1 AdminNotificationType (org.bedework.caldav.util.notifications.admin.AdminNotificationType)1 ApprovalResponseNotificationType (org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType)1 AwaitingApprovalNotificationType (org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType)1 SuggestBaseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)1 SuggestNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestNotificationType)1 SuggestResponseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType)1 CalFacadeStaleStateException (org.bedework.calfacade.exc.CalFacadeStaleStateException)1 SysCode (org.bedework.sysevents.events.SysEventBase.SysCode)1 EntitySuggestedEvent (org.bedework.sysevents.events.publicAdmin.EntitySuggestedEvent)1 EntitySuggestedResponseEvent (org.bedework.sysevents.events.publicAdmin.EntitySuggestedResponseEvent)1