Search in sources :

Example 1 with OrganizerType

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

the class Sharing method deletedNotification.

private InviteNotificationType deletedNotification(final String colPath, final String shareeHref, final String sharerHref, final String summary, final AccessType access) throws CalFacadeException {
    final InviteNotificationType in = new InviteNotificationType();
    in.setUid(Uid.getUid());
    in.setHref(shareeHref);
    in.setInviteStatus(removeStatus);
    in.setAccess(access);
    in.setHostUrl(colPath);
    final OrganizerType org = new OrganizerType();
    org.setHref(sharerHref);
    in.setOrganizer(org);
    in.setSummary(summary);
    return in;
}
Also used : InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) OrganizerType(org.bedework.caldav.util.sharing.OrganizerType)

Example 2 with OrganizerType

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

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

the class Sharing method share.

@Override
public ShareResultType share(final BwCalendar col, final ShareType share) throws CalFacadeException {
    if (!col.getCanAlias()) {
        throw new CalFacadeForbidden("Cannot share");
    }
    final ShareResultType sr = new ShareResultType();
    final List<String> removePrincipalHrefs = new ArrayList<>();
    final List<AddPrincipal> addPrincipals = new ArrayList<>();
    final String calAddr = principalToCaladdr(getPrincipal());
    final InviteType invite = getInviteStatus(col);
    if (invite.getOrganizer() == null) {
        final OrganizerType org = new OrganizerType();
        org.setHref(calAddr);
        invite.setOrganizer(org);
    }
    final List<InviteNotificationType> notifications = new ArrayList<>();
    boolean addedSharee = false;
    boolean removedSharee = false;
    /* If there are any removal elements in the invite, remove those
     * sharees. We'll flag hrefs as bad if they are not actually sharees.
     *
     * If we do remove a sharee we'll add notifications to the list
     * to send later.
     */
    for (final RemoveType rem : share.getRemove()) {
        final InviteNotificationType n = doRemove(col, rem, calAddr, invite);
        if (n != null) {
            removedSharee = true;
            if ((n.getPreviousStatus() != null) && !n.getPreviousStatus().equals(declineStatus)) {
                // We don't notify if the user had declined
                notifications.add(n);
            }
            sr.addGood(rem.getHref());
            removePrincipalHrefs.add(rem.getHref());
        } else {
            sr.addBad(rem.getHref());
        }
    }
    /* Now deal with the added sharees if there are any.
     */
    for (final SetType set : share.getSet()) {
        final InviteNotificationType n = doSet(col, set, addPrincipals, calAddr, invite);
        if (n != null) {
            addedSharee = true;
            notifications.add(n);
            sr.addGood(set.getHref());
        } else {
            sr.addBad(set.getHref());
        }
    }
    if (!addedSharee && !removedSharee) {
        // Nothing changed
        return sr;
    }
    /* Send any invitations and update the sharing status.
     * If it's a removal and the current status is not
     * accepted then just delete the current invitation
     */
    final Notifications notify = (Notifications) getSvc().getNotificationsHandler();
    sendNotifications: for (final InviteNotificationType in : notifications) {
        final Sharee sh = getSharee(in.getHref());
        final boolean remove = in.getInviteStatus().equals(removeStatus);
        final List<NotificationType> notes = notify.getMatching(in.getHref(), AppleServerTags.inviteNotification);
        if (!Util.isEmpty(notes)) {
            for (final NotificationType n : notes) {
                final InviteNotificationType nin = (InviteNotificationType) n.getNotification();
                if (!nin.getHostUrl().equals(in.getHostUrl())) {
                    continue;
                }
                if (remove) {
                    if (nin.getInviteStatus().equals(noresponseStatus)) {
                        notify.remove(sh.pr, n);
                        continue sendNotifications;
                    }
                } else {
                    notify.remove(sh.pr, n);
                }
            }
        }
        final NotificationType note = new NotificationType();
        note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
        note.setNotification(in);
        notify.send(sh.pr, note);
        /* Add the invite to the set of properties associated with this collection
       * We give it a name consisting of the inviteNotification tag + uid.
       */
        final QName qn = new QName(AppleServerTags.inviteNotification.getNamespaceURI(), AppleServerTags.inviteNotification.getLocalPart() + in.getUid());
        try {
            col.setProperty(NamespaceAbbrevs.prefixed(qn), in.toXml());
        } catch (final CalFacadeException cfe) {
            throw cfe;
        } catch (final Throwable t) {
            throw new CalFacadeException(t);
        }
    }
    if (addedSharee && !col.getShared()) {
        // Mark the collection as shared
        col.setShared(true);
    }
    try {
        col.setQproperty(AppleServerTags.invite, invite.toXml());
        getCols().update(col);
        for (final String principalHref : removePrincipalHrefs) {
            removeAccess(col, principalHref);
        }
        for (final AddPrincipal ap : addPrincipals) {
            setAccess(col, ap);
        }
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return sr;
}
Also used : ShareResultType(org.bedework.caldav.util.sharing.ShareResultType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) OrganizerType(org.bedework.caldav.util.sharing.OrganizerType) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) RemoveType(org.bedework.caldav.util.sharing.RemoveType) DtStamp(net.fortuna.ical4j.model.property.DtStamp) SetType(org.bedework.caldav.util.sharing.SetType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) InviteType(org.bedework.caldav.util.sharing.InviteType) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)3 OrganizerType (org.bedework.caldav.util.sharing.OrganizerType)3 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 DateTime (net.fortuna.ical4j.model.DateTime)1 DtStamp (net.fortuna.ical4j.model.property.DtStamp)1 InviteType (org.bedework.caldav.util.sharing.InviteType)1 RemoveType (org.bedework.caldav.util.sharing.RemoveType)1 SetType (org.bedework.caldav.util.sharing.SetType)1 ShareResultType (org.bedework.caldav.util.sharing.ShareResultType)1 UserType (org.bedework.caldav.util.sharing.UserType)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)1