Search in sources :

Example 11 with BwResource

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

the class BwSysIntfImpl method getFiles.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#getFiles(org.bedework.caldav.server.CalDAVCollection)
   */
@Override
public Collection<CalDAVResource> getFiles(final CalDAVCollection coll) throws WebdavException {
    try {
        Collection<BwResource> bwrs = getSvci().getResourcesHandler().getAll(coll.getPath());
        if (bwrs == null) {
            return null;
        }
        Collection<CalDAVResource> rs = new ArrayList<CalDAVResource>();
        for (BwResource r : bwrs) {
            rs.add(new BwCalDAVResource(this, r));
        }
        return rs;
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : CalDAVResource(org.bedework.caldav.server.CalDAVResource) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) BwResource(org.bedework.calfacade.BwResource) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 12 with BwResource

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

the class CalintfImpl method getResource.

/* ====================================================================
   *                       resources
   * ==================================================================== */
@Override
public BwResource getResource(final String name, final BwCalendar coll, final int desiredAccess) throws CalFacadeException {
    final BwResource res = entityDao.getResource(name, coll, desiredAccess);
    if (res == null) {
        return null;
    }
    final CurrentAccess ca = checkAccess(res, desiredAccess, true);
    if (!ca.getAccessAllowed()) {
        return null;
    }
    return res;
}
Also used : BwResource(org.bedework.calfacade.BwResource) CurrentAccess(org.bedework.access.Acl.CurrentAccess)

Example 13 with BwResource

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

the class CalSvc method getSynchItems.

private String getSynchItems(final BwCalendar col, final String vpath, final String token, final Set<SynchReportItem> items, final boolean recurse) throws CalFacadeException {
    final Events eventsH = (Events) getEventsHandler();
    final ResourcesImpl resourcesH = (ResourcesImpl) getResourcesHandler();
    final Calendars colsH = (Calendars) getCalendarsHandler();
    String newToken = "";
    BwCalendar resolvedCol = col;
    if (debug) {
        trace("sync token: " + token + " col: " + resolvedCol.getPath());
    }
    if (col.getTombstoned()) {
        return token;
    }
    if (col.getInternalAlias()) {
        resolvedCol = getCalendarsHandler().resolveAlias(col, true, false);
    }
    if (resolvedCol.getTombstoned()) {
        return token;
    }
    /* Each collection could be:
     *    a. A calendar collection or special - like Inbox -
     *           only need to look for events.
     *    b. Other collections. Need to look for events, resources and collections.
     */
    final boolean eventsOnly = resolvedCol.getCollectionInfo().onlyCalEntities;
    final Set<EventInfo> evs = eventsH.getSynchEvents(resolvedCol.getPath(), token);
    for (final EventInfo ei : evs) {
        if (!ei.getEvent().getTombstoned() && !eventsH.isVisible(col, ei.getEvent().getName())) {
            continue;
        }
        final SynchReportItem sri = new SynchReportItem(vpath, ei);
        items.add(sri);
        if (sri.getToken().compareTo(newToken) > 0) {
            newToken = sri.getToken();
        }
    }
    if (!eventsOnly) {
        // Look for resources
        final List<BwResource> ress = resourcesH.getSynchResources(resolvedCol.getPath(), token);
        for (final BwResource r : ress) {
            final SynchReportItem sri = new SynchReportItem(vpath, r);
            items.add(sri);
            if (sri.getToken().compareTo(newToken) > 0) {
                newToken = sri.getToken();
            }
        }
    }
    final Set<SynchReportItem> colItems = new TreeSet<>();
    final Set<BwCalendar> cols = colsH.getSynchCols(resolvedCol.getPath(), token);
    final List<BwCalendar> aliases = new ArrayList<>();
    for (final BwCalendar c : cols) {
        final int calType = c.getCalType();
        if (calType == BwCalendar.calTypePendingInbox) {
            continue;
        }
        if ((token != null) && (calType == BwCalendar.calTypeAlias)) {
            aliases.add(c);
            continue;
        }
        final SynchReportItem sri = new SynchReportItem(vpath, c, canSync(c));
        colItems.add(sri);
        items.add(sri);
        if (sri.getToken().compareTo(newToken) > 0) {
            newToken = sri.getToken();
        }
        if (debug) {
            trace("     token=" + sri.getToken() + " for " + c.getPath());
        }
    }
    if (!Util.isEmpty(aliases)) {
        /* Resolve each one and see if the target is a candidate
       */
        for (final BwCalendar c : aliases) {
            final BwCalendar resolved = getCalendarsHandler().resolveAlias(c, true, false);
            if (resolved == null) {
                continue;
            }
            if (c.getTombstoned() && !getCal().testSynchCol(c, token)) {
                continue;
            }
            if (!getCal().testSynchCol(resolved, token)) {
                continue;
            }
            final SynchReportItem sri = new SynchReportItem(vpath, c, canSync(c), resolved.getLastmod().getTagValue());
            colItems.add(sri);
            items.add(sri);
            if (sri.getToken().compareTo(newToken) > 0) {
                newToken = sri.getToken();
            }
        }
    }
    if (!recurse) {
        return newToken;
    }
    if (Util.isEmpty(colItems)) {
        return newToken;
    }
    for (final SynchReportItem sri : colItems) {
        if (!sri.getCanSync()) {
            continue;
        }
        final BwCalendar sricol = sri.getCol();
        final String t = getSynchItems(sricol, Util.buildPath(true, vpath, "/", sricol.getName()), token, items, true);
        if (t.compareTo(newToken) > 0) {
            newToken = t;
        }
    }
    return newToken;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwResource(org.bedework.calfacade.BwResource) ArrayList(java.util.ArrayList) BwString(org.bedework.calfacade.BwString) BwCalendar(org.bedework.calfacade.BwCalendar) TreeSet(java.util.TreeSet) SynchReportItem(org.bedework.calsvci.SynchReportItem)

Example 14 with BwResource

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

the class Notifications method removeAll.

@Override
public void removeAll(final String principalHref) throws CalFacadeException {
    if (principalHref == null) {
        return;
    }
    final BwCalendar ncol = getCols().getSpecial(principalHref, BwCalendar.calTypeNotifications, true);
    if (ncol == null) {
        return;
    }
    /* Remove resources */
    final ResourcesI resI = getSvc().getResourcesHandler();
    final Collection<BwResource> rs = resI.getAll(ncol.getPath());
    if (!Util.isEmpty(rs)) {
        for (final BwResource r : rs) {
            resI.delete(Util.buildPath(false, r.getColPath(), "/", r.getName()));
        }
    }
}
Also used : BwResource(org.bedework.calfacade.BwResource) ResourcesI(org.bedework.calsvci.ResourcesI) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 15 with BwResource

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

the class Notifications method getMatching.

@Override
public List<NotificationType> getMatching(final QName type) throws CalFacadeException {
    final List<NotificationType> res = new ArrayList<>();
    final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
    if (ncol == null) {
        return res;
    }
    final Collection<BwResource> rsrc = getSvc().getResourcesHandler().getAll(ncol.getPath());
    if (Util.isEmpty(rsrc)) {
        return res;
    }
    if (rsrc.size() > 100) {
        warn("Large resource collection for " + ncol.getPath());
    }
    for (final BwResource r : rsrc) {
        if (type != null) {
            final NotificationInfo ni = NotificationType.fromContentType(r.getContentType());
            if ((ni == null) || !type.equals(ni.type)) {
                continue;
            }
        }
        final NotificationType nt = makeNotification(r);
        if (nt != null) {
            res.add(nt);
        }
    }
    return res;
}
Also used : NotificationInfo(org.bedework.caldav.util.notifications.NotificationType.NotificationInfo) NotificationType(org.bedework.caldav.util.notifications.NotificationType) BwResource(org.bedework.calfacade.BwResource) ArrayList(java.util.ArrayList) BwCalendar(org.bedework.calfacade.BwCalendar)

Aggregations

BwResource (org.bedework.calfacade.BwResource)16 BwCalendar (org.bedework.calfacade.BwCalendar)10 BwResourceContent (org.bedework.calfacade.BwResourceContent)7 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)7 ArrayList (java.util.ArrayList)3 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 ResourcesI (org.bedework.calsvci.ResourcesI)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 TreeSet (java.util.TreeSet)1 CurrentAccess (org.bedework.access.Acl.CurrentAccess)1 HibSession (org.bedework.calcorei.HibSession)1 CalDAVResource (org.bedework.caldav.server.CalDAVResource)1 NotificationInfo (org.bedework.caldav.util.notifications.NotificationType.NotificationInfo)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwString (org.bedework.calfacade.BwString)1