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));
}
}
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;
}*/
}
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(")");
}
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(')');
}
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());
}
}
Aggregations