use of org.bedework.calfacade.util.ChangeTableEntry in project bw-calendar-engine by Bedework.
the class XbwCategoryPropUpdater method applyUpdate.
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
try {
final ChangeTableEntry cte = ui.getCte();
final BwEvent ev = ui.getEvent();
final List<BwXproperty> xcats = ev.getXproperties(BwXproperty.xBedeworkCategories);
final Set<BwCategory> cats = ev.getCategories();
final String lang = UpdaterUtil.getLang(ui.getProp());
final String xval = getValue(ui.getProp());
final BwString cstr = new BwString(lang, xval);
if (ui.isRemove()) {
if (Util.isEmpty(xcats)) {
// Nothing to remove
return UpdateResult.getOkResult();
}
for (final BwXproperty xp : xcats) {
if (!xp.getValue().equals(xval)) {
continue;
}
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
/* Do we have a corresponding category */
for (final BwCategory c : cats) {
if (c.getWord().equals(cstr)) {
ev.removeCategory(c);
cte.addRemovedValue(c);
break;
}
}
return UpdateResult.getOkResult();
}
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
for (final BwXproperty xp : xcats) {
if (xp.getValue().equals(xval)) {
return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
}
}
/* Add the xprop or a category */
if (!checkCategory(ui, ev, cats, lang, xval)) {
final BwXproperty xp = makeXprop(lang, xval);
ev.addXproperty(xp);
cte.addValue(xp);
}
return UpdateResult.getOkResult();
}
if (ui.isChange()) {
for (final BwXproperty xp : xcats) {
if (xp.getValue().equals(xval)) {
// Found
ev.removeXproperty(xp);
cte.addRemovedValue(xp);
final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
final String nxval = getValue(ui.getUpdprop());
if (!checkCategory(ui, ev, cats, nlang, nxval)) {
final BwXproperty nxp = makeXprop(nlang, nxval);
ev.addXproperty(nxp);
cte.addValue(nxp);
}
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 DurationPropUpdater method applyUpdate.
@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
if (ui.getSubComponent() != null) {
return alarmDurationPropUpdater.applyUpdate(ui);
}
BwEvent ev = ui.getEvent();
DurationPropType dur = (DurationPropType) ui.getProp();
DatesState ds = (DatesState) ui.getState(DatesState.stateName);
if (ds == null) {
ds = new DatesState(ev);
ui.saveState(DatesState.stateName, ds);
}
ChangeTableEntry cte = ui.getCte();
if (ui.isRemove()) {
if (ev.getEndType() != StartEndComponent.endTypeDuration) {
return new UpdateResult("Entity has no duration - cannot remove");
}
cte.setDeleted(ev.getDuration());
ds.duration = null;
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (ev.getEndType() == StartEndComponent.endTypeDuration) {
return new UpdateResult("Entity already has duration - cannot add");
}
ds.duration = dur.getDuration();
cte.setAdded(ds.duration);
return UpdateResult.getOkResult();
}
/* Changing duration */
if (ev.getEndType() != StartEndComponent.endTypeDuration) {
return new UpdateResult("Entity has no duration - cannot change");
}
dur = (DurationPropType) ui.getUpdprop();
if (!dur.getDuration().equals(ev.getDuration())) {
cte.setChanged(ev.getDuration(), dur.getDuration());
}
ds.duration = dur.getDuration();
return UpdateResult.getOkResult();
}
use of org.bedework.calfacade.util.ChangeTableEntry in project bw-calendar-engine by Bedework.
the class GeoPropUpdater method applyUpdate.
@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
BwEvent ev = ui.getEvent();
GeoPropType pr = (GeoPropType) ui.getProp();
ChangeTableEntry cte = ui.getCte();
BwGeo val = new BwGeo(new BigDecimal(String.valueOf(pr.getLatitude())), new BigDecimal(String.valueOf(pr.getLongitude())));
BwGeo evVal = ev.getGeo();
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());
}
pr = (GeoPropType) ui.getUpdprop();
val = new BwGeo(new BigDecimal(String.valueOf(pr.getLatitude())), new BigDecimal(String.valueOf(pr.getLongitude())));
}
if (Util.cmpObjval(val, evVal) != 0) {
cte.setChanged(evVal, val);
ev.setGeo(val);
}
return UpdateResult.getOkResult();
}
use of org.bedework.calfacade.util.ChangeTableEntry in project bw-calendar-engine by Bedework.
the class PercentCompletePropUpdater method applyUpdate.
@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
BwEvent ev = ui.getEvent();
PercentCompletePropType pr = (PercentCompletePropType) ui.getProp();
ChangeTableEntry cte = ui.getCte();
BigInteger val = pr.getInteger();
BigInteger evVal = null;
if (ev.getPercentComplete() != null) {
evVal = BigInteger.valueOf(ev.getPercentComplete());
}
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 = ((PercentCompletePropType) ui.getUpdprop()).getInteger();
}
if (Util.cmpObjval(val, evVal) != 0) {
cte.setChanged(evVal, val);
ev.setPercentComplete(val.intValue());
}
return UpdateResult.getOkResult();
}
use of org.bedework.calfacade.util.ChangeTableEntry in project bw-calendar-engine by Bedework.
the class Events method checkChanges.
@SuppressWarnings("unchecked")
private boolean checkChanges(final EventInfo ei, final boolean organizerSchedulingObject, final boolean attendeeSchedulingObject) throws CalFacadeException {
final UpdateResult updResult = ei.getUpdResult();
if (ei.getChangeset(getPrincipalHref()).isEmpty()) {
// Forced update?
updResult.hasChanged = true;
if (attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.reply = true;
}
return true;
}
if (debug) {
ei.getChangeset(getPrincipalHref()).dumpEntries();
}
final ChangeTable ct = ei.getChangeset(getPrincipalHref());
final Collection<ChangeTableEntry> ctes = ct.getEntries();
updResult.sequenceChange = ct.getSequenceChangeNeeded();
for (final ChangeTableEntry cte : ctes) {
if (!cte.getChanged()) {
continue;
}
updResult.hasChanged = true;
final PropertyInfoIndex pi = cte.getIndex();
if (!organizerSchedulingObject && pi.equals(PropertyInfoIndex.ORGANIZER)) {
final BwOrganizer oldOrg = (BwOrganizer) cte.getOldVal();
final BwOrganizer newOrg = (BwOrganizer) cte.getNewVal();
if ((oldOrg == null) || (newOrg == null) || !oldOrg.getOrganizerUri().equals(newOrg.getOrganizerUri())) {
// Never valid
throw new CalFacadeForbidden(CaldavTags.attendeeAllowed, "Cannot change organizer");
}
}
if (pi.equals(PropertyInfoIndex.ATTENDEE) || pi.equals(PropertyInfoIndex.VOTER)) {
updResult.addedAttendees = cte.getAddedValues();
updResult.deletedAttendees = cte.getRemovedValues();
if (attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.reply = true;
} else {
if (!Util.isEmpty(updResult.deletedAttendees)) {
// Bump sequence as we are sending out cancels
updResult.sequenceChange = true;
}
}
}
if (pi.equals(PropertyInfoIndex.POLL_WINNER)) {
if (!attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.pollWinner = ei.getEvent().getPollWinner();
}
}
if (pi.equals(PropertyInfoIndex.POLL_ITEM)) {
if (attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.reply = true;
}
}
if (organizerSchedulingObject) {
final BwIcalPropertyInfoEntry pie = BwIcalPropertyInfo.getPinfo(cte.getIndex());
if (pie.getReschedule()) {
updResult.doReschedule = true;
}
}
}
return updResult.hasChanged;
}
Aggregations