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();
}
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);
}
}
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();
}
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();
}
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);
}
}
Aggregations