use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class OutboundSchedulingHandler method getRecipientInbox.
/* Get the inbox for the recipient from the search result. If there is
* no inbox object already it will be added. If the recipient is not local to this
* system, we mark the inbox entry as deferred and add the recipient to the
* list of external recipients. We will possibly mail the request or try
* ischedule to another server.
*
* If fromAtt is not null and the recipient is that attendee we skip it. This
* is the result of a reply from that attendee being broadcast to the other
* attendees.
*
* If reinvite is true we are resending the invitation to all attendees,
* including those who previously declined. Otherwise we skip those who
* declined.
*
* Note we have to search all overrides to get the information we need. We can
* short circuit this to some extent as we fill in information about attendees.
*/
private void getRecipientInbox(final EventInfo ei, final String recip, final String fromAttUri, final ScheduleResult sr, final boolean freeBusyRequest) throws CalFacadeException {
final BwEvent ev = ei.getEvent();
/* See if the attendee is in this event */
final BwAttendee att = ev.findAttendee(recip);
if ((att != null) && (fromAttUri != null) && fromAttUri.equals(att.getAttendeeUri())) {
// Skip this one, they were the ones that sent the reply.
return;
}
final UserInbox ui = getInbox(sr, recip, freeBusyRequest);
if (att != null) {
ui.addAttendee(att);
if (Util.compareStrings(att.getPartstat(), IcalDefs.partstatValDeclined) == 0) {
// Skip this one, they declined.
return;
}
att.setScheduleStatus(IcalDefs.deliveryStatusPending);
}
if (ui.getStatus() == ScheduleStates.scheduleDeferred) {
sr.externalRcs.add(recip);
} else if (ui.getStatus() == ScheduleStates.scheduleNoAccess) {
sr.errorCode = CalFacadeException.schedulingAttendeeAccessDisallowed;
if (att != null) {
att.setScheduleStatus(IcalDefs.deliveryStatusNoAccess);
}
} else if ((ui.principal == null) && (ui.getHost() != null)) {
sr.externalRcs.add(recip);
}
if (ei.getNumOverrides() > 0) {
for (final EventInfo oei : ei.getOverrides()) {
getRecipientInbox(oei, recip, fromAttUri, sr, freeBusyRequest);
}
}
}
use of org.bedework.calfacade.svc.EventInfo 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);
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class SchedulingBase method significantChange.
/**
* Return true if there is a significant change for the entity or any overrides
*
* @param ei
* @return true if something important changed
* @throws CalFacadeException
*/
protected boolean significantChange(final EventInfo ei) throws CalFacadeException {
if (ei.getNewEvent() || ei.getChangeset(getPrincipalHref()).getSignificantChange()) {
return true;
}
BwEvent ev = ei.getEvent();
boolean override = ev instanceof BwEventProxy;
if (override || (ei.getOverrides() == null)) {
return false;
}
for (EventInfo oei : ei.getOverrides()) {
if (significantChange(oei)) {
return true;
}
}
return false;
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class AttendeeSchedulingHandler method scheduleResponse.
/* (non-Javadoc)
* @see org.bedework.calsvci.SchedulingI#processCancel(org.bedework.calfacade.svc.EventInfo, org.bedework.calfacade.svc.EventInfo)
* /
public ScheduleResult processCancel(final EventInfo ei) throws CalFacadeException {
/* We, as an attendee, received a CANCEL from the organizer.
*
* /
ScheduleResult sr = new ScheduleResult();
BwEvent ev = ei.getEvent();
BwCalendar inbox = getSvc().getCalendarsHandler().get(ev.getColPath());
boolean forceDelete = true;
check: {
if (inbox.getCalType() != BwCalendar.calTypeInbox) {
sr.errorCode = CalFacadeException.schedulingBadSourceCalendar;
break check;
}
if (ev.getOriginator() == null) {
sr.errorCode = CalFacadeException.schedulingNoOriginator;
break check;
}
BwPreferences prefs = getSvc().getPrefsHandler().get();
EventInfo colEi = getStoredMeeting(ei.getEvent());
if (colEi == null) {
break check;
}
BwEvent colEv = colEi.getEvent();
if (prefs.getScheduleAutoCancelAction() ==
BwPreferences.scheduleAutoCancelSetStatus) {
if (colEv.getSuppressed()) {
if (colEi.getOverrides() != null) {
for (EventInfo oei: colEi.getOverrides()) {
oei.getEvent().setStatus(BwEvent.statusCancelled);
}
}
} else {
colEv.setStatus(BwEvent.statusCancelled);
}
getSvc().getEventsHandler().update(colEi, true, null);
} else {
getSvc().getEventsHandler().delete(colEi, false);
}
forceDelete = false;
}
updateInbox(ei, inbox.getOwnerHref(),
false, // attendeeAccepting
forceDelete); // forceDelete
return sr;
}
*/
/* (non-Javadoc)
* @see org.bedework.calsvci.SchedulingI#scheduleResponse(org.bedework.calfacade.BwEvent)
*/
@Override
public ScheduleResult scheduleResponse(final EventInfo ei) throws CalFacadeException {
/* As an attendee, respond to a scheduling request.
*
* Copy event
* remove all attendees and readd this user
* Add to organizers inbox if internal
* Put in outbox if external.
*/
ScheduleResult sr = new ScheduleResult();
try {
int smethod = ei.getEvent().getScheduleMethod();
if (!Icalendar.itipReplyMethodType(smethod)) {
sr.errorCode = CalFacadeException.schedulingBadMethod;
return sr;
}
/* For each recipient within this system add the event to their inbox.
*
* If there are any external users add it to the outbox and it will be
* mailed to the recipients.
*/
int outAccess = PrivilegeDefs.privScheduleReply;
/* There should only be one attendee for a reply */
if (!ei.getEvent().getSuppressed()) {
BwEvent ev = ei.getEvent();
if (ev.getNumAttendees() != 1) {
sr.errorCode = CalFacadeException.schedulingBadAttendees;
return sr;
}
}
if (ei.getNumOverrides() > 0) {
for (EventInfo oei : ei.getOverrides()) {
BwEvent ev = oei.getEvent();
if (ev.getNumAttendees() != 1) {
sr.errorCode = CalFacadeException.schedulingBadAttendees;
return sr;
}
}
}
if (!initScheduleEvent(ei, true, false)) {
return sr;
}
/* Do this here to check we have access. We might need the outbox later
*/
BwCalendar outBox = getSpecialCalendar(getPrincipal(), BwCalendar.calTypeOutbox, true, outAccess);
sendSchedule(sr, ei, null, null, false);
if (sr.ignored) {
return sr;
}
if (!sr.externalRcs.isEmpty()) {
sr.errorCode = addToOutBox(ei, outBox, sr.externalRcs);
}
return sr;
} catch (Throwable t) {
getSvc().rollbackTransaction();
if (t instanceof CalFacadeException) {
throw (CalFacadeException) t;
}
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.svc.EventInfo in project bw-calendar-engine by Bedework.
the class AttendeeSchedulingHandler method requestRefresh.
@Override
public ScheduleResult requestRefresh(final EventInfo ei, final String comment) throws CalFacadeException {
ScheduleResult sr = new ScheduleResult();
BwEvent ev = ei.getEvent();
if (ev.getScheduleMethod() != ScheduleMethods.methodTypeRequest) {
sr.errorCode = CalFacadeException.schedulingBadMethod;
return sr;
}
BwAttendee att = findUserAttendee(ev);
if (att == null) {
throw new CalFacadeException(CalFacadeException.schedulingNotAttendee);
}
BwEvent outEv = new BwEventObj();
EventInfo outEi = new EventInfo(outEv);
outEv.setScheduleMethod(ScheduleMethods.methodTypeRefresh);
outEv.addRecipient(ev.getOrganizer().getOrganizerUri());
outEv.setOriginator(att.getAttendeeUri());
outEv.updateDtstamp();
outEv.setOrganizer((BwOrganizer) ev.getOrganizer().clone());
outEv.getOrganizer().setDtstamp(outEv.getDtstamp());
outEv.addAttendee((BwAttendee) att.clone());
outEv.setUid(ev.getUid());
outEv.setRecurrenceId(ev.getRecurrenceId());
outEv.setDtstart(ev.getDtstart());
outEv.setDtend(ev.getDtend());
outEv.setDuration(ev.getDuration());
outEv.setNoStart(ev.getNoStart());
outEv.setRecurring(false);
if (comment != null) {
outEv.addComment(new BwString(null, comment));
}
sr = scheduleResponse(outEi);
outEv.setScheduleState(BwEvent.scheduleStateProcessed);
return sr;
}
Aggregations