Search in sources :

Example 1 with TimeRange

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

the class SimpleFilterParser method makeTimeRange.

private TimeRange makeTimeRange(final String startStr, final String endStr) throws ParseFailed {
    try {
        DateTime start = null;
        DateTime end = null;
        if (startStr != null) {
            start = new DateTime(startStr);
        }
        if (endStr != null) {
            end = new DateTime(endStr);
        }
        return new TimeRange(start, end);
    } catch (final Throwable t) {
        throw parseResult.setCfe(new CalFacadeException(t));
    }
}
Also used : TimeRange(org.bedework.caldav.util.TimeRange) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with TimeRange

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

the class ESQueryFilter method makeFilter.

private FilterBuilder makeFilter(final FilterBase f) throws CalFacadeException {
    if (f == null) {
        return null;
    }
    if (f instanceof BooleanFilter) {
        final BooleanFilter bf = (BooleanFilter) f;
        if (!bf.getValue()) {
            return new MatchNone();
        } else {
            return new MatchAllFilterBuilder();
        }
    }
    if (f instanceof AndFilter) {
        final List<FilterBuilder> fbs = makeFilters(f.getChildren(), true);
        if (fbs.size() == 1) {
            return fbs.get(0);
        }
        final AndFilterBuilder afb = new AndFilterBuilder();
        afb.filterName(f.getName());
        for (final FilterBuilder fb : fbs) {
            if (fb instanceof TermOrTerms) {
                afb.add(makeFilter((TermOrTerms) fb));
            } else {
                afb.add(fb);
            }
        }
        return afb;
    }
    if (f instanceof OrFilter) {
        final List<FilterBuilder> fbs = makeFilters(f.getChildren(), false);
        if (fbs.size() == 1) {
            return fbs.get(0);
        }
        final OrFilterBuilder ofb = new OrFilterBuilder();
        ofb.filterName(f.getName());
        for (final FilterBuilder fb : fbs) {
            if (fb instanceof TermOrTerms) {
                ofb.add(((TermOrTerms) fb).makeFb());
            } else {
                ofb.add(fb);
            }
        }
        return ofb;
    }
    if (f instanceof BwViewFilter) {
        return doView((BwViewFilter) f);
    }
    if (f instanceof BwHrefFilter) {
        queryLimited = true;
        final TermFilterBuilder tfb = FilterBuilders.termFilter(hrefJname, ((BwHrefFilter) f).getHref());
        tfb.filterName(f.getName());
        return tfb;
    }
    if (!(f instanceof PropertyFilter)) {
        return null;
    }
    final PropertyFilter pf = (PropertyFilter) f;
    /*
    if (pf.getPropertyIndex() == PropertyInfoIndex.CATEGORY_PATH) {
      // Special case this one.
      return new TermOrTerms(PropertyInfoIndex.CATEGORY_PATH.getJname(),
                             ((ObjectFilter)pf).getEntity());
    }*/
    final BwIcalPropertyInfo.BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
    if (pi == null) {
        throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
    }
    final String fieldName;
    final PropertyInfoIndex pii = pf.getPropertyIndex();
    if (pf.getParentPropertyIndex() != null) {
        fieldName = makePropertyRef(pf.getParentPropertyIndex(), pii);
    } else {
        fieldName = getJname(pii);
    }
    if (f instanceof PresenceFilter) {
        final PresenceFilter prf = (PresenceFilter) f;
        if (prf.getTestPresent()) {
            return makeFilter(pf.getPropertyIndexes(), null, pf.getIntKey(), pf.getStrKey(), OperationType.presence, pf.getNot());
        }
        return makeFilter(pf.getPropertyIndexes(), null, pf.getIntKey(), pf.getStrKey(), OperationType.absence, pf.getNot());
    }
    if (pf instanceof TimeRangeFilter) {
        return makeFilter(pf.getPropertyIndexes(), ((TimeRangeFilter) pf).getEntity(), pf.getIntKey(), pf.getStrKey(), OperationType.timeRange, pf.getNot());
    }
    if (pf instanceof BwCollectionFilter) {
        if (!pf.getNot()) {
            queryLimited = true;
        }
        final BwCalendar col = ((BwCollectionFilter) pf).getEntity();
        return new TermOrTerms(colpathJname, col.getPath(), pf.getNot(), f.getName());
    }
    if (pf instanceof EntityTypeFilter) {
        final EntityTypeFilter etf = (EntityTypeFilter) pf;
        return new TermOrTerms(entityTypeJname, IcalDefs.entityTypeNames[etf.getEntity()], pf.getNot(), f.getName());
    }
    if (pf instanceof EntityTimeRangeFilter) {
        final EntityTimeRangeFilter etrf = (EntityTimeRangeFilter) pf;
        final TimeRange tr = etrf.getEntity();
        String start = null;
        String end = null;
        if (tr.getStart() != null) {
            start = tr.getStart().toString();
        }
        if (tr.getEnd() != null) {
            end = tr.getEnd().toString();
        }
        return addDateRangeFilter(null, etrf.getEntityType(), start, end);
    }
    if (pii == PropertyInfoIndex.COLLECTION) {
        if (!pf.getNot()) {
            queryLimited = true;
        }
    }
    if (pf instanceof ObjectFilter) {
        final OperationType op;
        if (((ObjectFilter) pf).getPrefixMatch()) {
            op = OperationType.prefix;
        } else {
            op = OperationType.compare;
        }
        return makeFilter(pf.getPropertyIndexes(), getValue((ObjectFilter) pf), pf.getIntKey(), pf.getStrKey(), op, pf.getNot());
    }
    return null;
/*
    if (f instanceof TimeRangeFilter) {
      addThisJoin(pi);
      return;
    }

    if (f instanceof BwObjectFilter) {
      addThisJoin(pi);
      return;
    }*/
}
Also used : BooleanFilter(org.bedework.caldav.util.filter.BooleanFilter) PresenceFilter(org.bedework.caldav.util.filter.PresenceFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) BwIcalPropertyInfo(org.bedework.calfacade.ical.BwIcalPropertyInfo) EntityTypeFilter(org.bedework.caldav.util.filter.EntityTypeFilter) BwCollectionFilter(org.bedework.calfacade.filter.BwCollectionFilter) AndFilterBuilder(org.elasticsearch.index.query.AndFilterBuilder) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) OrFilterBuilder(org.elasticsearch.index.query.OrFilterBuilder) RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder) QueryFilterBuilder(org.elasticsearch.index.query.QueryFilterBuilder) NotFilterBuilder(org.elasticsearch.index.query.NotFilterBuilder) NestedFilterBuilder(org.elasticsearch.index.query.NestedFilterBuilder) MatchAllFilterBuilder(org.elasticsearch.index.query.MatchAllFilterBuilder) TermsFilterBuilder(org.elasticsearch.index.query.TermsFilterBuilder) AndFilterBuilder(org.elasticsearch.index.query.AndFilterBuilder) BwHrefFilter(org.bedework.calfacade.filter.BwHrefFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) BwCalendar(org.bedework.calfacade.BwCalendar) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) OrFilterBuilder(org.elasticsearch.index.query.OrFilterBuilder) AndFilter(org.bedework.caldav.util.filter.AndFilter) BwViewFilter(org.bedework.calfacade.filter.BwViewFilter) TimeRange(org.bedework.caldav.util.TimeRange) MatchAllFilterBuilder(org.elasticsearch.index.query.MatchAllFilterBuilder) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) PropertyFilter(org.bedework.caldav.util.filter.PropertyFilter) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)

Example 3 with TimeRange

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

the class Filters method doEntityTimeRange.

/* If both dates are null just return. Otherwise return the appropriate
   * terms with the ids: <br/>
   * fromDate    -- first day
   * toDate      -- last day
   *
   * We build two near identical terms.
   *
   *   (floatFlag=true AND <drtest>) OR
   *   (floatFlag is null AND <drtest-utc>)
   *
   * where drtest uses the local from and to times and
   *       drtest-utc uses the utc from and to.
   *
   */
private void doEntityTimeRange(final EntityTimeRangeFilter trf) {
    TimeRange tr = trf.getEntity();
    if ((tr.getEnd() == null) && (tr.getStart() == null)) {
        return;
    }
    qseg.append("(");
    appendDrtestTerms(true, tr);
    qseg.append(" or ");
    appendDrtestTerms(false, tr);
    qseg.append(")");
}
Also used : TimeRange(org.bedework.caldav.util.TimeRange)

Example 4 with TimeRange

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

the class Filters method doTimeRange.

private void doTimeRange(final TimeRangeFilter trf, final boolean dateTimeField, final String fld, final String subfld) {
    TimeRange tr = trf.getEntity();
    qseg.append('(');
    if (tr.getStart() != null) {
        qseg.append('(');
        qseg.append(fld);
        qseg.append(".");
        qseg.append(subfld);
        if (dateTimeField) {
            qseg.append(".date");
        }
        qseg.append(">=:");
        parTerm();
        qseg.append(')');
    }
    if (tr.getEnd() != null) {
        if (tr.getStart() != null) {
            qseg.append(" and ");
        }
        qseg.append('(');
        qseg.append(fld);
        qseg.append(".");
        qseg.append(subfld);
        if (dateTimeField) {
            qseg.append(".date");
        }
        qseg.append("<:");
        parTerm();
        qseg.append(')');
    }
    qseg.append(')');
}
Also used : TimeRange(org.bedework.caldav.util.TimeRange)

Example 5 with TimeRange

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

the class ESQueryFilter method makeFilter.

private FilterBuilder makeFilter(final PropertyInfoIndex pii, final String path, final Object val, final OperationType opType) throws CalFacadeException {
    final BwIcalPropertyInfoEntry bwPie = BwIcalPropertyInfo.getPinfo(pii);
    switch(opType) {
        case compare:
            if (bwPie.getAnalyzed()) {
                if (val instanceof Collection) {
                    final String[] vals;
                    try {
                        final Collection valsC = (Collection) val;
                        vals = (String[]) (valsC).toArray(new String[valsC.size()]);
                    } catch (final Throwable t) {
                        throw new CalFacadeException(CalFacadeException.filterBadOperator, "Invalid query. Multi match only allowed on strings");
                    }
                    final MultiMatchQueryBuilder mmqb = new MultiMatchQueryBuilder(path, vals);
                    return new QueryFilterBuilder(mmqb);
                }
                return new QueryFilterBuilder(new MatchQueryBuilder(path, val));
            }
            if (val instanceof Collection) {
                final TermsFilterBuilder tfb = FilterBuilders.termsFilter(path, (Collection) val);
                tfb.execution("or");
                return tfb;
            }
            return new TermFilterBuilder(path, val);
        case timeRange:
            final RangeFilterBuilder rfb = FilterBuilders.rangeFilter(path);
            final TimeRange tr = (TimeRange) val;
            if (tr.getEnd() == null) {
                rfb.gte(tr.getStart().toString());
                return rfb;
            }
            if (tr.getStart() == null) {
                rfb.lt(tr.getEnd().toString());
                return rfb;
            }
            rfb.from(tr.getStart().toString());
            rfb.to(tr.getEnd().toString());
            rfb.includeLower(true);
            rfb.includeUpper(false);
            return rfb;
        case absence:
            return FilterBuilders.missingFilter(path);
        case presence:
            return FilterBuilders.existsFilter(path);
        case prefix:
            return FilterBuilders.prefixFilter(path, (String) val);
        default:
            throw new CalFacadeException(CalFacadeException.filterBadOperator, opType.toString());
    }
}
Also used : RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) TermsFilterBuilder(org.elasticsearch.index.query.TermsFilterBuilder) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) QueryFilterBuilder(org.elasticsearch.index.query.QueryFilterBuilder) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) TimeRange(org.bedework.caldav.util.TimeRange) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) Collection(java.util.Collection) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder)

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