Search in sources :

Example 51 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class AttendeePropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        ChangeTableEntry cte = ui.getCte();
        BwEvent ev = ui.getEvent();
        Set<BwAttendee> atts = ev.getAttendees();
        AttendeePropType pr = (AttendeePropType) ui.getProp();
        String attUri = ui.getIcalCallback().getCaladdr(ui.getIcalCallback().getPrincipal().getPrincipalRef());
        /* Must have an organizer propery */
        BwOrganizer org = ev.getOrganizer();
        if (org == null) {
            return new UpdateResult("No organizer for attendee update");
        }
        boolean isOrganizer = attUri.equals(org.getOrganizerUri());
        if (!isOrganizer) {
            /* Options are pretty limited here - change partstat only to our own entry
         */
            if (!pr.getCalAddress().equals(attUri)) {
                return new UpdateResult("Cannot update other attendees");
            }
            if (ui.isAdd() || ui.isRemove()) {
                return new UpdateResult("Cannot add or remove attendees");
            }
            if (!ui.isChange()) {
                // Nothing to do
                return UpdateResult.getOkResult();
            }
            // return new UpdateResult("unimplemented - attendee update");
            throw new WebdavException("Unimplemented - attendees update");
        }
        if (ui.isAdd()) {
            if (!Util.isEmpty(atts)) {
                for (BwAttendee att : atts) {
                    if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                        // Already there
                        return UpdateResult.getOkResult();
                    }
                }
            }
            BwAttendee newAtt = makeAttendee(pr);
            ev.addAttendee(newAtt);
            cte.addAddedValue(newAtt);
            return UpdateResult.getOkResult();
        }
        if (ui.isRemove()) {
            if (Util.isEmpty(atts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            BwAttendee remAtt = makeAttendee(pr);
            if (ev.removeAttendee(remAtt)) {
                cte.addRemovedValue(remAtt);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            // Change a value
            if (Util.isEmpty(atts)) {
                // Nothing to change
                return new UpdateResult("No comment to change");
            }
            for (BwAttendee att : atts) {
                if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                    // Found
                    throw new WebdavException("Unimplemented - attendees update");
                // return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 52 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class CategoryPropUpdater method addValue.

@Override
protected void addValue(final BwEvent ev, final BwString val, final UpdateInfo ui) throws WebdavException {
    try {
        BwCategory cat = null;
        if (ev.getNumCategories() == 0) {
            // Nothing to do
            return;
        }
        for (BwCategory evcat : ev.getCategories()) {
            if (evcat.getWord().equals(val)) {
                // Found the category attached to the event.
                cat = evcat;
                break;
            }
        }
        if (cat != null) {
            // Nothing to do
            return;
        }
        cat = ui.getIcalCallback().findCategory(val);
        if (cat == null) {
            cat = BwCategory.makeCategory();
            cat.setWord(val);
            ui.getIcalCallback().addCategory(cat);
        }
        ev.addCategory(cat);
        ui.getCte().addAddedValue(cat);
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwCategory(org.bedework.calfacade.BwCategory) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 53 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class ContactPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final Set<BwContact> contacts = ev.getContacts();
        final BwString nm = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
        final String altrep = UpdaterUtil.getAltrep(ui.getProp());
        if (ui.isAdd()) {
            if (!Util.isEmpty(contacts)) {
                for (final BwContact cnct : contacts) {
                    if (cnct.getCn().equals(nm)) {
                        // Already there
                        return UpdateResult.getOkResult();
                    }
                }
            }
            // Add it
            BwContact cnct = ui.getIcalCallback().findContact(nm);
            if (cnct == null) {
                cnct = BwContact.makeContact();
                cnct.setCn(nm);
                cnct.setLink(altrep);
                ui.getIcalCallback().addContact(cnct);
            }
            ev.addContact(cnct);
            cte.addAddedValue(cnct);
            return UpdateResult.getOkResult();
        }
        if (ui.isRemove()) {
            if (Util.isEmpty(contacts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            for (final BwContact cnct : contacts) {
                if (cnct.getCn().equals(nm)) {
                    if (ev.removeContact(cnct)) {
                        cte.addRemovedValue(cnct);
                    }
                    return UpdateResult.getOkResult();
                }
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            // Change a value
            if (Util.isEmpty(contacts)) {
                // Nothing to change
                return new UpdateResult("No contact to change");
            }
            for (final BwContact evcnct : contacts) {
                if (evcnct.getCn().equals(nm)) {
                    // Found - remove that one and add a new one.
                    final BwString newnm = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
                    BwContact cnct = ui.getIcalCallback().findContact(newnm);
                    if (cnct == null) {
                        cnct = new BwContact();
                        cnct.setCn(newnm);
                        cnct.setLink(altrep);
                        ui.getIcalCallback().addContact(cnct);
                    }
                    if (ev.removeContact(evcnct)) {
                        cte.addRemovedValue(evcnct);
                    }
                    ev.addContact(cnct);
                    cte.addAddedValue(cnct);
                    return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwContact(org.bedework.calfacade.BwContact) BwString(org.bedework.calfacade.BwString) BwString(org.bedework.calfacade.BwString) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 54 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class XbwCategoryPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xcats = ev.getXproperties(BwXproperty.xBedeworkCategories);
        final Set<BwCategory> cats = ev.getCategories();
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = getValue(ui.getProp());
        final BwString cstr = new BwString(lang, xval);
        if (ui.isRemove()) {
            if (Util.isEmpty(xcats)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            for (final BwXproperty xp : xcats) {
                if (!xp.getValue().equals(xval)) {
                    continue;
                }
                // Found
                ev.removeXproperty(xp);
                cte.addRemovedValue(xp);
                /* Do we have a corresponding category */
                for (final BwCategory c : cats) {
                    if (c.getWord().equals(cstr)) {
                        ev.removeCategory(c);
                        cte.addRemovedValue(c);
                        break;
                    }
                }
                return UpdateResult.getOkResult();
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            for (final BwXproperty xp : xcats) {
                if (xp.getValue().equals(xval)) {
                    return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
                }
            }
            /* Add the xprop or a category */
            if (!checkCategory(ui, ev, cats, lang, xval)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            for (final BwXproperty xp : xcats) {
                if (xp.getValue().equals(xval)) {
                    // Found
                    ev.removeXproperty(xp);
                    cte.addRemovedValue(xp);
                    final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
                    final String nxval = getValue(ui.getUpdprop());
                    if (!checkCategory(ui, ev, cats, nlang, nxval)) {
                        final BwXproperty nxp = makeXprop(nlang, nxval);
                        ev.addXproperty(nxp);
                        cte.addValue(nxp);
                    }
                    return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) BwCategory(org.bedework.calfacade.BwCategory) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) BwString(org.bedework.calfacade.BwString) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 55 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException 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)

Aggregations

WebdavException (org.bedework.webdav.servlet.shared.WebdavException)55 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)32 BwEvent (org.bedework.calfacade.BwEvent)20 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)20 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)13 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)10 ArrayList (java.util.ArrayList)9 EventInfo (org.bedework.calfacade.svc.EventInfo)9 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)8 BwDateTime (org.bedework.calfacade.BwDateTime)7 BwString (org.bedework.calfacade.BwString)6 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)4 TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)3 Holder (javax.xml.ws.Holder)3 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)3 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)3 CalPrincipalInfo (org.bedework.caldav.server.sysinterface.CalPrincipalInfo)3 BwCategory (org.bedework.calfacade.BwCategory)3