Search in sources :

Example 26 with BwCalendar

use of org.bedework.calfacade.BwCalendar 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 27 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class Sharing method removeAccess.

private boolean removeAccess(final BwCalendar col, final String principalHref) throws CalFacadeException {
    Acl acl = col.getCurrentAccess().getAcl();
    try {
        if (Util.isEmpty(acl.getAces())) {
            return false;
        }
        final BwPrincipal pr = caladdrToPrincipal(principalHref);
        acl = removeAccess(acl, pr.getAccount(), pr.getKind());
        if (acl == null) {
            // no change
            return false;
        }
        getSvc().changeAccess(col, acl.getAces(), true);
        if (!col.getInternalAlias()) {
            return true;
        }
        final BwCalendar target = getSvc().getCalendarsHandler().resolveAlias(col, false, false);
        if (target == null) {
            return false;
        }
        /* Switch identity to the sharee then reget the handler
       * and do the share
       */
        pushPrincipal(target.getOwnerHref());
        try {
            return removeAccess(target, principalHref);
        } catch (final CalFacadeException cfe) {
            throw cfe;
        } catch (final Throwable t) {
            throw new CalFacadeException(t);
        } finally {
            popPrincipal();
        }
    } catch (final AccessException ae) {
        throw new CalFacadeException(ae);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) AccessException(org.bedework.access.AccessException) Acl(org.bedework.access.Acl) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 28 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class Users method remove.

@Override
public void remove(final BwPrincipal pr) throws CalFacadeException {
    final String userRoot = getSvc().getPrincipalInfo().getCalendarHomePath(pr);
    /* views */
    final Collection<BwView> views = getSvc().getViewsHandler().getAll(pr);
    for (final BwView view : views) {
        getSvc().getViewsHandler().remove(view);
    }
    /* Set default calendar to null so we don't get blocked. */
    final BwPreferences prefs = getSvc().getPrefsHandler().get(pr);
    if (prefs != null) {
        prefs.setDefaultCalendarPath(null);
        getSvc().getPrefsHandler().update(prefs);
    }
    /* collections and user home */
    final BwCalendar home = getSvc().getCalendarsHandler().get(userRoot);
    if (home != null) {
        ((Calendars) getCols()).delete(home, true, true, false, true);
    }
    /* Remove preferences */
    getSvc().getPrefsHandler().delete(prefs);
    getCal().delete(pr);
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwCalendar(org.bedework.calfacade.BwCalendar) BwView(org.bedework.calfacade.svc.BwView)

Example 29 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class Notifications method find.

@Override
public NotificationType find(final String name) throws CalFacadeException {
    final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
    if (ncol == null) {
        return null;
    }
    final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", name));
    if (noteRsrc == null) {
        return null;
    }
    return makeNotification(noteRsrc);
}
Also used : BwResource(org.bedework.calfacade.BwResource) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 30 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class Notifications method remove.

@Override
public void remove(final String principalHref, final String name) throws CalFacadeException {
    if (name == null) {
        return;
    }
    final BwCalendar ncol = getCols().getSpecial(principalHref, BwCalendar.calTypeNotifications, true);
    if (ncol == null) {
        return;
    }
    final String path = Util.buildPath(false, ncol.getPath(), "/", name);
    getSvc().getResourcesHandler().delete(path);
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)134 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)46 EventInfo (org.bedework.calfacade.svc.EventInfo)23 BwEvent (org.bedework.calfacade.BwEvent)19 ArrayList (java.util.ArrayList)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)18 BwPrincipal (org.bedework.calfacade.BwPrincipal)15 TreeSet (java.util.TreeSet)10 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)10 BwCategory (org.bedework.calfacade.BwCategory)10 BwResource (org.bedework.calfacade.BwResource)10 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)9 FilterBase (org.bedework.caldav.util.filter.FilterBase)8 BwPreferences (org.bedework.calfacade.svc.BwPreferences)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)7 CurrentAccess (org.bedework.access.Acl.CurrentAccess)6 CalendarsI (org.bedework.calsvci.CalendarsI)6 Acl (org.bedework.access.Acl)5 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)5