Search in sources :

Example 6 with AndFilter

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

the class Filters method addJoins.

/*
  private String makeUtcformat(String dt) {
    int len = dt.length();

    if (len == 16) {
      return dt;
    }

    if (len == 15) {
      return dt + "Z";
    }

    if (len == 8) {
      return dt + "T000000Z";
    }

    throw new RuntimeException("Bad date " + dt);
  }*/
private void addJoins(final FilterBase f) throws CalFacadeException {
    if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
        for (FilterBase flt : f.getChildren()) {
            addJoins(flt);
        }
        return;
    }
    if (!(f instanceof PropertyFilter)) {
        return;
    }
    if (f instanceof PresenceFilter) {
        return;
    }
    if (f instanceof BwHrefFilter) {
        return;
    }
    PropertyFilter pf = (PropertyFilter) f;
    BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
    if (pi == null) {
        throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
    }
    if (!pi.getMultiValued()) {
        return;
    }
    if (f instanceof TimeRangeFilter) {
        addThisJoin(pi);
        return;
    }
    if (f instanceof BwObjectFilter) {
        addThisJoin(pi);
        return;
    }
}
Also used : PresenceFilter(org.bedework.caldav.util.filter.PresenceFilter) AndFilter(org.bedework.caldav.util.filter.AndFilter) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) BwHrefFilter(org.bedework.calfacade.filter.BwHrefFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) PropertyFilter(org.bedework.caldav.util.filter.PropertyFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter)

Example 7 with AndFilter

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

the class Filters method match.

private boolean match(final FilterBase f, final BwEvent ev, final String userHref) throws CalFacadeException {
    if (f == null) {
        return true;
    }
    if (debug) {
        debug("match " + f);
    }
    if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
        boolean itsAnd = (f instanceof AndFilter);
        for (FilterBase flt : f.getChildren()) {
            if (match(flt, ev, userHref)) {
                if (!itsAnd) {
                    // Success for OR
                    if (debug) {
                        debug("match true");
                    }
                    return true;
                }
            } else if (itsAnd) {
                debug("match true");
                return false;
            }
        }
        // For AND all matched, for OR nothing matched
        debug("match " + itsAnd);
        return itsAnd;
    }
    if (f instanceof EntityTimeRangeFilter) {
        // Matched in db query
        return true;
    }
    if (!(f instanceof PropertyFilter)) {
        /* We assume we can't handle this one as a query.
       */
        throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
    }
    PropertyFilter pf = (PropertyFilter) f;
    BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
    if (pi == null) {
        throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
    }
    String fieldName = pi.getDbFieldName();
    boolean param = pi.getParam();
    if (param) {
        BwIcalPropertyInfoEntry parentPi = BwIcalPropertyInfo.getPinfo(pf.getParentPropertyIndex());
        fieldName = parentPi.getDbFieldName() + "." + fieldName;
    }
    try {
        if (pf instanceof BwCategoryFilter) {
            return traceMatch(pf.match(ev, userHref));
        }
        if (f instanceof PresenceFilter) {
            return traceMatch(matchPresence(pf.getPropertyIndex(), ev, userHref));
        }
        if (pf instanceof TimeRangeFilter) {
            return traceMatch(match((TimeRangeFilter) pf, ev));
        }
        if (pf instanceof BwObjectFilter) {
            return traceMatch(pf.match(ev, userHref));
        }
    } catch (WebdavException wde) {
        throw new CalFacadeException(wde);
    }
    throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
Also used : PresenceFilter(org.bedework.caldav.util.filter.PresenceFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCategoryFilter(org.bedework.calfacade.filter.BwCategoryFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) AndFilter(org.bedework.caldav.util.filter.AndFilter) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) PropertyFilter(org.bedework.caldav.util.filter.PropertyFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter)

Example 8 with AndFilter

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

the class Filters method parReplace.

/* Fill in the parameters after we generated the query.
   */
private void parReplace(final FilterBase f) throws CalFacadeException {
    if (f instanceof AndFilter) {
        AndFilter fb = (AndFilter) f;
        for (FilterBase flt : fb.getChildren()) {
            parReplace(flt);
        }
        return;
    }
    if (f instanceof BwHrefFilter) {
        BwHrefFilter hf = (BwHrefFilter) f;
        // Special case this
        sess.setString(parPrefix + qi, hf.getPathPart());
        qi++;
        sess.setString(parPrefix + qi, hf.getNamePart());
        qi++;
    }
    if (f instanceof BwCategoryFilter) {
        BwCategoryFilter cf = (BwCategoryFilter) f;
        BwCategory cat = cf.getEntity();
        /* XXX - this is what we want to be able to do
      sess.setString(parPrefix + qi, cat.getUid());
      */
        sess.setEntity(parPrefix + qi, cat);
        qi++;
        return;
    }
    if (f instanceof EntityTimeRangeFilter) {
        doEntityTimeRangeReplace((EntityTimeRangeFilter) f);
        return;
    }
    if (f instanceof TimeRangeFilter) {
        TimeRangeFilter trf = (TimeRangeFilter) f;
        TimeRange tr = trf.getEntity();
        if (tr.getStart() != null) {
            sess.setParameter(parPrefix + qi, tr.getStart().toString());
            qi++;
        }
        if (tr.getEnd() != null) {
            sess.setParameter(parPrefix + qi, tr.getEnd().toString());
            qi++;
        }
        return;
    }
    if (f instanceof BwObjectFilter) {
        ObjectFilter of = ((BwObjectFilter) f).getEntity();
        Object o = of.getEntity();
        Collection c = null;
        boolean isString = o instanceof String;
        if (!isString) {
            if (o instanceof Collection) {
                c = (Collection) o;
                if (c.size() > 0) {
                    o = c.iterator().next();
                    isString = o instanceof String;
                }
            }
        }
        boolean doCaseless = isString && of.getCaseless();
        if (c != null) {
            // TODO - Assuming String collection
            for (Object co : c) {
                String s = (String) co;
                if (doCaseless) {
                    s = s.toLowerCase();
                }
                sess.setParameter(parPrefix + qi, s);
                qi++;
            }
            return;
        }
        if (o instanceof BwCalendar) {
            BwCalendar cal = unwrap((BwCalendar) o);
            sess.setString(parPrefix + qi, cal.getPath());
        } else if (o instanceof BwPrincipal) {
            sess.setString(parPrefix + qi, ((BwPrincipal) o).getPrincipalRef());
        } else if (o instanceof BwDbentity) {
            sess.setEntity(parPrefix + qi, o);
        } else if (of.getExact()) {
            if (doCaseless) {
                o = ((String) o).toLowerCase();
            }
            sess.setParameter(parPrefix + qi, o);
        } else if (of.getEntity() instanceof String) {
            String s = o.toString();
            if (doCaseless) {
                s = s.toLowerCase();
            }
            sess.setString(parPrefix + qi, "%" + s + "%");
        } else {
            sess.setString(parPrefix + qi, "%" + o + "%");
        }
        qi++;
        return;
    }
    if (f instanceof OrFilter) {
        OrFilter fb = (OrFilter) f;
        for (FilterBase flt : fb.getChildren()) {
            parReplace(flt);
        }
        return;
    }
}
Also used : BwHrefFilter(org.bedework.calfacade.filter.BwHrefFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) BwCategory(org.bedework.calfacade.BwCategory) BwCategoryFilter(org.bedework.calfacade.filter.BwCategoryFilter) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) BwCalendar(org.bedework.calfacade.BwCalendar) OrFilter(org.bedework.caldav.util.filter.OrFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) AndFilter(org.bedework.caldav.util.filter.AndFilter) TimeRange(org.bedework.caldav.util.TimeRange) BwPrincipal(org.bedework.calfacade.BwPrincipal) Collection(java.util.Collection) BwDbentity(org.bedework.calfacade.base.BwDbentity) FilterBase(org.bedework.caldav.util.filter.FilterBase) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter)

Example 9 with AndFilter

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

the class SimpleFilterParser method and.

private FilterBase and(final String name, final FilterBase af, final FilterBase f) {
    final FilterBase res;
    if (af == null) {
        res = f;
    } else {
        if (af instanceof AndFilter) {
            res = af;
        } else {
            res = new AndFilter();
            res.addChild(af);
        }
        res.addChild(f);
    }
    if (name != null) {
        res.setName(name);
    }
    return res;
}
Also used : AndFilter(org.bedework.caldav.util.filter.AndFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Aggregations

AndFilter (org.bedework.caldav.util.filter.AndFilter)9 FilterBase (org.bedework.caldav.util.filter.FilterBase)7 OrFilter (org.bedework.caldav.util.filter.OrFilter)7 EntityTimeRangeFilter (org.bedework.caldav.util.filter.EntityTimeRangeFilter)6 TimeRangeFilter (org.bedework.caldav.util.filter.TimeRangeFilter)6 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)5 PresenceFilter (org.bedework.caldav.util.filter.PresenceFilter)5 PropertyFilter (org.bedework.caldav.util.filter.PropertyFilter)5 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 BwObjectFilter (org.bedework.calfacade.filter.BwObjectFilter)5 BwCategoryFilter (org.bedework.calfacade.filter.BwCategoryFilter)4 BwHrefFilter (org.bedework.calfacade.filter.BwHrefFilter)4 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)4 BwCalendar (org.bedework.calfacade.BwCalendar)3 TimeRange (org.bedework.caldav.util.TimeRange)2 EntityTypeFilter (org.bedework.caldav.util.filter.EntityTypeFilter)2 BwCategory (org.bedework.calfacade.BwCategory)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 BooleanFilter (org.bedework.caldav.util.filter.BooleanFilter)1