use of org.bedework.calfacade.BwRecurrenceInstance in project bw-calendar-engine by Bedework.
the class CoreEventsDAO method getInstance.
protected BwRecurrenceInstance getInstance(final BwEvent ev, final String rid) throws CalFacadeException {
final HibSession sess = getSess();
sess.createQuery(recurrenceInstanceQuery);
sess.setEntity("master", ev);
sess.setString("rid", rid);
return (BwRecurrenceInstance) sess.getUnique();
}
use of org.bedework.calfacade.BwRecurrenceInstance in project bw-calendar-engine by Bedework.
the class SchedulingBase method copyEventInfo.
/**
* Same as copyEventInfo(EventInfo, BwPrincipal) except it only copies
* significant changes.
*
* @param ei
* @param significantChangesOnly
* @param owner
* @return a copy of the event.
* @throws CalFacadeException
*/
protected EventInfo copyEventInfo(final EventInfo ei, final boolean significantChangesOnly, final BwPrincipal owner) throws CalFacadeException {
BwEvent ev = ei.getEvent();
BwEvent newEv = copyEvent(ev, null, owner);
StringBuilder changeInfo = new StringBuilder();
changeInfo.append(ev.getDtstamp());
final boolean cancel = ev.getScheduleMethod() == ScheduleMethods.methodTypeCancel;
final boolean adding = ei.getUpdResult().adding;
final boolean reply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
if (cancel) {
changeInfo.append(";CANCEL");
} else if (adding) {
changeInfo.append(";CREATE");
} else if (reply) {
changeInfo.append(";REPLY");
} else {
changeInfo.append(";UPDATE");
}
if (adding || cancel) {
changeInfo.append(";MASTER");
} else {
addChangeInfo(ei, changeInfo, "MASTER");
}
if (!ev.getRecurring()) {
setChangeInfo(newEv, changeInfo);
return new EventInfo(newEv);
}
if (cancel) {
/* Collect any attendees in overrides not in the copied master */
Set<EventInfo> overrides = ei.getOverrides();
if (overrides != null) {
for (EventInfo oei : overrides) {
for (BwAttendee ovatt : oei.getEvent().getAttendees()) {
if (newEv.findAttendee(ovatt.getAttendeeUri()) == null) {
newEv.addAttendee((BwAttendee) ovatt.clone());
}
}
}
}
setChangeInfo(newEv, changeInfo);
return new EventInfo(newEv);
}
boolean fromOrganizer = ev.getOrganizerSchedulingObject();
boolean attendeeInMaster = false;
String uri = getSvc().getDirectories().principalToCaladdr(owner);
if (fromOrganizer) {
attendeeInMaster = ev.findAttendee(uri) != null;
}
/* Save the status - we may change to master-suppressed */
String masterStatus = newEv.getStatus();
/* We may suppress the master event if there is no significant change and
* we only want significant changes or if the attendee is not an attendee
* of the master event.
*/
boolean masterSuppressed = false;
boolean significant = ei.getChangeset(getPrincipalHref()).getSignificantChange();
if (fromOrganizer && !attendeeInMaster) {
masterSuppressed = true;
}
List<String> deletedRecurids = null;
if (masterSuppressed) {
// Attendee will appear in overrides. Remove rules and r/exdates
if (!Util.isEmpty(ei.getUpdResult().deletedInstances)) {
deletedRecurids = new ArrayList<>();
for (BwRecurrenceInstance ri : ei.getUpdResult().deletedInstances) {
deletedRecurids.add(ri.getRecurrenceId());
}
}
if (newEv.getRrules() != null) {
newEv.getRrules().clear();
}
if (newEv.getRdates() != null) {
newEv.getRdates().clear();
}
if (newEv.getExrules() != null) {
newEv.getExrules().clear();
}
if (newEv.getExdates() != null) {
newEv.getExdates().clear();
}
newEv.setSuppressed(true);
}
Set<EventInfo> overrides = ei.getOverrides();
Set<EventInfo> newovs = new TreeSet<>();
if (overrides != null) {
for (EventInfo oei : overrides) {
BwEvent oev = oei.getEvent();
boolean attendeeInOverride = oev.findAttendee(uri) != null;
if (!masterSuppressed && attendeeInMaster && attendeeInOverride) {
if (significantChangesOnly) {
significant = oei.getChangeset(getPrincipalHref()).getSignificantChange();
if (!oei.getNewEvent() && !significant) {
continue;
}
}
}
if (fromOrganizer) {
if (!masterSuppressed && attendeeInMaster) {
/* If the attendee is not in this override, add an exdate to the master
*/
if (!attendeeInOverride) {
String rid = oev.getRecurrenceId();
BwDateTime bwrdt = BwDateTime.fromUTC(rid.length() == 8, rid);
newEv.addExdate(bwrdt);
continue;
}
} else if (attendeeInOverride) {
/* Add this override as an rdate */
String rid = oev.getRecurrenceId();
BwDateTime bwrdt = BwDateTime.fromUTC(rid.length() == 8, rid);
newEv.addRdate(bwrdt);
if ((deletedRecurids != null) && deletedRecurids.contains(oev.getRecurrenceId())) {
oev.setStatus(BwEvent.statusCancelled);
} else if ((oev.getStatus() != null) && oev.getStatus().equals(BwEvent.statusMasterSuppressed)) {
// Not overridden - set to saved master value
oev.setStatus(masterStatus);
}
oev.setSequence(ev.getSequence());
} else {
continue;
}
}
if (adding || cancel) {
changeInfo.append(";RID=");
changeInfo.append(oev.getRecurrenceId());
} else {
addChangeInfo(ei, changeInfo, oev.getRecurrenceId());
}
newovs.add(new EventInfo(copyEvent(oev, newEv, owner)));
}
}
setChangeInfo(newEv, changeInfo);
return new EventInfo(newEv, newovs);
}
Aggregations