Search in sources :

Example 1 with NotificationType

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

the class Sharing method unsubscribe.

@Override
public void unsubscribe(final BwCalendar col) throws CalFacadeException {
    if (!col.getInternalAlias()) {
        return;
    }
    final BwCalendar shared = getCols().resolveAlias(col, true, false);
    if (shared == null) {
        // Gone or no access - nothing to do now.
        return;
    }
    final String sharerHref = shared.getOwnerHref();
    final BwPrincipal sharee = getSvc().getPrincipal();
    pushPrincipal(sharerHref);
    try {
        /* Get the invite property and locate and update this sharee */
        final InviteType invite = getInviteStatus(shared);
        UserType uentry = null;
        final String invitee = principalToCaladdr(sharee);
        if (invite != null) {
            uentry = invite.finduser(invitee);
        }
        if (uentry == null) {
            if (debug) {
                trace("Cannot find invitee: " + invitee);
            }
            return;
        }
        uentry.setInviteStatus(AppleServerTags.inviteDeclined);
        shared.setProperty(NamespaceAbbrevs.prefixed(AppleServerTags.invite), invite.toXml());
        getCols().update(shared);
        /* At this stage we need a message to notify the sharer -
         change notification.
         The name of the alias is the uid of the original invite
         */
        final NotificationType note = new NotificationType();
        note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
        // Create a reply object.
        final InviteReplyType reply = new InviteReplyType();
        reply.setHref(principalToCaladdr(sharee));
        reply.setAccepted(false);
        reply.setHostUrl(shared.getPath());
        reply.setInReplyTo(col.getName());
        reply.setSummary(col.getSummary());
        note.setNotification(reply);
        getSvc().getNotificationsHandler().add(note);
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    } finally {
        popPrincipal();
    }
/*
    final BwPrincipal pr = caladdrToPrincipal(getPrincipalHref());

    if (pr != null) {
      pushPrincipal(shared.getOwnerHref());
      NotificationType n = null;
      try {
        n = findInvite(pr, shared.getPath());
      } finally {
        popPrincipal();
      }
      if (n != null) {
        InviteNotificationType in = (InviteNotificationType)n.getNotification();
        Holder<AccessType> access = new Holder<AccessType>();

        // Create a dummy reply object.
        InviteReplyType reply = new InviteReplyType();
        reply.setHref(getPrincipalHref());
        reply.setAccepted(false);
        reply.setHostUrl(shared.getPath());
        reply.setInReplyTo(in.getUid());

        updateSharingStatus(shared.getOwnerHref(), shared.getPath(), reply, access);
      }
    }
    */
}
Also used : DtStamp(net.fortuna.ical4j.model.property.DtStamp) BwPrincipal(org.bedework.calfacade.BwPrincipal) NotificationType(org.bedework.caldav.util.notifications.NotificationType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) InviteType(org.bedework.caldav.util.sharing.InviteType) InviteReplyType(org.bedework.caldav.util.sharing.InviteReplyType) BwCalendar(org.bedework.calfacade.BwCalendar) UserType(org.bedework.caldav.util.sharing.UserType) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with NotificationType

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

the class Sharing method doSet.

private InviteNotificationType doSet(final BwCalendar col, final SetType s, final List<AddPrincipal> addPrincipals, final String calAddr, final InviteType invite) throws CalFacadeException {
    final Sharee sh = getSharee(s.getHref());
    if ((sh.pr != null) && sh.pr.equals(getPrincipal())) {
        // Inviting ourself
        return null;
    }
    /*
       pr != null means this is potentially one of our users.

       If the principal doesn't exist and we handle outbound
       notifications then we should drop a notification into the
       global notification collection. Eventually the user will log in
       we hope - we can then turn that invite into a real local user
       invite,
     */
    UserType uentry = invite.finduser(sh.href);
    if (uentry != null) {
        if (uentry.getInviteStatus().equals(Parser.inviteNoresponseTag)) {
            // Already an outstanding invitation
            final NotificationType n = findInvite(sh.pr, col.getPath());
            if (n != null) {
                final InviteNotificationType in = (InviteNotificationType) n.getNotification();
                if (in.getAccess().equals(s.getAccess())) {
                    // In their collection - no need to resend.
                    return null;
                }
                /* Delete the old notification - we're changing the access */
                deleteInvite(sh.pr, n);
            }
        }
    }
    final InviteNotificationType in = new InviteNotificationType();
    in.setSharedType(InviteNotificationType.sharedTypeCalendar);
    in.setUid(Uid.getUid());
    in.setHref(sh.href);
    in.setInviteStatus(Parser.inviteNoresponseTag);
    in.setAccess(s.getAccess());
    in.setHostUrl(col.getPath());
    in.setSummary(s.getSummary());
    final OrganizerType org = new OrganizerType();
    org.setHref(calAddr);
    in.setOrganizer(org);
    in.getSupportedComponents().addAll(col.getSupportedComponents());
    // Update the collection sharing status
    if (uentry != null) {
        uentry.setInviteStatus(in.getInviteStatus());
        uentry.setAccess(in.getAccess());
    } else {
        uentry = new UserType();
        uentry.setHref(sh.href);
        uentry.setInviteStatus(in.getInviteStatus());
        uentry.setCommonName(s.getCommonName());
        uentry.setAccess(in.getAccess());
        uentry.setSummary(s.getSummary());
        invite.getUsers().add(uentry);
    }
    uentry.setExternalUser(!sh.external);
    if (!sh.external) {
        addPrincipals.add(new AddPrincipal(sh.pr, s.getAccess().testRead()));
    }
    return in;
}
Also used : InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) OrganizerType(org.bedework.caldav.util.sharing.OrganizerType) UserType(org.bedework.caldav.util.sharing.UserType)

Example 3 with NotificationType

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

the class NotificationsInfo method updated.

/**
 * @param currentAuth
 * @param ev
 * @return Info for single updated event.
 * @throws CalFacadeException
 */
public static String updated(final String currentAuth, final BwEvent ev) throws CalFacadeException {
    ResourceChangeType rc = getUpdated(currentAuth, ev);
    if (rc == null) {
        return null;
    }
    NotificationType note = getNotification();
    note.setNotification(rc);
    try {
        return note.toXml(true);
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 4 with NotificationType

use of org.bedework.caldav.util.notifications.NotificationType 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)

Example 5 with NotificationType

use of org.bedework.caldav.util.notifications.NotificationType 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

NotificationType (org.bedework.caldav.util.notifications.NotificationType)14 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)6 InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)4 DateTime (net.fortuna.ical4j.model.DateTime)3 DtStamp (net.fortuna.ical4j.model.property.DtStamp)3 BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)3 AdminNotificationType (org.bedework.caldav.util.notifications.admin.AdminNotificationType)3 ApprovalResponseNotificationType (org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType)3 AwaitingApprovalNotificationType (org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType)3 SuggestBaseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)3 SuggestNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestNotificationType)3 SuggestResponseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType)3 InviteType (org.bedework.caldav.util.sharing.InviteType)3 UserType (org.bedework.caldav.util.sharing.UserType)3 BwCalendar (org.bedework.calfacade.BwCalendar)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 ResourceChangeType (org.bedework.caldav.util.notifications.ResourceChangeType)2 InviteReplyType (org.bedework.caldav.util.sharing.InviteReplyType)2