use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex in project bw-calendar-engine by Bedework.
the class ChangeTable method processChanges.
/**
* Go through the change table entries removing fields that were not present
* in the incoming data. This method is for the traditional update by
* replacement approach. Do NOT call for the patch or selective update
* approach as found in e.g. SOAP.
*
* @param ev
* @param update
* @throws CalFacadeException
*/
@SuppressWarnings("unchecked")
public void processChanges(final BwEvent ev, final boolean update) throws CalFacadeException {
HashMap<PropertyInfoIndex, ChangeTableEntry> fullmap = new HashMap<>(map);
for (PropertyInfoIndex pii : PropertyInfoIndex.values()) {
ChangeTableEntry ent = fullmap.get(pii);
if (ent == null) {
ent = new ChangeTableEntry(this, pii);
fullmap.put(pii, ent);
}
}
/* Single valued first */
for (ChangeTableEntry ent : fullmap.values()) {
if (ent.getPresent()) {
continue;
}
switch(ev.getEntityType()) {
case IcalDefs.entityTypeEvent:
if (!ent.getEventProperty()) {
continue;
}
break;
case IcalDefs.entityTypeTodo:
if (!ent.getTodoProperty()) {
continue;
}
break;
case IcalDefs.entityTypeFreeAndBusy:
if (!ent.getFreebusyProperty()) {
continue;
}
break;
case IcalDefs.entityTypeVavailability:
// XXX Fake this one for the moment
if (!ent.getEventProperty()) {
continue;
}
break;
case IcalDefs.entityTypeAvailable:
// XXX Fake this one for the moment
if (!ent.getEventProperty()) {
continue;
}
break;
case IcalDefs.entityTypeVpoll:
if (!ent.getVpollProperty()) {
continue;
}
break;
default:
warn("Unsupported entity type: " + ev.getEntityType());
continue;
}
switch(ent.getIndex()) {
case ACCEPT_RESPONSE:
if (ev.getPollAcceptResponse() != null) {
ent.setDeleted(ev.getPollAcceptResponse());
if (update) {
ev.setPollAcceptResponse(null);
}
}
break;
case CLASS:
if (ev.getClassification() != null) {
ent.setDeleted(ev.getClassification());
if (update) {
ev.setClassification(null);
}
}
break;
case COMPLETED:
if (ev.getCompleted() != null) {
ent.setDeleted(ev.getCompleted());
if (update) {
ev.setCompleted(null);
}
}
break;
case CREATED:
// Leave
break;
case DESCRIPTION:
if (ev.getDescription() != null) {
ent.setDeleted(ev.getDescription());
if (update) {
ev.setDescription(null);
}
}
break;
case DTSTAMP:
// Leave
break;
case DTSTART:
// XXX Check this is handled elsewhere
break;
case DURATION:
// XXX Check this is handled elsewhere
break;
case GEO:
if (ev.getGeo() != null) {
ent.setDeleted(ev.getGeo());
if (update) {
ev.setGeo(null);
}
}
break;
case LAST_MODIFIED:
// Leave
break;
case LOCATION:
if (ev.getLocation() != null) {
ent.setDeleted(ev.getLocation());
if (update) {
ev.setLocation(null);
}
}
break;
case ORGANIZER:
if (ev.getOrganizer() != null) {
ent.setDeleted(ev.getOrganizer());
if (update) {
ev.setOrganizer(null);
}
}
break;
case PERCENT_COMPLETE:
if (ev.getPercentComplete() != null) {
ent.setDeleted(ev.getPercentComplete());
if (update) {
ev.setPercentComplete(null);
}
}
break;
case POLL_ITEM_ID:
if (ev.getPollItemId() != null) {
ent.setDeleted(ev.getPollItemId());
if (update) {
ev.setPollItemId(null);
}
}
break;
case POLL_MODE:
if (ev.getPollMode() != null) {
ent.setDeleted(ev.getPollMode());
if (update) {
ev.setPollMode(null);
}
}
break;
case POLL_PROPERTIES:
if (ev.getPollProperties() != null) {
ent.setDeleted(ev.getPollProperties());
if (update) {
ev.setPollProperties(null);
}
}
break;
case PRIORITY:
if (ev.getPriority() != null) {
ent.setDeleted(ev.getPriority());
if (update) {
ev.setPriority(null);
}
}
break;
case RECURRENCE_ID:
// XXX Handled elsewhere?
break;
case RELATED_TO:
if (ev.getRelatedTo() != null) {
ent.setDeleted(ev.getRelatedTo());
if (update) {
ev.setRelatedTo(null);
}
}
break;
case SEQUENCE:
// XXX Handled elsewhere?
break;
case STATUS:
if (ev.getStatus() != null) {
ent.setDeleted(ev.getStatus());
if (update) {
ev.setStatus(null);
}
}
break;
case SUMMARY:
if (ev.getSummary() != null) {
ent.setDeleted(ev.getSummary());
if (update) {
ev.setSummary(null);
}
}
break;
case UID:
// Leave
break;
case URL:
if (ev.getLink() != null) {
ent.setDeleted(ev.getLink());
if (update) {
ev.setLink(null);
}
}
break;
case DTEND:
// XXX Handled elsewhere?
break;
case TRANSP:
/*
if (ev.getPeruserTransparency(userHref) != null) {
ent.setDeleted(ev.getPeruserTransparency(userHref));
if (update) {
ev.setPeruserTransparency(userHref, null);
}
}
*/
if (ev.getTransparency() != null) {
ent.setDeleted(ev.getTransparency());
if (update) {
ev.setTransparency(null);
}
}
break;
case ACTION:
break;
case BUSYTYPE:
break;
case COLLECTION:
break;
case COST:
break;
case DELETED:
break;
case DUE:
break;
case END_TYPE:
break;
case FREEBUSY:
break;
case HREF:
break;
case LANG:
break;
case REPEAT:
break;
case TRIGGER:
break;
case UNKNOWN_PROPERTY:
break;
case VALARM:
break;
case XBEDEWORK_COST:
break;
// following are multi
case ATTACH:
break;
case ATTENDEE:
break;
case CATEGORIES:
break;
case COMMENT:
break;
case CONTACT:
break;
case EXDATE:
break;
case EXRULE:
break;
case RDATE:
break;
case REQUEST_STATUS:
break;
case RESOURCES:
break;
case RRULE:
break;
case VOTER:
break;
case XPROP:
break;
// following are Timezones - ignored
case TZID:
break;
case TZIDPAR:
break;
case TZNAME:
break;
case TZOFFSETFROM:
break;
case TZOFFSETTO:
break;
case TZURL:
break;
// following are ignored
case CALSCALE:
break;
case CREATOR:
break;
case CTAG:
break;
case ENTITY_TYPE:
break;
case ETAG:
break;
case METHOD:
break;
case OWNER:
break;
case PRODID:
break;
case VERSION:
break;
}
}
for (ChangeTableEntry ent : fullmap.values()) {
/* See if any change was significant */
if (!schedulingInsignificantProperties.contains(ent.getIndex())) {
if (ent.getAdded() || ent.getChanged() || ent.getDeleted()) {
significantPropertyChanged = true;
}
}
/* These can be present but we still need to delete members. */
if (!ent.getEventProperty() && !ent.getVpollProperty()) {
continue;
}
Collection originalVals;
switch(ent.getIndex()) {
case ATTACH:
originalVals = ev.getAttachments();
if (checkMulti(ent, originalVals, update)) {
ev.setAttachments((Set) ent.getAddedValues());
}
break;
case ATTENDEE:
if (ev.getEntityType() == IcalDefs.entityTypeVpoll) {
// Skip so as not to disturb the attendees property - we deal with it as VOTER
break;
}
originalVals = ev.getAttendees();
/* diff(ent, originalVals);
if (ev instanceof BwEventProxy) {
// It's an override - we have to clone all the set if anything changes
if (ent.changed && update) {
Set<BwAttendee> orig = new TreeSet<BwAttendee>();
for (Object o: originalVals) {
BwAttendee att = (BwAttendee)o;
orig.add((BwAttendee)att.clone());
}
checkMulti(ent, orig, update);
ev.setAttendees(orig);
}
} else if (checkMulti(ent, originalVals, update)) {
ev.setAttendees((Set)ent.getAddedValues());
}*/
if (checkMulti(ent, originalVals, update)) {
ev.setAttendees((Set) ent.getAddedValues());
}
break;
case CATEGORIES:
originalVals = ev.getCategories();
if (checkMulti(ent, originalVals, update)) {
ev.setCategories((Set) ent.getAddedValues());
}
break;
case COMMENT:
originalVals = ev.getComments();
if (checkMulti(ent, originalVals, update)) {
ev.setComments((Set) ent.getAddedValues());
}
break;
case CONTACT:
originalVals = ev.getContacts();
if (checkMulti(ent, originalVals, update)) {
ev.setContacts((Set) ent.getAddedValues());
}
break;
case REQUEST_STATUS:
originalVals = ev.getRequestStatuses();
if (checkMulti(ent, originalVals, update)) {
ev.setRequestStatuses((Set) ent.getAddedValues());
}
break;
case RELATED_TO:
break;
case RESOURCES:
originalVals = ev.getResources();
if (checkMulti(ent, originalVals, update)) {
ev.setResources((Set) ent.getAddedValues());
}
break;
case VALARM:
originalVals = ev.getAlarms();
if (checkMulti(ent, originalVals, update)) {
ev.setAlarms((Set) ent.getAddedValues());
}
break;
case XPROP:
originalVals = ev.getXproperties();
if (checkMulti(ent, originalVals, update)) {
ev.setXproperties((List) ent.getAddedValues());
}
break;
case EXDATE:
if (ev.getRecurrenceId() == null) {
originalVals = ev.getExdates();
if (checkMulti(ent, originalVals, update)) {
ev.setExdates((Set) ent.getAddedValues());
}
}
break;
case EXRULE:
if (ev.getRecurrenceId() == null) {
originalVals = ev.getExrules();
if (checkMulti(ent, originalVals, update)) {
ev.setExrules((Set) ent.getAddedValues());
}
}
break;
case RDATE:
if (ev.getRecurrenceId() == null) {
originalVals = ev.getRdates();
if (checkMulti(ent, originalVals, update)) {
ev.setRdates((Set) ent.getAddedValues());
}
}
break;
case RRULE:
if (ev.getRecurrenceId() == null) {
originalVals = ev.getRrules();
if (checkMulti(ent, originalVals, update)) {
ev.setRrules((Set) ent.getAddedValues());
}
}
break;
case VOTER:
if (ev.getEntityType() != IcalDefs.entityTypeVpoll) {
// Skip so as not to disturb the attendees property
break;
}
originalVals = ev.getAttendees();
if (checkMulti(ent, originalVals, update)) {
ev.setAttendees((Set) ent.getAddedValues());
}
break;
case ACCEPT_RESPONSE:
break;
case ACTION:
break;
case BUSYTYPE:
break;
case CALSCALE:
break;
case CLASS:
break;
case COLLECTION:
break;
case COMPLETED:
break;
case COST:
break;
case CREATED:
break;
case CREATOR:
break;
case CTAG:
break;
case DELETED:
break;
case DESCRIPTION:
break;
case DTEND:
break;
case DTSTAMP:
break;
case DTSTART:
break;
case DUE:
break;
case DURATION:
break;
case END_TYPE:
break;
case ENTITY_TYPE:
break;
case ETAG:
break;
case FREEBUSY:
break;
case GEO:
break;
case HREF:
break;
case LANG:
break;
case LAST_MODIFIED:
break;
case LOCATION:
break;
case METHOD:
break;
case ORGANIZER:
break;
case OWNER:
break;
case PERCENT_COMPLETE:
break;
case POLL_ITEM_ID:
break;
case POLL_MODE:
break;
case POLL_PROPERTIES:
break;
case PRIORITY:
break;
case PRODID:
break;
case RECURRENCE_ID:
break;
case REPEAT:
break;
case SEQUENCE:
break;
case STATUS:
break;
case SUMMARY:
break;
case TRANSP:
break;
case TRIGGER:
break;
case TZID:
break;
case TZIDPAR:
break;
case TZNAME:
break;
case TZOFFSETFROM:
break;
case TZOFFSETTO:
break;
case TZURL:
break;
case UID:
break;
case UNKNOWN_PROPERTY:
break;
case URL:
break;
case VERSION:
break;
case XBEDEWORK_COST:
break;
default:
break;
}
}
/* Added any deleted items to the change table. */
for (ChangeTableEntry ent : fullmap.values()) {
if (ent.getDeleted()) {
ev.getChangeset(null).changed(ent.getIndex(), ent.getOldVal(), null);
}
}
}
use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex in project bw-calendar-engine by Bedework.
the class BwUpdates method validateDates.
private UpdateResult validateDates(final EventInfo ei) throws WebdavException {
DatesState ds = (DatesState) state.get(DatesState.stateName);
if (ds == null) {
return UpdateResult.getOkResult();
}
BwEvent ev = ei.getEvent();
boolean task = ev.getEntityType() == IcalDefs.entityTypeTodo;
PropertyInfoIndex endPi;
ChangeTable chg = ei.getChangeset(userHref);
if (task) {
endPi = PropertyInfoIndex.DUE;
} else {
endPi = PropertyInfoIndex.DTEND;
}
try {
boolean scheduleReply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
if (ds.start == null) {
if (!scheduleReply && !task) {
return new UpdateResult("org.bedework.error.nostartdate");
}
/* A todo can have no date and time. set start to now, end to
* many years from now and the noStart flag.
*
* Such an entry has to appear only on the current day.
*/
if (ds.end != null) {
ds.start = ds.end;
} else {
Date now = new Date(new java.util.Date().getTime());
DtStart dtStart = new DtStart(now);
dtStart.getParameters().add(Value.DATE);
ds.start = BwDateTime.makeBwDateTime(dtStart);
}
if (!ev.getNoStart() || !CalFacadeUtil.eqObjval(ev.getDtstart(), ds.start)) {
chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), null);
ev.setDtstart(ds.start);
ev.setNoStart(true);
}
} else if (ev.getNoStart() || !ds.start.equals(ev.getDtstart())) {
chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), ds.start);
ev.setNoStart(false);
ev.setDtstart(ds.start);
}
char endType = StartEndComponent.endTypeNone;
if (ds.end != null) {
if ((ev.getEndType() != StartEndComponent.endTypeDate) || !CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
chg.changed(endPi, ev.getDtend(), ds.end);
endType = StartEndComponent.endTypeDate;
ev.setDtend(ds.end);
}
} else if (scheduleReply || task) {
// about 10 years
Dur years = new Dur(520);
Date now = new Date(new java.util.Date().getTime());
DtEnd dtEnd = new DtEnd(new Date(years.getTime(now)));
dtEnd.getParameters().add(Value.DATE);
ds.end = BwDateTime.makeBwDateTime(dtEnd);
if (!CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
chg.changed(endPi, ev.getDtend(), ds.end);
ev.setDtend(ds.end);
}
}
/**
* If we were given a duration store it in the event and calculate
* an end to the event - which we should not have been given.
*/
if (ds.duration != null) {
if (endType != StartEndComponent.endTypeNone) {
if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
// Apple is sending both - duration indicates the minimum
// freebusy duration. Ignore for now.
} else {
return new UpdateResult(CalFacadeException.endAndDuration);
}
}
endType = StartEndComponent.endTypeDuration;
if (!ds.duration.equals(ev.getDuration())) {
chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), ds.duration);
ev.setDuration(ds.duration);
}
ev.setDtend(BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), ev.getDtstart().getDateType(), new Dur(ds.duration)));
} else if (!scheduleReply && (endType == StartEndComponent.endTypeNone) && !task) {
/* No duration and no end specified.
* Set the end values to the start values + 1 for dates
*/
boolean dateOnly = ev.getDtstart().getDateType();
Dur dur;
if (dateOnly) {
// 1 day
dur = new Dur(1, 0, 0, 0);
} else {
// No duration
dur = new Dur(0, 0, 0, 0);
}
BwDateTime bwDtEnd = BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), dateOnly, dur);
if (!CalFacadeUtil.eqObjval(ev.getDtend(), bwDtEnd)) {
chg.changed(endPi, ev.getDtend(), bwDtEnd);
ev.setDtend(bwDtEnd);
}
}
if ((endType != StartEndComponent.endTypeDuration) && (ev.getDtstart() != null) && (ev.getDtend() != null)) {
// Calculate a duration
String durVal = BwDateTime.makeDuration(ev.getDtstart(), ev.getDtend()).toString();
if (!durVal.equals(ev.getDuration())) {
chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), durVal);
ev.setDuration(durVal);
}
}
ev.setEndType(endType);
return UpdateResult.getOkResult();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex in project bw-calendar-engine by Bedework.
the class IcalPropertyHandler method closePinfo.
/**
* @param env
* @return boolean true for ok
*/
public boolean closePinfo(final ProcessingEnvironment env) {
try {
if ((pinfos == null) || pinfos.isEmpty()) {
return true;
}
startPinfo(env);
SortedMap<String, PropertyInfoIndex> pixNames = new TreeMap<>();
for (PropertyInfoIndex ipe : PropertyInfoIndex.values()) {
pixNames.put(ipe.name(), ipe);
}
/* Now in sort order... */
List<PropertyInfoIndex> sorted = new ArrayList<>(pixNames.values());
for (PropertyInfoIndex ipe : sorted) {
MergedIcalProperty mip = pinfos.get(ipe);
if (mip == null) {
continue;
}
emit(env, mip);
pixNames.remove(ipe.name());
}
pinfoOut.println(" }");
pinfoOut.println();
pinfoOut.println(" /** An array of property indexes required for valid events */");
pinfoOut.println(" public static Set<PropertyInfoIndex> requiredPindexes = ");
pinfoOut.println(" new TreeSet<>();");
pinfoOut.println();
pinfoOut.println(" static {");
for (PropertyInfoIndex ipe : sorted) {
MergedIcalProperty mip = pinfos.get(ipe);
if ((mip == null) || !mip.required) {
continue;
}
pinfoOut.println(" requiredPindexes.add(PropertyInfoIndex." + ipe.name() + ");");
}
pinfoOut.println(" }");
pinfoOut.println();
pinfoOut.println(" /** An array of property indexes required for valid annotations */");
pinfoOut.println(" public static Set<PropertyInfoIndex> requiredAnnotationPindexes = ");
pinfoOut.println(" new TreeSet<>();");
pinfoOut.println();
pinfoOut.println(" static {");
for (PropertyInfoIndex ipe : sorted) {
MergedIcalProperty mip = pinfos.get(ipe);
if ((mip == null) || !mip.annotationRequired) {
continue;
}
pinfoOut.println(" requiredAnnotationPindexes.add(PropertyInfoIndex." + ipe.name() + ");");
}
pinfoOut.println(" }");
pinfoOut.println();
pinfoOut.println(" /** An array of unreferenced property indexes */");
pinfoOut.println(" PropertyInfoIndex[] unreferencedPindexes = {");
for (PropertyInfoIndex ipe : pixNames.values()) {
pinfoOut.println(" PropertyInfoIndex." + ipe.name() + ",");
}
pinfoOut.println(" };");
pinfoOut.println();
pinfoOut.println(" /** Get entry given an index");
pinfoOut.println(" * @param pindex");
pinfoOut.println(" * @return BwIcalPropertyInfoEntry");
pinfoOut.println(" */");
pinfoOut.println(" public static BwIcalPropertyInfoEntry getPinfo(PropertyInfoIndex pindex) {");
pinfoOut.println(" return info.get(pindex);");
pinfoOut.println(" }");
pinfoOut.println();
pinfoOut.println(" private static void addPinfo(BwIcalPropertyInfoEntry pinfo) {");
pinfoOut.println(" BwIcalPropertyInfoEntry pinfo1 = info.put(pinfo.getPindex(), pinfo);");
pinfoOut.println(" if (pinfo1 != null) {");
pinfoOut.println(" throw new RuntimeException(\"Duplicate index \" + pinfo.getPindex());");
pinfoOut.println(" }");
// propertyInfoByPname.put(pinfo.name, pinfo);
pinfoOut.println(" }");
pinfoOut.println("}");
pinfoOut.close();
pinfoOut = null;
return true;
} catch (Throwable t) {
Messager msg = env.getMessager();
t.printStackTrace();
msg.printMessage(Kind.ERROR, "Exception: " + t.getMessage());
return false;
}
}
use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex 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.util.calendar.PropertyIndex.PropertyInfoIndex 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;
}*/
}
Aggregations