use of org.bedework.calfacade.configs.AuthProperties in project bw-calendar-engine by Bedework.
the class InRequest method getRecurrences.
private Collection<Recurrence> getRecurrences(final EventInfo ei) throws CalFacadeException {
AuthProperties authpars = getSvc().getAuthProperties();
int maxYears = authpars.getMaxYears();
int maxInstances = authpars.getMaxInstances();
return RecurUtil.getRecurrences(ei, maxYears, maxInstances, null, null);
}
use of org.bedework.calfacade.configs.AuthProperties in project bw-calendar-engine by Bedework.
the class InRequest method autoRespond.
/* ====================================================================
Private methods
==================================================================== */
private boolean autoRespond(final CalSvcI svci, final EventInfo ourCopy, final EventInfo inboxEi, final boolean doubleBookOk, final String uri) throws CalFacadeException {
BwEvent inboxEv = inboxEi.getEvent();
String owner = inboxEv.getOwnerHref();
if (ourCopy == null) {
// Error - deleted while we did this?
if (debug) {
trace("InSchedule - no event for auto respond for " + owner);
}
return false;
}
BwOrganizer org = new BwOrganizer();
org.setOrganizerUri(uri);
BwAttendee att = null;
BwEvent ourEvent = ourCopy.getEvent();
String now = DateTimeUtil.isoDateTimeUTC(new Date());
if (!ourEvent.getRecurring()) {
if (ourEvent.getDtend().getDate().compareTo(now) < 0) {
return false;
}
att = ourEvent.findAttendee(uri);
if (att == null) {
// Error?
if (debug) {
trace("InSchedule - no attendee on our copy for auto respond for " + owner);
}
return false;
}
if (debug) {
trace("send response event for " + owner + " " + inboxEv.getName());
}
// We're about to reply.
att.setRsvp(false);
String partStat = IcalDefs.partstatValAccepted;
ourEvent.removeXproperties(BwXproperty.appleNeedsReply);
if (!doubleBookOk) {
// See if there are any events booked during this time.
if (checkBusy(svci, ourEvent.getUid(), inboxEv.getDtstart(), inboxEv.getDtend(), org, inboxEv.getUid())) {
partStat = IcalDefs.partstatValDeclined;
} else {
ourEvent.setTransparency(IcalDefs.transparencyOpaque);
}
}
ourEvent.setScheduleMethod(ScheduleMethods.methodTypeReply);
att = (BwAttendee) att.clone();
ourEvent.removeAttendee(att);
ourEvent.addAttendee(att);
att.setPartstat(partStat);
return true;
}
// Recurring event - do the above per recurrence
AuthProperties authpars = svci.getAuthProperties();
int maxYears = authpars.getMaxYears();
int maxInstances = authpars.getMaxInstances();
Collection<Recurrence> recurrences = RecurUtil.getRecurrences(inboxEi, maxYears, maxInstances, now, null);
if (Util.isEmpty(recurrences)) {
return false;
}
if (debug) {
trace("autoRespond: " + recurrences.size() + " instances");
}
/* Assume accept and then override with declines - assuming we're in the
* master
*/
ourEvent.removeXproperties(BwXproperty.appleNeedsReply);
boolean masterSupressed = true;
if (!inboxEv.getSuppressed()) {
masterSupressed = false;
att = ourEvent.findAttendee(uri);
if (att != null) {
// It should never be null
att.setRsvp(false);
att.setPartstat(IcalDefs.partstatValAccepted);
}
ourEvent.setTransparency(IcalDefs.transparencyOpaque);
}
RecurInfo rinfo = checkBusy(svci, ourEvent.getUid(), recurrences, org, inboxEv.getUid(), doubleBookOk);
/* If we have a master then we should set its status to cover the largest
* number of overrides - if any.
*
* The easiest case is no overrides and all accepted or all declined.
*
* Otherwise we have to update or add overrides.
*/
boolean allAcceptedOrDeclined = (rinfo.availCt == 0) || (rinfo.busyCt == 0);
boolean masterAccept = rinfo.availCt >= rinfo.busyCt;
String masterPartStat;
if (masterAccept) {
masterPartStat = IcalDefs.partstatValAccepted;
} else {
masterPartStat = IcalDefs.partstatValDeclined;
}
if (!masterSupressed) {
att = ourEvent.findAttendee(uri);
if (!masterPartStat.equals(att.getPartstat())) {
att.setPartstat(masterPartStat);
}
if (masterAccept) {
ourEvent.setTransparency(IcalDefs.transparencyOpaque);
} else {
ourEvent.setTransparency(IcalDefs.transparencyTransparent);
}
}
if (allAcceptedOrDeclined) {
// Ensure any overrides have the same status
for (EventInfo oei : ourCopy.getOverrides()) {
BwEvent override = oei.getEvent();
att = override.findAttendee(uri);
att = (BwAttendee) att.clone();
// We're about to reply.
att.setRsvp(false);
override.removeAttendee(att);
override.addAttendee(att);
if (!masterPartStat.equals(att.getPartstat())) {
att.setPartstat(masterPartStat);
}
if (masterAccept) {
override.setTransparency(IcalDefs.transparencyOpaque);
} else {
override.setTransparency(IcalDefs.transparencyTransparent);
}
override.removeXproperties(BwXproperty.appleNeedsReply);
}
return true;
}
for (RecurrenceInfo ri : rinfo.ris) {
Recurrence r = ri.r;
// if (!masterSupressed && !ri.busy && (r.override == null)) {
// // fine
// continue;
// }
boolean mustOverride = masterAccept == ri.busy;
EventInfo oei = ourCopy.findOverride(r.recurrenceId, mustOverride);
if (oei == null) {
continue;
}
BwEvent override = oei.getEvent();
if (((BwEventProxy) override).getRef().unsaved()) {
override.setDtstart(r.start);
override.setDtend(r.end);
override.setDuration(BwDateTime.makeDuration(r.start, r.end).toString());
}
att = override.findAttendee(uri);
if (att == null) {
// Guess we weren't invited
continue;
}
att = (BwAttendee) att.clone();
// We're about to reply.
att.setRsvp(false);
override.removeAttendee(att);
override.addAttendee(att);
if (!ri.busy) {
att.setPartstat(IcalDefs.partstatValAccepted);
override.setTransparency(IcalDefs.transparencyOpaque);
} else {
att.setPartstat(IcalDefs.partstatValDeclined);
override.setTransparency(IcalDefs.transparencyTransparent);
}
override.removeXproperties(BwXproperty.appleNeedsReply);
}
return true;
}
Aggregations