Search in sources :

Example 1 with InviteReplyType

use of org.bedework.caldav.util.sharing.InviteReplyType 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 InviteReplyType

use of org.bedework.caldav.util.sharing.InviteReplyType in project bw-calendar-engine by Bedework.

the class Sharing method updateSharingStatus.

/* ====================================================================
   *                   Private methods
   * ==================================================================== */
/* This requires updating the shared calendar to reflect the accept/decline
   * status
   */
private boolean updateSharingStatus(final String sharerHref, final String path, final InviteReplyType reply, final Holder<AccessType> access) throws CalFacadeException {
    pushPrincipal(sharerHref);
    try {
        final BwCalendar col = getCols().get(path);
        if (col == null) {
            // Bad hosturl?
            throw new CalFacadeForbidden(CalFacadeException.shareTargetNotFound);
        }
        /* See if we have an outstanding invite for this user */
        final QName qn = new QName(AppleServerTags.inviteNotification.getNamespaceURI(), AppleServerTags.inviteNotification.getLocalPart() + reply.getInReplyTo());
        final String pname = NamespaceAbbrevs.prefixed(qn);
        final String xmlInvite = col.getProperty(pname);
        if (xmlInvite == null) {
            // No invite
            if (debug) {
                trace("No invite notification on collection with name: " + pname);
            }
            throw new CalFacadeForbidden(CalFacadeException.noInvite);
        }
        /* Remove the invite */
        col.setProperty(pname, null);
        /* Get the invite property and locate and update this sharee */
        final InviteType invite = getInviteStatus(col);
        UserType uentry = null;
        final String invitee = getSvc().getDirectories().normalizeCua(reply.getHref());
        if (invite != null) {
            uentry = invite.finduser(invitee);
        }
        if (uentry == null) {
            if (debug) {
                trace("Cannot find invitee: " + invitee);
            }
            throw new CalFacadeForbidden(CalFacadeException.noInviteeInUsers);
        }
        if (reply.testAccepted()) {
            uentry.setInviteStatus(AppleServerTags.inviteAccepted);
        } else {
            uentry.setInviteStatus(AppleServerTags.inviteDeclined);
        }
        access.value = uentry.getAccess();
        col.setProperty(NamespaceAbbrevs.prefixed(AppleServerTags.invite), invite.toXml());
        getCols().update(col);
        /* Now send the sharer the reply as a notification */
        final NotificationType note = new NotificationType();
        note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
        final InviteReplyType irt = (InviteReplyType) reply.clone();
        note.setNotification(irt);
        /* Fill in the summary (the sharer's summary) on the reply. */
        irt.setSummary(reply.getSummary());
        getSvc().getNotificationsHandler().add(note);
        return irt.testAccepted();
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    } finally {
        popPrincipal();
    }
}
Also used : DtStamp(net.fortuna.ical4j.model.property.DtStamp) QName(javax.xml.namespace.QName) 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) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwCalendar(org.bedework.calfacade.BwCalendar) UserType(org.bedework.caldav.util.sharing.UserType) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

DateTime (net.fortuna.ical4j.model.DateTime)2 DtStamp (net.fortuna.ical4j.model.property.DtStamp)2 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)2 InviteReplyType (org.bedework.caldav.util.sharing.InviteReplyType)2 InviteType (org.bedework.caldav.util.sharing.InviteType)2 UserType (org.bedework.caldav.util.sharing.UserType)2 BwCalendar (org.bedework.calfacade.BwCalendar)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 QName (javax.xml.namespace.QName)1 BwPrincipal (org.bedework.calfacade.BwPrincipal)1 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)1