use of org.bedework.caldav.util.filter.ObjectFilter in project bw-calendar-engine by Bedework.
the class BwObjectFilter method match.
/* ====================================================================
* matching methods
* ==================================================================== */
@Override
public boolean match(final Object o, final String userHref) throws WebdavException {
ObjectFilter of = getEntity();
Object ent = of.getEntity();
boolean not = of.getNot();
String val = null;
Integer ival = null;
if (ent instanceof BwCalendar) {
val = ((BwCalendar) ent).getPath();
} else if (ent instanceof String) {
val = (String) ent;
} else if (ent instanceof Integer) {
ival = (Integer) ent;
} else {
throw new WebdavException("Unmatchable filter");
}
BwEvent ev = null;
if (o instanceof BwEvent) {
ev = (BwEvent) o;
}
if (of instanceof EntityTypeFilter) {
if (ev == null) {
return false;
}
if (not) {
return ev.getEntityType() != ival;
}
return ev.getEntityType() == ival;
}
PropertyInfoIndex pii = of.getPropertyIndex();
BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pii);
if (pi.getParam()) {
pii = of.getParentPropertyIndex();
}
switch(pii) {
case CLASS:
if (ev.getClassification() == null) {
return false;
}
return stringMatch(ev.getClassification(), val);
case CREATED:
return stringMatch(ev.getCreated(), val);
case DESCRIPTION:
for (BwLongString ls : ev.getDescriptions()) {
if (stringMatch(ls.getValue(), val)) {
return true;
}
}
return false;
case DTSTAMP:
return stringMatch(ev.getDtstamp(), val);
case DTEND:
/* Event only */
case DUE:
/* Todo only */
return matchDateTime(pi, ev.getDtend(), val);
case DTSTART:
return matchDateTime(pi, ev.getDtstart(), val);
case DURATION:
return stringMatch(ev.getDuration(), val);
case GEO:
if (ev.getGeo() == null) {
return false;
}
return stringMatch(ev.getGeo().toString(), val);
case LAST_MODIFIED:
return stringMatch(ev.getLastmod(), val);
case LOCATION:
if (ev.getLocation() == null) {
return false;
}
return stringMatch(ev.getLocation().getAddress().getValue(), val);
case ORGANIZER:
if (ev.getOrganizer() == null) {
return false;
}
return stringMatch(ev.getOrganizer().getOrganizerUri(), val);
case PRIORITY:
if (ev.getPriority() == null) {
return false;
}
return stringMatch(String.valueOf(ev.getPriority()), val);
case RECURRENCE_ID:
if (ev.getRecurrenceId() == null) {
return false;
}
return stringMatch(ev.getRecurrenceId(), val);
case SEQUENCE:
return stringMatch(String.valueOf(ev.getSequence()), val);
case STATUS:
if (ev.getStatus() == null) {
return false;
}
return stringMatch(ev.getStatus(), val);
case SUMMARY:
for (BwString s : ev.getSummaries()) {
if (stringMatch(s.getValue(), val)) {
return true;
}
}
return false;
case UID:
return stringMatch(ev.getUid(), val);
case URL:
if (ev.getLink() == null) {
return false;
}
return stringMatch(ev.getLink(), val);
case TRANSP:
try {
if (ev.getPeruserTransparency(userHref) == null) {
return false;
}
return stringMatch(ev.getPeruserTransparency(userHref), val);
} catch (Throwable t) {
throw new WebdavException(t);
}
case COMPLETED:
if (ev.getCompleted() == null) {
return false;
}
return stringMatch(ev.getCompleted(), val);
case PERCENT_COMPLETE:
if (ev.getPercentComplete() == null) {
return false;
}
return stringMatch(String.valueOf(ev.getPercentComplete()), val);
case ATTACH:
break;
case ATTENDEE:
break;
case CATEGORIES:
for (BwCategory cat : ev.getCategories()) {
if (stringMatch(cat.getWordVal(), val)) {
return true;
}
}
return false;
case COMMENT:
for (BwString s : ev.getComments()) {
if (stringMatch(s.getValue(), val)) {
return true;
}
}
return false;
case CONTACT:
for (BwContact c : ev.getContacts()) {
if (stringMatch(c.getCn().getValue(), val)) {
return true;
}
}
return false;
case EXDATE:
for (BwDateTime dt : ev.getExdates()) {
if (stringMatch(dt.getDtval(), val)) {
return true;
}
}
return false;
case EXRULE:
for (String s : ev.getExrules()) {
if (stringMatch(s, val)) {
return true;
}
}
return false;
case REQUEST_STATUS:
for (BwRequestStatus rs : ev.getRequestStatuses()) {
if (stringMatch(rs.getCode(), val)) {
return true;
}
}
return false;
case RELATED_TO:
if (ev.getRelatedTo() == null) {
return false;
}
return stringMatch(ev.getRelatedTo().getValue(), val);
case RESOURCES:
for (BwString s : ev.getResources()) {
if (stringMatch(s.getValue(), val)) {
return true;
}
}
return false;
case RDATE:
for (BwDateTime dt : ev.getRdates()) {
if (stringMatch(dt.getDtval(), val)) {
return true;
}
}
return false;
case RRULE:
for (String s : ev.getRrules()) {
if (stringMatch(s, val)) {
return true;
}
}
return false;
case FREEBUSY:
break;
case TZID:
break;
case TZNAME:
break;
case TZOFFSETFROM:
break;
case TZOFFSETTO:
break;
case TZURL:
break;
case ACTION:
break;
case REPEAT:
break;
case TRIGGER:
break;
case COLLECTION:
return stringMatch(ev.getColPath(), val);
case CREATOR:
return stringMatch(ev.getCreatorHref(), val);
case OWNER:
return stringMatch(ev.getOwnerHref(), val);
case ENTITY_TYPE:
break;
}
return false;
}
use of org.bedework.caldav.util.filter.ObjectFilter in project bw-calendar-engine by Bedework.
the class FilterBuilder method dump.
private void dump(final FilterBase f, final String curLine) {
if (f instanceof OrFilter) {
debug(curLine + " OR ");
Iterator<FilterBase> it = f.getChildren().iterator();
dumpChildren(it, curLine);
return;
}
if (f instanceof AndFilter) {
debug(curLine + " AND ");
Iterator<FilterBase> it = f.getChildren().iterator();
dumpChildren(it, curLine);
return;
}
if (f instanceof ObjectFilter) {
ObjectFilter of = (ObjectFilter) f;
if (of.getEntity() instanceof BwCalendar) {
final StringBuilder sb = new StringBuilder(curLine);
sb.append(curLine);
sb.append(" cal=");
sb.append(((BwCalendar) of.getEntity()).getPath());
debug(sb.toString());
} else {
debug(curLine + f.toString());
}
} else {
debug(curLine + f.toString());
}
}
use of org.bedework.caldav.util.filter.ObjectFilter in project bw-calendar-engine by Bedework.
the class ESQueryFilter method locationKeyFilter.
/**
* Build a filter for a single location identified by the key with
* the given name and value.
*
* @param name - of key field
* @param val - expected full value
* @return a filter builder
*/
public FilterBuilder locationKeyFilter(final String name, final String val) throws CalFacadeException {
final ObjectFilter<String> kf = new ObjectFilter<>(null, PropertyInfoIndex.LOC_KEYS_FLD, null, name);
kf.setEntity(val);
kf.setExact(true);
kf.setCaseless(false);
final ObjectFilter<String> ef = new ObjectFilter<>(null, PropertyInfoIndex.ENTITY_TYPE, null, null);
ef.setEntity(docTypeLocation);
ef.setExact(true);
ef.setCaseless(false);
final AndFilter and = new AndFilter();
and.addChild(ef);
and.addChild(kf);
return buildFilter(and);
}
use of org.bedework.caldav.util.filter.ObjectFilter 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.filter.ObjectFilter in project bw-calendar-engine by Bedework.
the class Filters method reconstruct.
/* Return null if there are no terms to test for - otherwise return the
* modified filter.
*
* Mostly we replace ObjectFilter with its wrapped form.
*/
private FilterBase reconstruct(final FilterBase f, final boolean forOverrides) throws CalFacadeException {
if (f == null) {
return null;
}
if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
boolean itsAnd = (f instanceof AndFilter);
List<FilterBase> fs = new ArrayList<FilterBase>();
for (FilterBase flt : f.getChildren()) {
FilterBase chf = reconstruct(flt, forOverrides);
if (chf != null) {
fs.add(chf);
}
}
if (fs.size() == 0) {
return null;
}
if (fs.size() == 1) {
return fs.get(0);
}
FilterBase res;
if (itsAnd) {
res = new AndFilter();
} else {
res = new OrFilter();
}
for (FilterBase flt : fs) {
res.addChild(flt);
}
return res;
}
if (!(f instanceof PropertyFilter)) {
throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
PropertyFilter pf = (PropertyFilter) f;
if (pf.getPropertyIndex() == PropertyInfoIndex.HREF) {
// Special case this
return f;
}
if (BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex()) == null) {
throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
}
if (f instanceof PresenceFilter) {
if (!forOverrides) {
return f;
}
if ((pf.getPropertyIndex() == PropertyInfoIndex.COLLECTION) || (pf.getPropertyIndex() == PropertyInfoIndex.DTEND) || (pf.getPropertyIndex() == PropertyInfoIndex.DTSTART) || (pf.getPropertyIndex() == PropertyInfoIndex.DURATION)) {
return f;
}
termsDropped = true;
return null;
} else if (pf instanceof EntityTimeRangeFilter) {
return f;
} else if (pf instanceof TimeRangeFilter) {
if (!forOverrides) {
return f;
}
termsDropped = true;
return null;
} else if (pf instanceof BwCategoryFilter) {
if (!forOverrides) {
return f;
}
termsDropped = true;
return null;
} else if (pf instanceof ObjectFilter) {
if (!forOverrides) {
if (pf instanceof EntityTypeFilter) {
EntityTypeFilter etf = (EntityTypeFilter) pf;
if ((etf.getEntity() == IcalDefs.entityTypeVavailability) || (etf.getEntity() == IcalDefs.entityTypeVavailability)) {
// Ensure we get or exclude both
boolean not = etf.getNot();
FilterBase both;
if (not) {
both = new AndFilter();
} else {
both = new OrFilter();
}
try {
both.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "vavailability", false));
both.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "available", false));
} catch (Throwable t) {
throw new CalFacadeException(t);
}
return both;
}
}
return new BwObjectFilter(null, (ObjectFilter) pf);
}
if (pf.getPropertyIndex() != PropertyInfoIndex.COLLECTION) {
termsDropped = true;
return null;
}
return new BwObjectFilter(null, (ObjectFilter) pf);
} else {
/* We assume we can't handle this one as a query.
*/
throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
}
Aggregations