Search in sources :

Example 1 with ApprovalResponseNotificationType

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

the class Notifier method processApproved.

private ProcessMessageResult processApproved(final SysEvent msg) {
    try {
        String targetPrincipal = null;
        final SysCode sysCode = msg.getSysCode();
        AdminNotificationType ant = null;
        if (sysCode == SysCode.APPROVAL_STATUS) {
            final EntityApprovalResponseEvent eare = (EntityApprovalResponseEvent) msg;
            final ApprovalResponseNotificationType arnt = new ApprovalResponseNotificationType();
            arnt.setUid(Uid.getUid());
            arnt.setHref(eare.getHref());
            arnt.setPrincipalHref(eare.getOwnerHref());
            arnt.setAccepted(eare.getApproved());
            arnt.setComment(eare.getComment());
            arnt.setCalsuiteHref(eare.getCalsuiteHref());
            targetPrincipal = eare.getCalsuiteHref();
            ant = arnt;
        } else if (sysCode == SysCode.APPROVAL_NEEDED) {
            final EntityApprovalNeededEvent eane = (EntityApprovalNeededEvent) msg;
            final AwaitingApprovalNotificationType aant = new AwaitingApprovalNotificationType();
            aant.setUid(Uid.getUid());
            aant.setHref(eane.getHref());
            aant.setPrincipalHref(eane.getOwnerHref());
            aant.setComment(eane.getComment());
            aant.setCalsuiteHref(eane.getCalsuiteHref());
            targetPrincipal = eane.getCalsuiteHref();
            ant = aant;
        }
        if (ant == 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(ant.getElementName())) {
                if ((n == null) || (n.getNotification() == null)) {
                    // Bad notiifcation?
                    continue;
                }
                final AdminNotificationType ns = (AdminNotificationType) n.getNotification();
                if (ant.getHref().equals(ns.getHref())) {
                    // Already have a notification for resource
                    storedNote = n;
                    break;
                }
            }
            if (storedNote != null) {
                getNotes().remove(storedNote);
            }
            // save this one
            ant.setName(getEncodedUuid());
            final NotificationType n = new NotificationType();
            n.setNotification(ant);
            getNotes().add(n);
            return ProcessMessageResult.PROCESSED;
        } finally {
            closeSvci(getSvc());
        }
    } catch (final Throwable t) {
        rollback(getSvc());
        error(t);
    } finally {
        try {
            closeSvci(getSvc());
        } catch (final Throwable ignored) {
        }
    }
    return ProcessMessageResult.FAILED;
}
Also used : EntityApprovalResponseEvent(org.bedework.sysevents.events.publicAdmin.EntityApprovalResponseEvent) EntityApprovalNeededEvent(org.bedework.sysevents.events.publicAdmin.EntityApprovalNeededEvent) 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) ApprovalResponseNotificationType(org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType) AwaitingApprovalNotificationType(org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType) AdminNotificationType(org.bedework.caldav.util.notifications.admin.AdminNotificationType) SysCode(org.bedework.sysevents.events.SysEventBase.SysCode)

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 SysCode (org.bedework.sysevents.events.SysEventBase.SysCode)1 EntityApprovalNeededEvent (org.bedework.sysevents.events.publicAdmin.EntityApprovalNeededEvent)1 EntityApprovalResponseEvent (org.bedework.sysevents.events.publicAdmin.EntityApprovalResponseEvent)1