Search in sources :

Example 1 with CalFacadeSubscriptionLoopException

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

the class FilterBuilder method makeFolderFilter.

private CalFilter makeFolderFilter(final BwCalendar val, final ArrayList<String> pathElements) throws CalFacadeException {
    Collection<BwCalendar> cols = parser.getChildren(val);
    OrCalFilter res = new OrCalFilter();
    for (BwCalendar col : cols) {
        if (colCache.get(col.getPath()) == null) {
            colCache.put(col.getPath(), col);
        }
        if (!col.getDisplay()) {
            continue;
        }
        ArrayList<String> pe;
        if (pathElements == null) {
            pe = new ArrayList<>();
        } else {
            pe = new ArrayList<>(pathElements);
        }
        String path = col.getPath();
        if (pe.contains(path)) {
            throw new CalFacadeSubscriptionLoopException();
        }
        pe.add(path);
        CalFilter cf = makeColFilter(col, true, false, pe);
        if (cf == null) {
            continue;
        }
        mergeFilter(res.terms, cf, false);
    }
    if (res.terms.size() == 0) {
        return null;
    }
    if (res.terms.size() == 1) {
        /* Only one filter resulted. Return that rather than the or-filter */
        return res.terms.iterator().next();
    }
    return res;
}
Also used : CalFacadeSubscriptionLoopException(org.bedework.calfacade.exc.CalFacadeSubscriptionLoopException) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 2 with CalFacadeSubscriptionLoopException

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

the class FilterBuilder method makeColFilter.

/* Create a filter for the supplied collection object.
   *
   * explicitSelection is true if we have a single path and it refers directly
   * to the given collection, e.g. /user/xxx/Inbox
   *
   * This allows us to see the contents of the inbox for example, but not to
   * include it when given paths like /user/xxx
   *
   * pathElement is used to detect loops in the actual path. We fail with an
   * exception if we discover a repeated URI in the list.
   */
private CalFilter makeColFilter(final BwCalendar cal, final boolean applyFilter, final boolean explicitSelection, final ArrayList<String> pathElements) throws CalFacadeException {
    /* Result of parsing any filter attached to this entity. */
    FilterBase fltr = null;
    if (applyFilter && (cal.getFilterExpr() != null)) {
        fltr = parseExpr(cal);
    }
    if (cal.getCalType() == BwCalendar.calTypeEventList) {
        OrCalFilter ocf = new OrCalFilter();
        for (EventListEntry ele : cal.getEventList()) {
            HrefFilter hf = new HrefFilter();
            hf.href = ele.getHref();
            ocf.terms.add(hf);
        }
        return ocf;
    }
    /* This covers most - calendar collection, inbox, outbox, external alias etc */
    if (cal.getCollectionInfo().onlyCalEntities) {
        // Leaf node
        if (!explicitSelection && (cal.getCalType() != BwCalendar.calTypeCalendarCollection) && (cal.getCalType() != BwCalendar.calTypeExtSub)) {
            return null;
        }
        EntityCalFilter ecalFilter = new EntityCalFilter();
        ecalFilter.cal = cal;
        ecalFilter.filter = fltr;
        // filterCache.put(calPath, ecalFilter);
        return ecalFilter;
    }
    if (cal.getInternalAlias()) {
        BwCalendar target = parser.resolveAlias(cal, false);
        if (target == null) {
            return null;
        }
        String path = target.getPath();
        if (pathElements.contains(path)) {
            throw new CalFacadeSubscriptionLoopException();
        }
        pathElements.add(path);
        return anded(fltr, makeColFilter(target, true, false, pathElements));
    }
    if (cal.getCalType() == BwCalendar.calTypeFolder) {
        return anded(fltr, makeFolderFilter(cal, pathElements));
    }
    return null;
}
Also used : EventListEntry(org.bedework.calfacade.BwCalendar.EventListEntry) CalFacadeSubscriptionLoopException(org.bedework.calfacade.exc.CalFacadeSubscriptionLoopException) BwCalendar(org.bedework.calfacade.BwCalendar) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)2 CalFacadeSubscriptionLoopException (org.bedework.calfacade.exc.CalFacadeSubscriptionLoopException)2 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 EventListEntry (org.bedework.calfacade.BwCalendar.EventListEntry)1