Search in sources :

Example 6 with TimeRange

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

the class Filters method doEntityTimeRangeReplace.

private void doEntityTimeRangeReplace(final EntityTimeRangeFilter trf) throws CalFacadeException {
    TimeRange tr = trf.getEntity();
    if ((tr.getEnd() == null) && (tr.getStart() == null)) {
        return;
    }
    qseg.append("(");
    drReplace(true, tr);
    qseg.append(" or ");
    drReplace(false, tr);
    qseg.append(")");
}
Also used : TimeRange(org.bedework.caldav.util.TimeRange)

Example 7 with TimeRange

use of org.bedework.caldav.util.TimeRange 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)

Aggregations

TimeRange (org.bedework.caldav.util.TimeRange)7 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3 Collection (java.util.Collection)2 AndFilter (org.bedework.caldav.util.filter.AndFilter)2 EntityTimeRangeFilter (org.bedework.caldav.util.filter.EntityTimeRangeFilter)2 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)2 OrFilter (org.bedework.caldav.util.filter.OrFilter)2 TimeRangeFilter (org.bedework.caldav.util.filter.TimeRangeFilter)2 BwCalendar (org.bedework.calfacade.BwCalendar)2 BwHrefFilter (org.bedework.calfacade.filter.BwHrefFilter)2 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)2 QueryFilterBuilder (org.elasticsearch.index.query.QueryFilterBuilder)2 RangeFilterBuilder (org.elasticsearch.index.query.RangeFilterBuilder)2 TermFilterBuilder (org.elasticsearch.index.query.TermFilterBuilder)2 TermsFilterBuilder (org.elasticsearch.index.query.TermsFilterBuilder)2 DateTime (net.fortuna.ical4j.model.DateTime)1 BooleanFilter (org.bedework.caldav.util.filter.BooleanFilter)1 EntityTypeFilter (org.bedework.caldav.util.filter.EntityTypeFilter)1 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 PresenceFilter (org.bedework.caldav.util.filter.PresenceFilter)1