Search in sources :

Example 21 with UpdateResult

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

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

the class RepeatPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwAlarm alarm = ui.getSubComponent().getAlarm();
    RepeatPropType pr = (RepeatPropType) ui.getProp();
    if (ui.isRemove()) {
        alarm.setRepeat(0);
        flagChange(alarm, ui);
        return UpdateResult.getOkResult();
    }
    if (ui.isAdd()) {
        if (alarm.getRepeat() != 0) {
            return new UpdateResult("Entity already has repeat - cannot add");
        }
        alarm.setRepeat(pr.getInteger().intValue());
        flagChange(alarm, ui);
        return UpdateResult.getOkResult();
    }
    if (!ui.isChange()) {
        return new UpdateResult("No update specified for " + ui.getPropName());
    }
    /* Ensure the old value matches */
    if (pr.getInteger().intValue() != alarm.getRepeat()) {
        return new UpdateResult("Values don't match for update to " + ui.getPropName());
    }
    pr = (RepeatPropType) ui.getUpdprop();
    alarm.setRepeat(pr.getInteger().intValue());
    flagChange(alarm, ui);
    return UpdateResult.getOkResult();
}
Also used : RepeatPropType(ietf.params.xml.ns.icalendar_2.RepeatPropType) BwAlarm(org.bedework.calfacade.BwAlarm) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 23 with UpdateResult

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

the class SequencePropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    SequencePropType pr = (SequencePropType) ui.getProp();
    ChangeTableEntry cte = ui.getCte();
    int val = pr.getInteger().intValue();
    int evVal = ev.getSequence();
    if (ui.isRemove()) {
        if (evVal == 0) {
            return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
        }
        val = 0;
    } else if (ui.isAdd()) {
        if (evVal != 0) {
            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 != evVal) {
            return new UpdateResult("Values don't match for update to " + ui.getPropName());
        }
        val = ((SequencePropType) ui.getUpdprop()).getInteger().intValue();
    }
    if (val < 0) {
        return new UpdateResult("Value for " + ui.getPropName() + " must be >= 0 ");
    }
    if (val != evVal) {
        cte.setChanged(evVal, val);
        ev.setSequence(val);
    }
    return UpdateResult.getOkResult();
}
Also used : SequencePropType(ietf.params.xml.ns.icalendar_2.SequencePropType) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 24 with UpdateResult

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

the class StatusPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    StatusPropType pr = (StatusPropType) ui.getProp();
    ChangeTableEntry cte = ui.getCte();
    String val = pr.getText();
    String evVal = ev.getStatus();
    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 = ((StatusPropType) ui.getUpdprop()).getText();
    }
    if (!Util.equalsString(val, evVal)) {
        cte.setChanged(evVal, val);
        ev.setStatus(val);
    }
    return UpdateResult.getOkResult();
}
Also used : StatusPropType(ietf.params.xml.ns.icalendar_2.StatusPropType) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 25 with UpdateResult

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

the class SummaryPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    BwEvent ev = ui.getEvent();
    if (ui.isRemove()) {
        return new UpdateResult("cannot remove: " + ui.getPropName());
    }
    String val = ((TextPropertyType) ui.getUpdprop()).getText();
    if (ui.getCte().setChanged(ev.getSummary(), val)) {
        ev.setSummary(val);
    }
    return UpdateResult.getOkResult();
}
Also used : BwEvent(org.bedework.calfacade.BwEvent) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) 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