Search in sources :

Example 46 with WebdavException

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

the class BwUpdates method findSubComponent.

private Component findSubComponent(final EventInfo ei, final BaseComponentType bc) throws WebdavException {
    try {
        BwEvent ev = ei.getEvent();
        int etype = ev.getEntityType();
        if (bc instanceof ValarmType) {
            if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
                return null;
            }
            /* Look for the alarm - we match on the whole component */
            BwAlarm matched = null;
            BwAlarm pattern = Xalarms.toBwAlarm((ValarmType) bc, false);
            if ((pattern == null) || (ev.getNumAlarms() == 0)) {
                return null;
            }
            for (BwAlarm al : ev.getAlarms()) {
                if (al.matches(pattern)) {
                    if (matched != null) {
                        // Multiple matches - bad
                        return null;
                    }
                    matched = al;
                }
            }
            return new PropertyUpdateComponent(ei, matched);
        }
        return null;
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 47 with WebdavException

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

the class BwUpdates method getCompSelector.

private CompSelector getCompSelector(final BaseComponentType selComp) throws WebdavException {
    CompSelector cs = new CompSelector();
    for (JAXBElement<? extends BasePropertyType> prop : selComp.getProperties().getBasePropertyOrTzid()) {
        if (prop.getName().equals(XcalTags.uid)) {
            cs.uid = ((UidPropType) prop.getValue()).getText();
            if ((cs.uid != null) && (cs.recurrenceId != null)) {
                return cs;
            }
            continue;
        }
        if (prop.getName().equals(XcalTags.recurrenceId)) {
            RecurrenceIdPropType rid = (RecurrenceIdPropType) prop.getValue();
            XcalUtil.DtTzid dtTzid = XcalUtil.getDtTzid(rid);
            try {
                cs.recurrenceId = BwDateTime.makeBwDateTime(dtTzid.dateOnly, dtTzid.dt, dtTzid.tzid);
            } catch (CalFacadeException cfe) {
                throw new WebdavException(cfe);
            }
            if ((cs.uid != null) && (cs.recurrenceId != null)) {
                return cs;
            }
            continue;
        }
    }
    return cs;
}
Also used : RecurrenceIdPropType(ietf.params.xml.ns.icalendar_2.RecurrenceIdPropType) XcalUtil(org.bedework.util.calendar.XcalUtil) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 48 with WebdavException

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

the class BwUpdates method addSubComp.

private UpdateResult addSubComp(final EventInfo ei, final ComponentReferenceType sel) throws WebdavException {
    try {
        BwEvent ev = ei.getEvent();
        int etype = ev.getEntityType();
        BaseComponentType bc = sel.getBaseComponent().getValue();
        if (bc instanceof ValarmType) {
            if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
                return new UpdateResult("Invalid entity type for alarm add");
            }
            BwAlarm al = Xalarms.toBwAlarm((ValarmType) bc, false);
            if (al == null) {
                return new UpdateResult("Invalid alarm for add");
            }
            ev.addAlarm(al);
            return UpdateResult.getOkResult();
        }
        return new UpdateResult("Invalid entity type for add");
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 49 with WebdavException

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

the class XbwContactPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xcontacts = ev.getXproperties(BwXproperty.xBedeworkContact);
        final Set<BwContact> contacts = ev.getContacts();
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = ((TextPropertyType) ui.getProp()).getText();
        final BwString cstr = new BwString(lang, xval);
        if (ui.isRemove()) {
            if (Util.isEmpty(xcontacts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            for (final BwXproperty xp : xcontacts) {
                if (!xp.getValue().equals(xval)) {
                    continue;
                }
                // Found
                ev.removeXproperty(xp);
                cte.addRemovedValue(xp);
                /* Do we have a corresponding contact */
                for (final BwContact c : contacts) {
                    if (c.getCn().equals(cstr)) {
                        ev.removeContact(c);
                        cte.addRemovedValue(c);
                        break;
                    }
                }
                return UpdateResult.getOkResult();
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            for (final BwXproperty xp : xcontacts) {
                if (xp.getValue().equals(xval)) {
                    return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
                }
            }
            /* Add the xprop or a contact */
            if (!checkContact(ui, ev, contacts, lang, xval)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addAddedValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            for (final BwXproperty xp : xcontacts) {
                if (xp.getValue().equals(xval)) {
                    // Found
                    ev.removeXproperty(xp);
                    cte.addRemovedValue(xp);
                    final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
                    final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
                    if (!checkContact(ui, ev, contacts, nlang, nxval)) {
                        final BwXproperty nxp = makeXprop(nlang, nxval);
                        ev.addXproperty(nxp);
                        cte.addAddedValue(nxp);
                    }
                    return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) 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) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) BwString(org.bedework.calfacade.BwString) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 50 with WebdavException

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

the class XbwLocPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xlocs = ev.getXproperties(xBedeworkLocation);
        // Should only be one or zero
        final BwXproperty xloc;
        if (Util.isEmpty(xlocs)) {
            xloc = null;
        } else {
            xloc = xlocs.get(0);
        }
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = ((TextPropertyType) ui.getProp()).getText();
        final BaseParameterType keyParam = XcalUtil.findParam(ui.getProp(), XcalTags.xBedeworkLocationKey);
        final String keyName;
        if (keyParam != null) {
            keyName = ((TextParameterType) keyParam).getText();
        } else {
            keyName = null;
        }
        final BwLocation evLoc = ev.getLocation();
        if (ui.isRemove()) {
            if (xlocs == null) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            // TODO - match values?
            ev.removeXproperty(xloc);
            cte.addRemovedValue(xloc);
            if (evLoc != null) {
                ev.setLocation(null);
                cte.addRemovedValue(evLoc);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            if (xloc != null) {
                return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
            }
            if (!checkLocation(ui, ev, lang, xval, null)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addAddedValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            if (xloc == null) {
                return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot change");
            }
            if (CalFacadeUtil.cmpObjval(xval, xloc.getValue()) != 0) {
                return new UpdateResult("Values don't match for update to " + ui.getPropName());
            }
            ev.removeXproperty(xloc);
            cte.addRemovedValue(xloc);
            final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
            final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
            if (!checkLocation(ui, ev, nlang, nxval, keyName)) {
                final BwXproperty nxp = makeXprop(nlang, nxval);
                if (keyName != null) {
                    nxp.getParameters().add(new Xpar(XcalTags.xBedeworkLocationKey.getLocalPart(), keyName));
                }
                ev.addXproperty(nxp);
                cte.addAddedValue(nxp);
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : Xpar(org.bedework.calfacade.BwXproperty.Xpar) BaseParameterType(ietf.params.xml.ns.icalendar_2.BaseParameterType) BwLocation(org.bedework.calfacade.BwLocation) BwXproperty(org.bedework.calfacade.BwXproperty) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

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