Search in sources :

Example 1 with ParseResult

use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult in project bw-calendar-engine by Bedework.

the class FilterBuilder method parseExpr.

private FilterBase parseExpr(final BwCalendar col) throws CalFacadeException {
    SimpleFilterParser sfp = parser.getParser();
    ParseResult pr = sfp.parse(col.getFilterExpr(), false, col.getPath());
    if (!pr.ok) {
        throw pr.cfe;
    }
    return pr.filter;
}
Also used : ParseResult(org.bedework.calfacade.filter.SimpleFilterParser.ParseResult)

Example 2 with ParseResult

use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult in project bw-calendar-engine by Bedework.

the class Filters method parse.

@Override
public ParseResult parse(final BwFilterDef val) {
    final String def = val.getDefinition();
    if ((def.length() > 5) && (def.startsWith("<?xml"))) {
        // Assume xml filter
        final ParseResult pr = new ParseResult();
        try {
            final FilterType f = org.bedework.caldav.util.filter.parse.Filters.parse(def);
            final EventQuery eq = org.bedework.caldav.util.filter.parse.Filters.getQuery(f);
            val.setFilters(eq.filter);
            pr.ok = true;
        } catch (final Throwable t) {
            pr.ok = false;
            pr.message = t.getMessage();
            pr.cfe = new CalFacadeException(t);
        }
        return pr;
    }
    // Assume simple expression filter
    final String source = "BwFilterDef:" + val.getOwnerHref() + ":" + val.getName();
    final ParseResult pr = getSvc().getFilterParser().parse(def, false, source);
    if (pr.ok) {
        val.setFilters(pr.filter);
    }
    return pr;
}
Also used : FilterType(ietf.params.xml.ns.caldav.FilterType) ParseResult(org.bedework.calfacade.filter.SimpleFilterParser.ParseResult) EventQuery(org.bedework.caldav.util.filter.parse.EventQuery) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with ParseResult

use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getEvents.

@Override
public Collection<CalDAVEvent> getEvents(final CalDAVCollection col, final FilterBase filter, final List<String> retrieveList, final RetrievalMode recurRetrieval) throws WebdavException {
    try {
        /* Limit the results to just this collection by adding an ANDed filter */
        final SimpleFilterParser sfp = getSvci().getFilterParser();
        final String expr = "(colPath='" + SfpTokenizer.escapeQuotes(col.getPath()) + "')";
        final ParseResult pr = sfp.parse(expr, true, null);
        if (!pr.ok) {
            throw new WebdavBadRequest("Failed to reference collection " + col.getPath() + ": message was " + pr.message);
        }
        final FilterBase f = FilterBase.addAndChild(filter, pr.filter);
        final Collection<EventInfo> bwevs = // Collection
        getSvci().getEventsHandler().getEvents(// Collection
        null, f, // start
        null, // end
        null, RetrieveList.getRetrieveList(retrieveList), DeletedState.noDeleted, getRrm(recurRetrieval));
        if (bwevs == null) {
            return null;
        }
        final Collection<CalDAVEvent> evs = new ArrayList<>();
        for (final EventInfo ei : bwevs) {
            if (recurRetrieval != null) {
                ei.getEvent().setForceUTC(recurRetrieval.getExpand() != null);
            }
            evs.add(new BwCalDAVEvent(this, ei));
        }
        return evs;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.unknownProperty.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Unknown property " + cfe.getExtra());
        }
        throw new WebdavException(cfe);
    } catch (final WebdavException wde) {
        throw wde;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ParseResult(org.bedework.calfacade.filter.SimpleFilterParser.ParseResult) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) SimpleFilterParser(org.bedework.calfacade.filter.SimpleFilterParser) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) CalDAVEvent(org.bedework.caldav.server.CalDAVEvent) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 4 with ParseResult

use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult 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

ParseResult (org.bedework.calfacade.filter.SimpleFilterParser.ParseResult)4 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3 SimpleFilterParser (org.bedework.calfacade.filter.SimpleFilterParser)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 FilterType (ietf.params.xml.ns.caldav.FilterType)1 ArrayList (java.util.ArrayList)1 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)1 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)1 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 EventQuery (org.bedework.caldav.util.filter.parse.EventQuery)1 EventListEntry (org.bedework.calfacade.BwCalendar.EventListEntry)1 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)1 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)1 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)1 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)1