use of org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry 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.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry in project bw-calendar-engine by Bedework.
the class RetrieveList method getRetrieveList.
public static List<BwIcalPropertyInfoEntry> getRetrieveList(final List<String> retrieveList) throws CalFacadeException {
if (retrieveList == null) {
return null;
}
// Convert property names to field names
final List<BwIcalPropertyInfoEntry> retrieveListFields = new ArrayList<>(retrieveList.size() + BwIcalPropertyInfo.requiredPindexes.size());
for (final String pname : retrieveList) {
final PropertyInfoIndex pi;
/* Special case etag for the moment */
if (pname.equals(etagName)) {
pi = PropertyInfoIndex.ETAG;
} else {
pi = PropertyInfoIndex.fromName(pname);
if (pi == null) {
continue;
// throw new CalFacadeException(CalFacadeException.unknownProperty,
// pname);
}
}
final BwIcalPropertyInfoEntry ipie = BwIcalPropertyInfo.getPinfo(pi);
if ((ipie == null) || (ipie.getMultiValued())) {
// warn("Bad property " + pname);
return null;
}
retrieveListFields.add(ipie);
}
for (final PropertyInfoIndex pi : BwIcalPropertyInfo.requiredPindexes) {
retrieveListFields.add(BwIcalPropertyInfo.getPinfo(pi));
}
return retrieveListFields;
}
use of org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry in project bw-calendar-engine by Bedework.
the class SimpleFilterParser method listProps.
private String listProps(final List<PropertyInfo> pis) {
String delim = "";
final StringBuilder sb = new StringBuilder();
for (final PropertyInfo pi : pis) {
sb.append(delim);
final BwIcalPropertyInfoEntry ipie = BwIcalPropertyInfo.getPinfo(pi.pii);
if (ipie == null) {
sb.append("bad-index(").append(pi).append("(");
} else {
sb.append(ipie.getJname());
}
delim = ".";
}
return sb.toString();
}
use of org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry in project bw-calendar-engine by Bedework.
the class ESQueryFilter method makeFilter.
/* TODO we need to provide a chain of filters when we have deep paths,
e.g. entity[key1].entity[key2].value = "something"
*/
public FilterBuilder makeFilter(final List<PropertyInfoIndex> pis, final Object val, final Integer intKey, final String strKey, final OperationType opType, final boolean negate) throws CalFacadeException {
/* Work backwards through the property list building a path.
When the head of the path is a nested type:
If it's the first we found:
generate a match or term query based on the leaf
otherwise:
we already have a nested query to push inside a new one
If the top entry has a keyindex we expect a String or Numeric
key value we generate a bool query with 2 must match terms.
*/
FilterBuilder fb = null;
// current nested level
FilterBuilder nfb = null;
PropertyInfoIndex leafPii = null;
/* See if we need to build a nested query */
final BwIcalPropertyInfoEntry rootPie = BwIcalPropertyInfo.getPinfo(pis.get(0));
final boolean isNested = rootPie.getNested();
for (int plistIndex = pis.size() - 1; plistIndex >= 0; plistIndex--) {
final PropertyInfoIndex pii = pis.get(plistIndex);
if (leafPii == null) {
leafPii = pii;
}
final BwIcalPropertyInfoEntry bwPie = BwIcalPropertyInfo.getPinfo(pii);
if (isNested) {
final FilterBuilder nested;
String path = makePropertyRef(pis, plistIndex);
if (nfb != null) {
if (plistIndex == 0) {
// TODO Temp fix this
path = "event." + path;
}
nested = new NestedFilterBuilder(path, nfb);
} else {
fb = makeFilter(leafPii, makePropertyRef(pis), val, opType);
/* Is the parent indexed? */
final BwIcalPropertyInfoEntry parentPie;
if (plistIndex == 0) {
// No parent
parentPie = null;
} else {
parentPie = BwIcalPropertyInfo.getPinfo(pis.get(plistIndex - 1));
}
if ((parentPie != null) && (parentPie.getKeyindex() != PropertyInfoIndex.UNKNOWN_PROPERTY)) {
final BoolFilterBuilder bfb = new BoolFilterBuilder();
if (fb == null) {
error("No nested query for " + pii);
return null;
}
bfb.must(fb);
final List<PropertyInfoIndex> indexPis = new ArrayList<>();
indexPis.add(pis.get(plistIndex - 1));
indexPis.add(parentPie.getKeyindex());
final String indexPath = makePropertyRef(indexPis);
if (intKey != null) {
bfb.must(new TermFilterBuilder(indexPath, intKey));
} else if (strKey != null) {
bfb.must(new TermFilterBuilder(indexPath, strKey));
} else {
error("Missing key for index for " + pii);
return null;
}
fb = bfb;
}
nested = fb;
}
nfb = nested;
} else if (plistIndex == 0) {
// No nested types found
fb = makeFilter(leafPii, makePropertyRef(pis), val, opType);
}
}
if (nfb != null) {
fb = nfb;
}
if (negate) {
return FilterBuilders.notFilter(fb);
}
return fb;
}
use of org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry in project bw-calendar-engine by Bedework.
the class Filters method makeWhere.
/* Generate a where clause for a query which selects the events for the
* given filter.
*
* @param f Filter element.
*/
private void makeWhere(final FilterBase f) throws CalFacadeException {
if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
boolean itsAnd = (f instanceof AndFilter);
qseg.append('(');
boolean first = true;
for (FilterBase flt : f.getChildren()) {
if (!first) {
if (itsAnd) {
qseg.append(" and ");
} else {
qseg.append(" or ");
}
}
makeWhere(flt);
first = false;
}
qseg.append(")");
}
if (f instanceof BwHrefFilter) {
// Special case this
qseg.append('(');
qseg.append(masterName);
qseg.append(".");
qseg.append("colPath");
qseg.append("=:");
parTerm();
qseg.append(" and ");
qseg.append(masterName);
qseg.append(".");
qseg.append("name");
qseg.append("=:");
parTerm();
qseg.append(')');
queryLimited = true;
} else if (f instanceof PropertyFilter) {
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 multi = pi.getMultiValued();
boolean param = pi.getParam();
if (param) {
BwIcalPropertyInfoEntry parentPi = BwIcalPropertyInfo.getPinfo(pf.getParentPropertyIndex());
fieldName = parentPi.getDbFieldName() + "." + fieldName;
}
if (multi) {
if (f instanceof PresenceFilter) {
PresenceFilter prf = (PresenceFilter) f;
// qseg.append("(size(");
qseg.append("((select count(*) from ");
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
if (pi.getPresenceField() != null) {
qseg.append(".");
qseg.append(pi.getPresenceField());
}
qseg.append(")");
if (prf.getTestPresent()) {
qseg.append(">0)");
} else {
qseg.append("=0)");
}
} else if (pf instanceof TimeRangeFilter) {
String fld = "joined_" + pi.getDbFieldName();
String subfld = "unknown";
if (pi.getPindex() == PropertyInfoIndex.VALARM) {
subfld = "triggerTime";
}
doTimeRange((TimeRangeFilter) pf, false, fld, subfld);
} else if (pf instanceof BwCategoryFilter) {
BwCategory cat = ((BwCategoryFilter) pf).getEntity();
if (cat.unsaved()) {
((BwCategoryFilter) pf).setEntity(cb.getCategory(cat.getUid()));
}
qseg.append("(:");
parTerm();
if (f.getNot()) {
qseg.append(" not");
}
qseg.append(" in elements(");
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
qseg.append("))");
} else if (pf instanceof BwObjectFilter) {
// String fld = "joined_" + pi.getField();
String subfld = "value";
// if (pi.getPindex() == PropertyInfoIndex.CATEGORIES) {
// subfld = "word.value";
// }
doObject(((BwObjectFilter) pf).getEntity(), masterName, fieldName, subfld, true);
} else {
qseg.append("(:");
parTerm();
if (f.getNot()) {
qseg.append(" not");
}
qseg.append(" in elements(");
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
qseg.append("))");
}
// not multi follow
} else if (f instanceof PresenceFilter) {
PresenceFilter prf = (PresenceFilter) f;
qseg.append('(');
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
if (prf.getTestPresent()) {
qseg.append(" is not null");
} else {
qseg.append(" is null");
}
qseg.append(")");
} else if (pf instanceof EntityTimeRangeFilter) {
doEntityTimeRange((EntityTimeRangeFilter) pf);
} else if (pf instanceof TimeRangeFilter) {
doTimeRange((TimeRangeFilter) pf, (pi.getFieldType().getName().equals(BwDateTime.class.getName())), masterName, fieldName);
} else if (pf instanceof BwObjectFilter) {
doObject(((BwObjectFilter) pf).getEntity(), masterName, fieldName, null, false);
} else {
/* We assume we can't handle this one as a query.
*/
throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
}
}
Aggregations