use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.
the class XbwContactPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xcontacts = ev.getXproperties(BwXproperty.xBedeworkContact);
final Set<BwContact> contacts = ev.getContacts();
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = ((TextPropertyType) ui.getProp()).getText();
final BwString cstr = new BwString(lang, xval);
if (ui.isRemove()) {
if (Util.isEmpty(xcontacts)) {
// Nothing to remove
return UpdateResult.getOkResult();
}
for (final BwXproperty xp : xcontacts) {
if (!xp.getValue().equals(xval)) {
continue;
}
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
/* Do we have a corresponding contact */
for (final BwContact c : contacts) {
if (c.getCn().equals(cstr)) {
ev.removeContact(c);
cte.addRemovedValue(c);
break;
}
}
return UpdateResult.getOkResult();
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
for (final BwXproperty xp : xcontacts) {
if (xp.getValue().equals(xval)) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
}
}
/* Add the xprop or a contact */
if (!checkContact(ui, ev, contacts, lang, xval)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addAddedValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
for (final BwXproperty xp : xcontacts) {
if (xp.getValue().equals(xval)) {
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
if (!checkContact(ui, ev, contacts, nlang, nxval)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
ev.addXproperty(nxp);
cte.addAddedValue(nxp);
}
return UpdateResult.getOkResult();
}
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult in project bw-calendar-engine by Bedework.
the class XbwLocPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xlocs = ev.getXproperties(xBedeworkLocation);
// Should only be one or zero
final BwXproperty xloc;
if (Util.isEmpty(xlocs)) {
xloc = null;
} else {
xloc = xlocs.get(0);
}
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = ((TextPropertyType) ui.getProp()).getText();
final BaseParameterType keyParam = XcalUtil.findParam(ui.getProp(), XcalTags.xBedeworkLocationKey);
final String keyName;
if (keyParam != null) {
keyName = ((TextParameterType) keyParam).getText();
} else {
keyName = null;
}
final BwLocation evLoc = ev.getLocation();
if (ui.isRemove()) {
if (xlocs == null) {
// Nothing to remove
return UpdateResult.getOkResult();
}
// TODO - match values?
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
if (evLoc != null) {
ev.setLocation(null);
cte.addRemovedValue(evLoc);
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (xloc != null) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
}
if (!checkLocation(ui, ev, lang, xval, null)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addAddedValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
if (xloc == null) {
return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot change");
}
if (CalFacadeUtil.cmpObjval(xval, xloc.getValue()) != 0) {
return new UpdateResult("Values don't match for update to " + ui.getPropName());
}
ev.removeXproperty(xloc);
cte.addRemovedValue(xloc);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
if (!checkLocation(ui, ev, nlang, nxval, keyName)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
if (keyName != null) {
nxp.getParameters().add(new Xpar(XcalTags.xBedeworkLocationKey.getLocalPart(), keyName));
}
ev.addXproperty(nxp);
cte.addAddedValue(nxp);
}
}
return UpdateResult.getOkResult();
} catch (final CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult 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.caldav.server.sysinterface.SysIntf.UpdateResult 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.caldav.server.sysinterface.SysIntf.UpdateResult 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();
}
Aggregations