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