use of org.bedework.calfacade.util.ChangeTable 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;
}
use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.
the class Events method doCats.
private void doCats(final RealiasResult resp, final String colHref, final BwEvent ev) {
try {
final Set<BwCategory> cats = getCols().getCategorySet(colHref);
if (Util.isEmpty(cats)) {
return;
}
resp.getCats().addAll(cats);
for (final BwCategory cat : cats) {
if (ev.addCategory(cat)) {
final ChangeTable changes = ev.getChangeset(getPrincipalHref());
final ChangeTableEntry cte = changes.getEntry(PropertyInfoIndex.CATEGORIES);
cte.addAddedValue(cat);
}
}
} catch (final Throwable t) {
Response.error(new RealiasResult(null), t.getMessage());
}
}
use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.
the class EventInfo method getDeletedOverrideProxies.
/**
* @param userHref
* @return Collection of deleted override proxy events or null
* @throws CalFacadeException
*/
public Collection<BwEventProxy> getDeletedOverrideProxies(final String userHref) throws CalFacadeException {
TreeSet<BwEventProxy> proxies = new TreeSet<>();
if ((retrievedOverrides == null) || instanceOnly) {
return proxies;
}
for (EventOverride eo : retrievedOverrides) {
if (overrides.contains(eo)) {
continue;
}
BwEventProxy proxy = (BwEventProxy) eo.getEvent();
if (proxy.getRef().unsaved()) {
throw new RuntimeException("Unsaved override in delete list");
}
if (proxy.getXproperty(BwXproperty.peruserInstance) == null) {
/* Not peruser - remove it. */
proxies.add(proxy);
continue;
}
BwXproperty pu = proxy.findPeruserXprop(userHref, BwXproperty.peruserPropTransp);
if (pu != null) {
/* remove it */
proxy.removeXproperty(pu);
}
/* Remove any alarm(s) */
List<BwAlarm> toRemove = new ArrayList<>();
for (BwAlarm a : proxy.getAlarms()) {
if (a.getOwnerHref().equals(userHref)) {
toRemove.add(a);
}
}
for (BwAlarm a : toRemove) {
proxy.removeAlarm(a);
}
if (Util.isEmpty(proxy.getXproperties(BwXproperty.peruserPropTransp)) && Util.isEmpty(proxy.getAlarms())) {
/* No more peruser data - add to remove list */
proxies.add(proxy);
}
/* Update the changes */
ChangeTable chg = getChangeset(userHref);
if (pu != null) {
chg.addValue(PropertyInfoIndex.XPROP, pu);
}
if (!Util.isEmpty(toRemove)) {
for (BwAlarm a : toRemove) {
chg.addValue(PropertyInfoIndex.VALARM, a);
}
}
}
return proxies;
}
use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.
the class InProcessor method pendingToInbox.
/**
* Update the inbox according to it's owners wishes (what if owner and proxy
* have different wishes)
*
* @param ei - the pending inbox event
* @param inboxOwnerHref href of
* @param attendeeAccepting - is this the result of a REPLY with PARTSTAT accept?
* @param forceDelete - it's inbox noise, delete it
* @throws CalFacadeException
*/
public void pendingToInbox(final EventInfo ei, final String inboxOwnerHref, final boolean attendeeAccepting, final boolean forceDelete) throws CalFacadeException {
boolean delete = forceDelete;
if (!delete) {
final BwPrincipal principal = getSvc().getUsersHandler().getPrincipal(inboxOwnerHref);
if (principal == null) {
delete = true;
} else {
final BwPreferences prefs = getSvc().getPrefsHandler().get(principal);
final int sapr = prefs.getScheduleAutoProcessResponses();
if (sapr == BwPreferences.scheduleAutoProcessResponsesNoNotify) {
delete = true;
} else if (sapr == BwPreferences.scheduleAutoProcessResponsesNoAcceptNotify) {
delete = attendeeAccepting;
}
}
}
final BwEvent ev = ei.getEvent();
final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
if (delete) {
getSvc().getEventsHandler().delete(ei, false);
} else {
final BwCalendar inbox = getSvc().getCalendarsHandler().getSpecial(BwCalendar.calTypeInbox, false);
if (inbox == null) {
return;
}
// if (vpoll) {
/* Delete other notifications for the same event
* NOTE: DON'T for non-vpoll - this was deleting changes that had to
* be processed. Still an opportunity to improve this though.
*/
final Collection<EventInfo> inevs = getEventsByUid(inbox.getPath(), ev.getUid());
for (final EventInfo inei : inevs) {
final BwEvent inev = inei.getEvent();
if (inev.getScheduleState() != BwEvent.scheduleStateProcessed) {
continue;
}
if (debug) {
trace("delete earlier? event from inbox: " + inev.getName());
}
deleteEvent(inei, true, false);
}
if (debug) {
trace("set event to scheduleStateProcessed: " + ev.getName());
}
final ChangeTable chg = ei.getChangeset(inboxOwnerHref);
chg.changed(PropertyIndex.PropertyInfoIndex.SCHEDULE_STATE, ev.getScheduleState(), BwEvent.scheduleStateProcessed);
ev.setScheduleState(BwEvent.scheduleStateProcessed);
chg.changed(PropertyIndex.PropertyInfoIndex.COLPATH, ev.getColPath(), inbox.getPath());
ev.setColPath(inbox.getPath());
getSvc().getEventsHandler().update(ei, true, null);
}
}
use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.
the class InRequest method updateAttendeePollCopy.
private boolean updateAttendeePollCopy(final EventInfo ourCopy, final EventInfo inCopy, final String attUri) throws CalFacadeException {
try {
final BwEvent ourEv = ourCopy.getEvent();
final BwEvent inEv = inCopy.getEvent();
final boolean statusUpdate;
if (inEv.getScheduleMethod() == ScheduleMethods.methodTypeRequest) {
if (debug) {
trace("Update the poll common fields");
}
if (!updateAttendeeFields(ourCopy, inCopy, attUri)) {
return false;
}
statusUpdate = false;
} else if (inEv.getScheduleMethod() != ScheduleMethods.methodTypePollStatus) {
if (debug) {
debug("Bad method " + inEv.getScheduleMethod());
}
return false;
} else {
statusUpdate = true;
}
// Now update the vpoll items.
final ChangeTable chg = ourCopy.getChangeset(getPrincipalHref());
chg.changed(PropertyInfoIndex.STATUS, ourEv.getStatus(), inEv.getStatus());
ourEv.setStatus(inEv.getStatus());
final Integer pw = inEv.getPollWinner();
if (pw != null) {
chg.changed(PropertyInfoIndex.POLL_WINNER, ourEv.getPollWinner(), inEv.getPollWinner());
ourEv.setPollWinner(pw);
}
ourEv.clearVvoters();
for (final String s : inEv.getVvoters()) {
ourEv.addVvoter(s);
chg.addValue(PropertyInfoIndex.VVOTER, s);
}
if (!statusUpdate) {
ourEv.clearPollItems();
for (final String s : inEv.getPollItems()) {
ourEv.addPollItem(s);
chg.addValue(PropertyInfoIndex.POLL_ITEM, s);
}
}
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
return true;
}
Aggregations