Search in sources :

Example 6 with PresenceFilter

use of org.bedework.caldav.util.filter.PresenceFilter in project bw-calendar-engine by Bedework.

the class SimpleFilterParser method makePropFilter.

private FilterBase makePropFilter(final List<PropertyInfo> pis, final int oper) throws ParseFailed {
    final PropertyInfo pi = pis.get(0);
    FilterBase filter = null;
    final List<PropertyInfoIndex> pixs = new ArrayList<>();
    pis.forEach(val -> pixs.add(val.pii));
    final boolean exact = (oper != like) && (oper != notLike);
    if (pi.pii == PropertyInfoIndex.ENTITY_TYPE) {
        checkSub(pis, 1);
        return entityFilter(getMatch(oper).getValue());
    }
    if (oper == notDefined) {
        checkSub(pis, 2);
        return new PresenceFilter(null, pixs, false, pi.intKey, pi.strKey);
    }
    if (oper == isDefined) {
        // Presence check
        checkSub(pis, 2);
        return new PresenceFilter(null, pixs, true, pi.intKey, pi.strKey);
    }
    if (oper == inTimeRange) {
        checkSub(pis, 2);
        return ObjectFilter.makeFilter(null, pixs, getTimeRange(), pi.intKey, pi.strKey);
    }
    if (pi.pii == PropertyInfoIndex.VIEW) {
        checkSub(pis, 1);
        // expect list of views.
        final ArrayList<String> views = doWordList();
        for (final String view : views) {
            final FilterBase vpf = viewFilter(view);
            filter = and(null, filter, vpf);
        }
        return filter;
    }
    if (pi.pii == PropertyInfoIndex.VPATH) {
        checkSub(pis, 1);
        // expect list of virtual paths.
        final ArrayList<String> vpaths = doWordList();
        for (final String vpath : vpaths) {
            final FilterBase vpf = resolveVpath(vpath);
            filter = and(null, filter, vpf);
        }
        return filter;
    }
    if ((pi.pii == PropertyInfoIndex.CATEGORIES) && (pis.size() == 2)) {
        final PropertyInfo subPi = pis.get(1);
        if (subPi.pii == PropertyInfoIndex.UID) {
            // No match and category - expect list of uids.
            final ArrayList<String> uids = doWordList();
            for (final String uid : uids) {
                final BwCategory cat = callGetCategory(uid);
                if (cat == null) {
                    // Deleted category?
                    throw parseResult.fail("Category uid references missing category: " + uid + " Filter will always fail to match");
                }
                final ObjectFilter<String> f = new ObjectFilter<String>(null, pixs);
                f.setEntity(uid);
                f.setExact(exact);
                f.setNot(oper == notEqual);
                filter = and(null, filter, f);
            }
            return filter;
        }
        if (subPi.pii == PropertyInfoIndex.HREF) {
            // No match and category - expect list of paths.
            final ArrayList<String> paths = doWordList();
            for (final String path : paths) {
                final ObjectFilter<String> f = new ObjectFilter<String>(null, pixs);
                f.setEntity(path);
                f.setCaseless(false);
                f.setExact(exact);
                f.setNot(oper == notEqual);
                filter = and(null, filter, f);
            }
            return filter;
        }
    }
    if ((pi.pii == PropertyInfoIndex.COLLECTION) || (pi.pii == PropertyInfoIndex.COLPATH)) {
        checkSub(pis, 1);
        final ArrayList<String> paths = doWordList();
        for (final String path : paths) {
            final FilterBase pf = resolveColPath(path, true, true);
            if (pf == null) {
                continue;
            }
            filter = and(null, filter, pf);
        }
        return filter;
    }
    final MatchType match = getMatch(oper);
    if (pi.pii == PropertyInfoIndex.CATEGORIES) {
        checkSub(pis, 1);
        final String val = match.getValue();
        if (val.startsWith("/")) {
            pixs.add(PropertyInfoIndex.HREF);
            // Assume a path match
            final ObjectFilter<String> f = new ObjectFilter<String>(null, pixs);
            f.setEntity(val);
            f.setCaseless(false);
            f.setExact(exact);
            f.setNot(match.getNegateCondition().equals("yes"));
            return f;
        }
        // Try for name
        final BwCategory cat = callGetCategoryByName(val);
        if (cat == null) {
            throw parseResult.fail("Bad property: " + "category name: " + match.getValue() + " source: " + source);
        }
        pixs.add(PropertyInfoIndex.UID);
        final ObjectFilter<BwCategory> f = new BwCategoryFilter(null, pixs);
        f.setEntity(cat);
        f.setExact(exact);
        f.setNot(match.getNegateCondition().equals("yes"));
        return f;
    }
    checkSub(pis, 2);
    final ObjectFilter<String> f = new ObjectFilter<>(null, pixs, pi.intKey, pi.strKey);
    f.setEntity(match.getValue());
    f.setCaseless(Filters.caseless(match));
    f.setExact(exact);
    f.setNot(match.getNegateCondition().equals("yes"));
    f.setPrefixMatch(match.getPrefixMatch());
    return f;
}
Also used : PresenceFilter(org.bedework.caldav.util.filter.PresenceFilter) ArrayList(java.util.ArrayList) BwCategory(org.bedework.calfacade.BwCategory) ToString(org.bedework.util.misc.ToString) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) TextMatchType(ietf.params.xml.ns.caldav.TextMatchType) BwIcalPropertyInfo(org.bedework.calfacade.ical.BwIcalPropertyInfo) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Aggregations

PresenceFilter (org.bedework.caldav.util.filter.PresenceFilter)6 AndFilter (org.bedework.caldav.util.filter.AndFilter)5 EntityTimeRangeFilter (org.bedework.caldav.util.filter.EntityTimeRangeFilter)5 FilterBase (org.bedework.caldav.util.filter.FilterBase)5 OrFilter (org.bedework.caldav.util.filter.OrFilter)5 PropertyFilter (org.bedework.caldav.util.filter.PropertyFilter)5 TimeRangeFilter (org.bedework.caldav.util.filter.TimeRangeFilter)5 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 BwObjectFilter (org.bedework.calfacade.filter.BwObjectFilter)4 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)4 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)3 BwCategoryFilter (org.bedework.calfacade.filter.BwCategoryFilter)3 BwHrefFilter (org.bedework.calfacade.filter.BwHrefFilter)3 ArrayList (java.util.ArrayList)2 EntityTypeFilter (org.bedework.caldav.util.filter.EntityTypeFilter)2 BwCategory (org.bedework.calfacade.BwCategory)2 BwIcalPropertyInfo (org.bedework.calfacade.ical.BwIcalPropertyInfo)2 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)2 TextMatchType (ietf.params.xml.ns.caldav.TextMatchType)1 TimeRange (org.bedework.caldav.util.TimeRange)1