Search in sources :

Example 1 with TextParameterType

use of ietf.params.xml.ns.icalendar_2.TextParameterType in project bw-calendar-engine by Bedework.

the class LocationPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final BwEvent ev = ui.getEvent();
        final ChangeTableEntry cte = ui.getCte();
        BwString val = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
        final BwLocation evLoc = ev.getLocation();
        BwString evVal = null;
        if (evLoc != null) {
            evVal = evLoc.getAddress();
        }
        if (ui.isRemove()) {
            if (evVal == null) {
                return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
            }
            val = null;
        } else if (ui.isAdd()) {
            if (evVal != null) {
                return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
            }
        } else if (!ui.isChange()) {
            final ParameterUpdater.UpdateInfo langUpd = UpdaterUtil.findLangUpdate(ui.getParamUpdates());
            if (langUpd == null) {
                return new UpdateResult("No update specified for " + ui.getPropName());
            }
            String lang = val.getLang();
            if (langUpd.isRemove()) {
                lang = null;
            } else if (langUpd.isAdd()) {
                lang = ((TextParameterType) langUpd.getParam()).getText();
            } else if (langUpd.getUpdparam() != null) {
                lang = ((TextParameterType) langUpd.getUpdparam()).getText();
            }
            if (!Util.equalsString(lang, val.getLang())) {
                val = new BwString(lang, val.getValue());
            }
        } else {
            if (!val.equals(evVal)) {
                return new UpdateResult("Values don't match for update to " + ui.getPropName());
            }
            val = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
        }
        if (val == null) {
            cte.setDeleted(ev.getLocation());
            ev.setLocation(null);
        } else if (Util.cmpObjval(val, evVal) != 0) {
            BwLocation loc = ui.getIcalCallback().findLocation(val);
            if (loc == null) {
                loc = BwLocation.makeLocation();
                loc.setAddress(val);
                ui.getIcalCallback().addLocation(loc);
            }
            if (cte.setChanged(evLoc, loc)) {
                ev.setLocation(loc);
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) TextParameterType(ietf.params.xml.ns.icalendar_2.TextParameterType) 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) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) ParameterUpdater(org.bedework.caldav.bwserver.ParameterUpdater) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with TextParameterType

use of ietf.params.xml.ns.icalendar_2.TextParameterType 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

TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)2 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)2 BwEvent (org.bedework.calfacade.BwEvent)2 BwLocation (org.bedework.calfacade.BwLocation)2 BwString (org.bedework.calfacade.BwString)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 BaseParameterType (ietf.params.xml.ns.icalendar_2.BaseParameterType)1 TextParameterType (ietf.params.xml.ns.icalendar_2.TextParameterType)1 ParameterUpdater (org.bedework.caldav.bwserver.ParameterUpdater)1 BwXproperty (org.bedework.calfacade.BwXproperty)1 Xpar (org.bedework.calfacade.BwXproperty.Xpar)1