Search in sources :

Example 11 with BwIcalPropertyInfoEntry

use of org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry in project bw-calendar-engine by Bedework.

the class Filters method match.

private boolean match(final FilterBase f, final BwEvent ev, final String userHref) throws CalFacadeException {
    if (f == null) {
        return true;
    }
    if (debug) {
        debug("match " + f);
    }
    if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
        boolean itsAnd = (f instanceof AndFilter);
        for (FilterBase flt : f.getChildren()) {
            if (match(flt, ev, userHref)) {
                if (!itsAnd) {
                    // Success for OR
                    if (debug) {
                        debug("match true");
                    }
                    return true;
                }
            } else if (itsAnd) {
                debug("match true");
                return false;
            }
        }
        // For AND all matched, for OR nothing matched
        debug("match " + itsAnd);
        return itsAnd;
    }
    if (f instanceof EntityTimeRangeFilter) {
        // Matched in db query
        return true;
    }
    if (!(f instanceof PropertyFilter)) {
        /* We assume we can't handle this one as a query.
       */
        throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
    }
    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 param = pi.getParam();
    if (param) {
        BwIcalPropertyInfoEntry parentPi = BwIcalPropertyInfo.getPinfo(pf.getParentPropertyIndex());
        fieldName = parentPi.getDbFieldName() + "." + fieldName;
    }
    try {
        if (pf instanceof BwCategoryFilter) {
            return traceMatch(pf.match(ev, userHref));
        }
        if (f instanceof PresenceFilter) {
            return traceMatch(matchPresence(pf.getPropertyIndex(), ev, userHref));
        }
        if (pf instanceof TimeRangeFilter) {
            return traceMatch(match((TimeRangeFilter) pf, ev));
        }
        if (pf instanceof BwObjectFilter) {
            return traceMatch(pf.match(ev, userHref));
        }
    } catch (WebdavException wde) {
        throw new CalFacadeException(wde);
    }
    throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
Also used : PresenceFilter(org.bedework.caldav.util.filter.PresenceFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCategoryFilter(org.bedework.calfacade.filter.BwCategoryFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) AndFilter(org.bedework.caldav.util.filter.AndFilter) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) PropertyFilter(org.bedework.caldav.util.filter.PropertyFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter)

Example 12 with BwIcalPropertyInfoEntry

use of org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry in project bw-calendar-engine by Bedework.

the class Events method checkChanges.

@SuppressWarnings("unchecked")
private boolean checkChanges(final EventInfo ei, final boolean organizerSchedulingObject, final boolean attendeeSchedulingObject) throws CalFacadeException {
    final UpdateResult updResult = ei.getUpdResult();
    if (ei.getChangeset(getPrincipalHref()).isEmpty()) {
        // Forced update?
        updResult.hasChanged = true;
        if (attendeeSchedulingObject) {
            // Attendee replying?
            /* XXX We should really check to see if the value changed here -
         */
            updResult.reply = true;
        }
        return true;
    }
    if (debug) {
        ei.getChangeset(getPrincipalHref()).dumpEntries();
    }
    final ChangeTable ct = ei.getChangeset(getPrincipalHref());
    final Collection<ChangeTableEntry> ctes = ct.getEntries();
    updResult.sequenceChange = ct.getSequenceChangeNeeded();
    for (final ChangeTableEntry cte : ctes) {
        if (!cte.getChanged()) {
            continue;
        }
        updResult.hasChanged = true;
        final PropertyInfoIndex pi = cte.getIndex();
        if (!organizerSchedulingObject && pi.equals(PropertyInfoIndex.ORGANIZER)) {
            final BwOrganizer oldOrg = (BwOrganizer) cte.getOldVal();
            final BwOrganizer newOrg = (BwOrganizer) cte.getNewVal();
            if ((oldOrg == null) || (newOrg == null) || !oldOrg.getOrganizerUri().equals(newOrg.getOrganizerUri())) {
                // Never valid
                throw new CalFacadeForbidden(CaldavTags.attendeeAllowed, "Cannot change organizer");
            }
        }
        if (pi.equals(PropertyInfoIndex.ATTENDEE) || pi.equals(PropertyInfoIndex.VOTER)) {
            updResult.addedAttendees = cte.getAddedValues();
            updResult.deletedAttendees = cte.getRemovedValues();
            if (attendeeSchedulingObject) {
                // Attendee replying?
                /* XXX We should really check to see if the value changed here -
           */
                updResult.reply = true;
            } else {
                if (!Util.isEmpty(updResult.deletedAttendees)) {
                    // Bump sequence as we are sending out cancels
                    updResult.sequenceChange = true;
                }
            }
        }
        if (pi.equals(PropertyInfoIndex.POLL_WINNER)) {
            if (!attendeeSchedulingObject) {
                // Attendee replying?
                /* XXX We should really check to see if the value changed here -
           */
                updResult.pollWinner = ei.getEvent().getPollWinner();
            }
        }
        if (pi.equals(PropertyInfoIndex.POLL_ITEM)) {
            if (attendeeSchedulingObject) {
                // Attendee replying?
                /* XXX We should really check to see if the value changed here -
           */
                updResult.reply = true;
            }
        }
        if (organizerSchedulingObject) {
            final BwIcalPropertyInfoEntry pie = BwIcalPropertyInfo.getPinfo(cte.getIndex());
            if (pie.getReschedule()) {
                updResult.doReschedule = true;
            }
        }
    }
    return updResult.hasChanged;
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) ChangeTable(org.bedework.calfacade.util.ChangeTable) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Aggregations

BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)12 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)5 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 AndFilter (org.bedework.caldav.util.filter.AndFilter)3 EntityTimeRangeFilter (org.bedework.caldav.util.filter.EntityTimeRangeFilter)3 FilterBase (org.bedework.caldav.util.filter.FilterBase)3 OrFilter (org.bedework.caldav.util.filter.OrFilter)3 PresenceFilter (org.bedework.caldav.util.filter.PresenceFilter)3 PropertyFilter (org.bedework.caldav.util.filter.PropertyFilter)3 TimeRangeFilter (org.bedework.caldav.util.filter.TimeRangeFilter)3 BwCategory (org.bedework.calfacade.BwCategory)3 BwDateTime (org.bedework.calfacade.BwDateTime)3 BwObjectFilter (org.bedework.calfacade.filter.BwObjectFilter)3 ArrayList (java.util.ArrayList)2 BwContact (org.bedework.calfacade.BwContact)2 BwEvent (org.bedework.calfacade.BwEvent)2 BwString (org.bedework.calfacade.BwString)2 BwCategoryFilter (org.bedework.calfacade.filter.BwCategoryFilter)2 BwHrefFilter (org.bedework.calfacade.filter.BwHrefFilter)2 ChangeTable (org.bedework.calfacade.util.ChangeTable)2