Search in sources :

Example 91 with BwEvent

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

the class XbwWrapperPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    final ChangeTableEntry cte = ui.getCte();
    final BwEvent ev = ui.getEvent();
    /* Create an x-property from the selector */
    // TODO - do parameters properly
    final XBedeworkWrapperPropType wrapper = (XBedeworkWrapperPropType) ui.getProp();
    final BwXproperty theProp = new BwXproperty(UpdaterUtil.getWrapperName(wrapper), null, wrapper.getText());
    if (ui.isRemove()) {
        ev.removeXproperty(theProp);
        cte.addRemovedValue(theProp);
        return UpdateResult.getOkResult();
    }
    if (ui.isAdd()) {
        ev.addXproperty(theProp);
        cte.addValue(theProp);
        return UpdateResult.getOkResult();
    }
    if (ui.isChange()) {
        ev.removeXproperty(theProp);
        cte.addRemovedValue(theProp);
        final BwXproperty newProp = new BwXproperty(UpdaterUtil.getWrapperName(wrapper), null, ((XBedeworkWrapperPropType) ui.getUpdprop()).getText());
        ev.addXproperty(newProp);
        cte.addValue(newProp);
        return UpdateResult.getOkResult();
    }
    return UpdateResult.getOkResult();
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) XBedeworkWrapperPropType(ietf.params.xml.ns.icalendar_2.XBedeworkWrapperPropType) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry)

Example 92 with BwEvent

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

the class AttendeePropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        ChangeTableEntry cte = ui.getCte();
        BwEvent ev = ui.getEvent();
        Set<BwAttendee> atts = ev.getAttendees();
        AttendeePropType pr = (AttendeePropType) ui.getProp();
        String attUri = ui.getIcalCallback().getCaladdr(ui.getIcalCallback().getPrincipal().getPrincipalRef());
        /* Must have an organizer propery */
        BwOrganizer org = ev.getOrganizer();
        if (org == null) {
            return new UpdateResult("No organizer for attendee update");
        }
        boolean isOrganizer = attUri.equals(org.getOrganizerUri());
        if (!isOrganizer) {
            /* Options are pretty limited here - change partstat only to our own entry
         */
            if (!pr.getCalAddress().equals(attUri)) {
                return new UpdateResult("Cannot update other attendees");
            }
            if (ui.isAdd() || ui.isRemove()) {
                return new UpdateResult("Cannot add or remove attendees");
            }
            if (!ui.isChange()) {
                // Nothing to do
                return UpdateResult.getOkResult();
            }
            // return new UpdateResult("unimplemented - attendee update");
            throw new WebdavException("Unimplemented - attendees update");
        }
        if (ui.isAdd()) {
            if (!Util.isEmpty(atts)) {
                for (BwAttendee att : atts) {
                    if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                        // Already there
                        return UpdateResult.getOkResult();
                    }
                }
            }
            BwAttendee newAtt = makeAttendee(pr);
            ev.addAttendee(newAtt);
            cte.addAddedValue(newAtt);
            return UpdateResult.getOkResult();
        }
        if (ui.isRemove()) {
            if (Util.isEmpty(atts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            BwAttendee remAtt = makeAttendee(pr);
            if (ev.removeAttendee(remAtt)) {
                cte.addRemovedValue(remAtt);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            // Change a value
            if (Util.isEmpty(atts)) {
                // Nothing to change
                return new UpdateResult("No comment to change");
            }
            for (BwAttendee att : atts) {
                if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                    // Found
                    throw new WebdavException("Unimplemented - attendees update");
                // return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (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) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 93 with BwEvent

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

the class ClassPropUpdater method applyUpdate.

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

Example 94 with BwEvent

use of org.bedework.calfacade.BwEvent 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 95 with BwEvent

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

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10