Search in sources :

Example 1 with EventListEntry

use of org.bedework.calfacade.BwCalendar.EventListEntry 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)

Example 2 with EventListEntry

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

the class Events method get.

@Override
public EventInfo get(final BwCalendar col, final String name, final String recurrenceId, final List<String> retrieveList) throws CalFacadeException {
    if ((col == null) || (name == null)) {
        throw new CalFacadeException(CalFacadeException.badRequest);
    }
    if (col.getInternalAlias()) {
        final String expr = "(vpath='" + SfpTokenizer.escapeQuotes(col.getPath()) + "') and (name='" + SfpTokenizer.escapeQuotes(name) + "')";
        final SimpleFilterParser sfp = getSvc().getFilterParser();
        final ParseResult pr = sfp.parse(expr, true, null);
        if (!pr.ok) {
            throw new CalFacadeException("Failed to parse " + expr + ": message was " + pr.message);
        }
        final Collection<EventInfo> evs = getEvents(null, pr.filter, // start
        null, // end
        null, RetrieveList.getRetrieveList(retrieveList), DeletedState.noDeleted, RecurringRetrievalMode.overrides);
        if (evs.size() == 0) {
            return null;
        }
        if (evs.size() == 1) {
            return evs.iterator().next();
        }
        throw new CalFacadeException("Multiple results");
    }
    String path = col.getPath();
    if (col.getCalType() == BwCalendar.calTypeEventList) {
        /* Find the event in the list using the name */
        final SortedSet<EventListEntry> eles = col.getEventList();
        findHref: {
            for (final EventListEntry ele : eles) {
                if (ele.getName().equals(name)) {
                    path = ele.getPath();
                    break findHref;
                }
            }
            // Not in list
            return null;
        }
    // findHref
    }
    return get(path, name, null);
}
Also used : EventListEntry(org.bedework.calfacade.BwCalendar.EventListEntry) ParseResult(org.bedework.calfacade.filter.SimpleFilterParser.ParseResult) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) SimpleFilterParser(org.bedework.calfacade.filter.SimpleFilterParser) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

EventListEntry (org.bedework.calfacade.BwCalendar.EventListEntry)2 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)1 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 BwCalendar (org.bedework.calfacade.BwCalendar)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 CalFacadeSubscriptionLoopException (org.bedework.calfacade.exc.CalFacadeSubscriptionLoopException)1 SimpleFilterParser (org.bedework.calfacade.filter.SimpleFilterParser)1 ParseResult (org.bedework.calfacade.filter.SimpleFilterParser.ParseResult)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1