Search in sources :

Example 26 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class TriggerPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwAlarm alarm = ui.getSubComponent().getAlarm();
    TriggerPropType pr = (TriggerPropType) ui.getProp();
    if (ui.isRemove()) {
        return new UpdateResult("Cannot remove " + ui.getPropName());
    }
    if (ui.isAdd()) {
        return new UpdateResult("Cannot add " + ui.getPropName());
    }
    if (!ui.isChange()) {
        return new UpdateResult("No update specified for " + ui.getPropName());
    }
    /* Ensure the old value matches */
    if (pr.getDateTime() != null) {
        if (!alarm.getTriggerDateTime()) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
    } else {
        if (alarm.getTriggerDateTime()) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
    }
    pr = (TriggerPropType) ui.getUpdprop();
    if (pr.getDateTime() != null) {
        alarm.setTrigger(XcalUtil.getIcalFormatDateTime(pr.getDateTime()));
        alarm.setTriggerDateTime(true);
    } else {
        alarm.setTrigger(pr.getDuration());
        RelatedParamType r = (RelatedParamType) XcalUtil.findParam(pr, XcalTags.related);
        alarm.setTriggerStart((r == null) || (r.getText().toUpperCase().equals("START")));
    }
    flagChange(alarm, ui);
    return UpdateResult.getOkResult();
}
Also used : TriggerPropType(ietf.params.xml.ns.icalendar_2.TriggerPropType) BwAlarm(org.bedework.calfacade.BwAlarm) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) RelatedParamType(ietf.params.xml.ns.icalendar_2.RelatedParamType)

Example 27 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class UrlPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    UrlPropType pr = (UrlPropType) ui.getProp();
    ChangeTableEntry cte = ui.getCte();
    String val = pr.getUri();
    String evVal = ev.getLink();
    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()) {
        return new UpdateResult("No update specified for " + ui.getPropName());
    } else {
        if (!val.equals(evVal)) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
        val = ((UrlPropType) ui.getUpdprop()).getUri();
    }
    if (!Util.equalsString(val, evVal)) {
        cte.setChanged(evVal, val);
        ev.setLink(val);
    }
    return UpdateResult.getOkResult();
}
Also used : BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) UrlPropType(ietf.params.xml.ns.icalendar_2.UrlPropType)

Example 28 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult 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 29 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class DurationPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    if (ui.getSubComponent() != null) {
        return alarmDurationPropUpdater.applyUpdate(ui);
    }
    BwEvent ev = ui.getEvent();
    DurationPropType dur = (DurationPropType) ui.getProp();
    DatesState ds = (DatesState) ui.getState(DatesState.stateName);
    if (ds == null) {
        ds = new DatesState(ev);
        ui.saveState(DatesState.stateName, ds);
    }
    ChangeTableEntry cte = ui.getCte();
    if (ui.isRemove()) {
        if (ev.getEndType() != StartEndComponent.endTypeDuration) {
            return new UpdateResult("Entity has no duration - cannot remove");
        }
        cte.setDeleted(ev.getDuration());
        ds.duration = null;
        return UpdateResult.getOkResult();
    }
    if (ui.isAdd()) {
        if (ev.getEndType() == StartEndComponent.endTypeDuration) {
            return new UpdateResult("Entity already has duration - cannot add");
        }
        ds.duration = dur.getDuration();
        cte.setAdded(ds.duration);
        return UpdateResult.getOkResult();
    }
    /* Changing duration */
    if (ev.getEndType() != StartEndComponent.endTypeDuration) {
        return new UpdateResult("Entity has no duration - cannot change");
    }
    dur = (DurationPropType) ui.getUpdprop();
    if (!dur.getDuration().equals(ev.getDuration())) {
        cte.setChanged(ev.getDuration(), dur.getDuration());
    }
    ds.duration = dur.getDuration();
    return UpdateResult.getOkResult();
}
Also used : BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) DurationPropType(ietf.params.xml.ns.icalendar_2.DurationPropType) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 30 with UpdateResult

use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.

the class GeoPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    GeoPropType pr = (GeoPropType) ui.getProp();
    ChangeTableEntry cte = ui.getCte();
    BwGeo val = new BwGeo(new BigDecimal(String.valueOf(pr.getLatitude())), new BigDecimal(String.valueOf(pr.getLongitude())));
    BwGeo evVal = ev.getGeo();
    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()) {
        return new UpdateResult("No update specified for " + ui.getPropName());
    } else {
        if (!val.equals(evVal)) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
        pr = (GeoPropType) ui.getUpdprop();
        val = new BwGeo(new BigDecimal(String.valueOf(pr.getLatitude())), new BigDecimal(String.valueOf(pr.getLongitude())));
    }
    if (Util.cmpObjval(val, evVal) != 0) {
        cte.setChanged(evVal, val);
        ev.setGeo(val);
    }
    return UpdateResult.getOkResult();
}
Also used : BwGeo(org.bedework.calfacade.BwGeo) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) GeoPropType(ietf.params.xml.ns.icalendar_2.GeoPropType) BigDecimal(java.math.BigDecimal) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Aggregations

UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)31 BwEvent (org.bedework.calfacade.BwEvent)23 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)20 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)11 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)11 BwString (org.bedework.calfacade.BwString)6 TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)4 BwAlarm (org.bedework.calfacade.BwAlarm)4 BwDateTime (org.bedework.calfacade.BwDateTime)4 BwXproperty (org.bedework.calfacade.BwXproperty)4 BaseComponentType (ietf.params.xml.ns.icalendar_2.BaseComponentType)2 BasePropertyType (ietf.params.xml.ns.icalendar_2.BasePropertyType)2 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)2 DurationPropType (ietf.params.xml.ns.icalendar_2.DurationPropType)2 BigInteger (java.math.BigInteger)2 QName (javax.xml.namespace.QName)2 Holder (javax.xml.ws.Holder)2 ParameterUpdater (org.bedework.caldav.bwserver.ParameterUpdater)2 BwContact (org.bedework.calfacade.BwContact)2 BwLocation (org.bedework.calfacade.BwLocation)2