use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.
the class Xalarms method toXAlarm.
/**
* @param ev
* @param val
* @param pattern
* @param masterClass
* @return ValarmType
* @throws CalFacadeException
*/
public static ValarmType toXAlarm(final BwEvent ev, final BwAlarm val, final BaseComponentType pattern, final Class masterClass) throws CalFacadeException {
try {
ValarmType alarm = new ValarmType();
int atype = val.getAlarmType();
alarm.setProperties(new ArrayOfProperties());
List<JAXBElement<? extends BasePropertyType>> pl = alarm.getProperties().getBasePropertyOrTzid();
if (emit(pattern, masterClass, ValarmType.class, ActionPropType.class)) {
ActionPropType a = new ActionPropType();
a.setText(BwAlarm.alarmTypes[val.getAlarmType()]);
pl.add(of.createAction(a));
}
if (emit(pattern, masterClass, ValarmType.class, TriggerPropType.class)) {
TriggerPropType t = new TriggerPropType();
if (val.getTriggerDateTime()) {
// t.setDateTime(val.getTrigger());
t.setDateTime(XcalUtil.getXMlUTCCal(val.getTrigger()));
} else {
t.setDuration(val.getTrigger());
if (!val.getTriggerStart()) {
ArrayOfParameters pars = getAop(t);
RelatedParamType r = new RelatedParamType();
r.setText(IcalDefs.alarmTriggerRelatedEnd);
JAXBElement<RelatedParamType> param = of.createRelated(r);
pars.getBaseParameter().add(param);
}
}
pl.add(of.createTrigger(t));
}
if (emit(pattern, masterClass, ValarmType.class, DurationPropType.class)) {
if (val.getDuration() != null) {
DurationPropType dur = new DurationPropType();
dur.setDuration(val.getDuration());
pl.add(of.createDuration(dur));
RepeatPropType rep = new RepeatPropType();
rep.setInteger(BigInteger.valueOf(val.getRepeat()));
pl.add(of.createRepeat(rep));
}
}
/* Description */
if ((atype == BwAlarm.alarmTypeDisplay) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
// Both require description
String desc = val.getDescription();
if (desc == null) {
if (ev != null) {
if (ev.getDescription() != null) {
desc = ev.getDescription();
} else {
desc = ev.getSummary();
}
}
}
if (desc == null) {
desc = " ";
}
DescriptionPropType d = new DescriptionPropType();
d.setText(desc);
pl.add(of.createDescription(d));
}
/* Summary */
if (atype == BwAlarm.alarmTypeEmail) {
SummaryPropType s = new SummaryPropType();
s.setText(val.getSummary());
pl.add(of.createSummary(s));
}
if ((atype == BwAlarm.alarmTypeAudio) || (atype == BwAlarm.alarmTypeEmail) || (atype == BwAlarm.alarmTypeProcedure)) {
if (val.getAttach() != null) {
AttachPropType a = new AttachPropType();
a.setUri(val.getAttach());
pl.add(of.createAttach(a));
}
}
/* Attendees */
if (atype == BwAlarm.alarmTypeEmail) {
if (val.getNumAttendees() > 0) {
for (BwAttendee att : val.getAttendees()) {
pl.add(of.createAttendee(ToXEvent.makeAttendee(att)));
}
}
}
if (val.getNumXproperties() > 0) {
/* This alarm has x-props */
}
return alarm;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.
the class ImplicitSchedulingHandler method sendReply.
/* (non-Javadoc)
* @see org.bedework.calsvci.SchedulingI#sendReply(org.bedework.calfacade.svc.EventInfo, int, java.lang.String)
*/
@Override
public ScheduleResult sendReply(final EventInfo ei, final int partstat, final String comment) throws CalFacadeException {
ScheduleResult sr = new ScheduleResult();
BwEvent ev = ei.getEvent();
if (!ev.getAttendeeSchedulingObject()) {
sr.errorCode = CalFacadeException.schedulingBadMethod;
return sr;
}
BwAttendee att = findUserAttendee(ev);
if (att == null) {
sr.errorCode = CalFacadeException.schedulingNotAttendee;
return sr;
}
att = (BwAttendee) att.clone();
att.setPartstat(IcalDefs.partstats[partstat]);
att.setRsvp(partstat == IcalDefs.partstatNeedsAction);
BwEvent outEv = new BwEventObj();
EventInfo outEi = new EventInfo(outEv);
outEv.setScheduleMethod(ScheduleMethods.methodTypeReply);
outEv.addRequestStatus(new BwRequestStatus(IcalDefs.requestStatusSuccess.getCode(), IcalDefs.requestStatusSuccess.getDescription()));
outEv.addRecipient(ev.getOrganizer().getOrganizerUri());
outEv.setOriginator(att.getAttendeeUri());
outEv.updateDtstamp();
outEv.setOrganizer((BwOrganizer) ev.getOrganizer().clone());
outEv.getOrganizer().setDtstamp(outEv.getDtstamp());
outEv.addAttendee(att);
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.setSummary(ev.getSummary());
outEv.setRecurring(false);
if (comment != null) {
outEv.addComment(new BwString(null, comment));
}
sr = scheduleResponse(outEi);
outEv.setScheduleState(BwEvent.scheduleStateProcessed);
return sr;
}
use of org.bedework.calfacade.BwAttendee 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.BwAttendee 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.BwAttendee in project bw-calendar-engine by Bedework.
the class SchedulingBase method getRecipients.
private void getRecipients(final BwEvent master, final BwEvent ev) {
if (ev.getAttendees() == null) {
return;
}
for (BwAttendee att : ev.getAttendees()) {
if (att.getScheduleAgent() != IcalDefs.scheduleAgentServer) {
continue;
}
String uri = att.getAttendeeUri();
master.addRecipient(uri);
}
}
Aggregations