Search in sources :

Example 21 with ChangeTableEntry

use of org.bedework.calfacade.util.ChangeTableEntry in project bw-calendar-engine by Bedework.

the class CommentPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    final ChangeTableEntry cte = ui.getCte();
    final BwEvent ev = ui.getEvent();
    final Set<BwString> comments = ev.getComments();
    final BwString cstr = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
    if (ui.isAdd()) {
        if (Util.isEmpty(comments)) {
            ev.addComment(cstr);
        } else {
            for (final BwString s : comments) {
                if (s.equals(cstr)) {
                    // Already there
                    return UpdateResult.getOkResult();
                }
            }
            ev.addComment(cstr);
        }
        cte.addAddedValue(cstr);
        return UpdateResult.getOkResult();
    }
    if (ui.isRemove()) {
        if (Util.isEmpty(comments)) {
            // Nothing to remove
            return UpdateResult.getOkResult();
        }
        if (ev.removeComment(cstr)) {
            cte.addRemovedValue(cstr);
        }
        return UpdateResult.getOkResult();
    }
    if (ui.isChange()) {
        // Change a value
        if (Util.isEmpty(comments)) {
            // Nothing to change
            return new UpdateResult("No comment to change");
        }
        for (final BwString s : comments) {
            if (s.equals(cstr)) {
                // Found
                final BwString newcstr = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
                if (s.update(newcstr)) {
                    cte.addChangedValue(s);
                }
                return UpdateResult.getOkResult();
            }
        }
    }
    return UpdateResult.getOkResult();
}
Also used : BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)

Example 22 with ChangeTableEntry

use of org.bedework.calfacade.util.ChangeTableEntry 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 23 with ChangeTableEntry

use of org.bedework.calfacade.util.ChangeTableEntry 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 ChangeTableEntry

use of org.bedework.calfacade.util.ChangeTableEntry 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 ChangeTableEntry

use of org.bedework.calfacade.util.ChangeTableEntry 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)

Aggregations

ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)32 BwEvent (org.bedework.calfacade.BwEvent)26 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)20 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)10 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)10 BwDateTime (org.bedework.calfacade.BwDateTime)7 BwString (org.bedework.calfacade.BwString)7 BwXproperty (org.bedework.calfacade.BwXproperty)7 ChangeTable (org.bedework.calfacade.util.ChangeTable)7 BwAttendee (org.bedework.calfacade.BwAttendee)4 BwCategory (org.bedework.calfacade.BwCategory)4 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)3 TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)3 Holder (javax.xml.ws.Holder)3 BwContact (org.bedework.calfacade.BwContact)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 BwOrganizer (org.bedework.calfacade.BwOrganizer)2