Search in sources :

Example 61 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException 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 62 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException 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 63 with CalFacadeException

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

the class TimeZonesStoreImpl method updateFromTimeZones.

@Override
public UpdateFromTimeZonesInfo updateFromTimeZones(final String colHref, final int limit, final boolean checkOnly, final UpdateFromTimeZonesInfo info) throws CalFacadeException {
    /* Versions < 3.3 don't have recurrences fully implemented so we'll
     * ignore those.
     *
     * Fields that could be affected:
     * Event start + end
     * rdates and exdates
     * Recurrence instances
     *
     */
    if ((info != null) && !(info instanceof UpdateFromTimeZonesInfoInternal)) {
        throw new CalFacadeException(CalFacadeException.illegalObjectClass);
    }
    boolean redo = false;
    final UpdateFromTimeZonesInfoInternal iinfo;
    if (info != null) {
        if (info.getTotalEventsToCheck() == info.getTotalEventsChecked()) {
            redo = true;
        }
        iinfo = (UpdateFromTimeZonesInfoInternal) info;
    } else {
        iinfo = new UpdateFromTimeZonesInfoInternal();
    }
    if (redo || (iinfo.names == null)) {
        String lastmod = null;
        if (redo) {
            lastmod = new LastModified(new DateTime(iinfo.lastmod - 5000)).getValue();
        }
        // Get event ids from db.
        iinfo.lastmod = System.currentTimeMillis();
        if (iinfo.names == null) {
            iinfo.names = new ArrayList<>();
        }
        iinfo.totalEventsChecked = 0;
        iinfo.totalEventsUpdated = 0;
        iinfo.iterator = iinfo.names.iterator();
    }
    for (int i = 0; i < limit; i++) {
        if (!iinfo.iterator.hasNext()) {
            break;
        }
        final String name = iinfo.iterator.next();
        /*
      // See if event needs update
      BwPrincipal owner = svci.getUsersHandler().getPrincipal(ikey.getOwnerHref());

      BwDateTime start = checkDateTimeForTZ(ikey.getStart(), owner, iinfo);
      BwDateTime end = checkDateTimeForTZ(ikey.getEnd(), owner, iinfo);

      if ((start != null) || (end != null)) {
        CoreEventInfo cei = ((Events)svci.getEventsHandler()).getEvent(ikey);
        BwEvent ev = cei.getEvent();

        if (cei != null) {
          iinfo.updatedList.add(new BwEventKey(ev.getColPath(),
                                               ev.getUid(),
                                               ev.getRecurrenceId(),
                                               ev.getName(),
                                               ev.getRecurring()));
          if (!checkOnly) {
            if (start != null) {
              BwDateTime evstart = ev.getDtstart();
              if (debug) {
                trace("Updated start: ev.tzid=" + evstart.getTzid() +
                      " ev.dtval=" + evstart.getDtval() +
                      " ev.date=" + evstart.getDate() +
                      " newdate=" + start.getDate());
              }

              ev.setDtstart(BwDateTime.makeBwDateTime(evstart.getDateType(),
                                                      evstart.getDtval(),
                                                      start.getDate(),
                                                      evstart.getTzid(),
                                                      evstart.getFloating()));
            }
            if (end != null) {
              BwDateTime evend = ev.getDtend();
              if (debug) {
                trace("Updated end: ev.tzid=" + evend.getTzid() +
                      " ev.dtval=" + evend.getDtval() +
                      " ev.date=" + evend.getDate() +
                      " newdate=" + end.getDate());
              }
              ev.setDtend(BwDateTime.makeBwDateTime(evend.getDateType(),
                                                    evend.getDtval(),
                                                    end.getDate(),
                                                    evend.getTzid(),
                                                    evend.getFloating()));
            }

            EventInfo ei = new EventInfo(ev);

            Collection<CoreEventInfo> overrides = cei.getOverrides();
            if (overrides != null) {
              for (CoreEventInfo ocei: overrides) {
                BwEventProxy op = (BwEventProxy)ocei.getEvent();

                ei.addOverride(new EventInfo(op));
              }
            }

            svci.getEventsHandler().update(ei, false, null);
            iinfo.totalEventsUpdated++;
          }
        }
      }
      */
        iinfo.totalEventsChecked++;
    }
    if (debug) {
        trace(iinfo.toString());
    }
    return iinfo;
}
Also used : LastModified(net.fortuna.ical4j.model.property.LastModified) ToString(org.bedework.util.misc.ToString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 64 with CalFacadeException

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

the class Users method initUserObject.

BwPrincipal initUserObject(final String val) throws CalFacadeException {
    String account = val;
    if (account.endsWith("/")) {
        account = account.substring(0, account.length() - 1);
    }
    if (getSvc().getDirectories().isPrincipal(val)) {
        account = getSvc().getDirectories().accountFromPrincipal(val);
    }
    if (account == null) {
        throw new CalFacadeException("Bad user account " + val);
    }
    setRoots(getSvc());
    final BwPrincipal user = BwPrincipal.makeUserPrincipal();
    user.setAccount(account);
    user.setCategoryAccess(Access.getDefaultPersonalAccess());
    user.setLocationAccess(Access.getDefaultPersonalAccess());
    user.setContactAccess(Access.getDefaultPersonalAccess());
    user.setQuota(getSvc().getAuthProperties().getDefaultUserQuota());
    user.setPrincipalRef(Util.buildPath(colPathEndsWithSlash, userPrincipalRoot, "/", account));
    return user;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 65 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException 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)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12