use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.
the class InReply method updateOrganizerCopy.
private boolean updateOrganizerCopy(final EventInfo colEi, final EventInfo inBoxEi, final String attUri, final ScheduleResult sr) throws CalFacadeException {
final BwEvent inBoxEv = inBoxEi.getEvent();
final BwEvent calEv = colEi.getEvent();
final ChangeTable chg = calEv.getChangeset(getPrincipalHref());
/* Only set true if the inbox copy needs to stay as notification.
* Do not set true for status updates
*/
boolean changed = false;
if (debug) {
trace("Update for attendee " + attUri);
}
if (inBoxEv.getScheduleMethod() != ScheduleMethods.methodTypeReply) {
sr.errorCode = CalFacadeException.schedulingBadMethod;
return false;
}
/* If the incoming sequence is less than that in the organizers event
* then ignore the incoming reply?
*/
/* Update the participation status from the incoming attendee */
BwAttendee calAtt;
final ChangeTableEntry cte = chg.getEntry(PropertyIndex.PropertyInfoIndex.ATTENDEE);
if (!inBoxEv.getSuppressed()) {
calAtt = calEv.findAttendee(attUri);
if (calAtt == null) {
if (debug) {
trace("Not an attendee of " + calEv);
}
sr.errorCode = CalFacadeException.schedulingUnknownAttendee;
sr.extraInfo = attUri;
return false;
}
// For a recurring instance we replace or we update all recurring instances.
final boolean recurringInstance = (calEv instanceof BwEventProxy);
final BwAttendee att = inBoxEv.findAttendee(attUri);
if (calAtt.changedBy(att)) {
changed = true;
if (recurringInstance) {
calEv.removeAttendee(att);
calAtt = (BwAttendee) att.clone();
} else {
att.copyTo(calAtt);
}
cte.addChangedValue(calAtt);
}
calAtt.setScheduleStatus(getRstat(inBoxEv));
if (recurringInstance) {
calEv.addAttendee(calAtt);
}
// XXX Ensure no name change
if (calEv instanceof BwEventProxy) {
final BwEventProxy pr = (BwEventProxy) calEv;
final BwEventAnnotation ann = pr.getRef();
ann.setName(null);
}
}
/* The above changed the master - now we need to update or add any overrides
*/
if (calEv.getRecurring() && (inBoxEi.getOverrides() != null)) {
for (final EventInfo oei : inBoxEi.getOverrides()) {
final BwEvent oev = oei.getEvent();
final EventInfo cei = colEi.findOverride(oev.getRecurrenceId());
/*
if (cei == null) {
// Organizer must have deleted the override.
if (debug) {
trace("Skipping missing override " + oev.getRecurrenceId());
}
continue;
}*/
final BwEvent ocalEv = cei.getEvent();
if (((BwEventProxy) ocalEv).getRef().unsaved()) {
// New Override
try {
final String rid = oev.getRecurrenceId();
Date dt = new DateTime(rid);
if (calEv.getDtstart().getDateType()) {
// RECUR - fix all day recurrences sometime
if (rid.length() > 8) {
// Try to fix up bad all day recurrence ids. - assume a local timezone
((DateTime) dt).setTimeZone(null);
dt = new Date(dt.toString().substring(0, 8));
}
}
final DtStart st = new DtStart(dt);
final String tzid = calEv.getDtstart().getTzid();
if (tzid != null) {
final TimeZone tz = Timezones.getTz(tzid);
st.setTimeZone(tz);
}
ocalEv.setDtstart(BwDateTime.makeBwDateTime(st));
ocalEv.setDuration(calEv.getDuration());
ocalEv.setDtend(ocalEv.getDtstart().addDur(new Dur(calEv.getDuration())));
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
final BwAttendee ovatt = oev.findAttendee(attUri);
calAtt = ocalEv.findAttendee(attUri);
if (calAtt == null) {
// Organizer must have removed the attendee.
if (debug) {
trace("Skipping override " + attUri + " is not attending");
}
continue;
}
if (calAtt.changedBy(ovatt)) {
changed = true;
ocalEv.removeAttendee(ovatt);
calAtt = (BwAttendee) ovatt.clone();
calAtt.setScheduleStatus(getRstat(oev));
ocalEv.addAttendee(calAtt);
cte.addChangedValue(calAtt);
}
}
}
final boolean noinvites = !changed;
colEi.setReplyUpdate(true);
/* Update the organizer copy. This will broadcast the changes tp all
* attendees
*/
getSvc().getEventsHandler().update(colEi, noinvites, attUri);
return changed;
}
use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.
the class InRequest method updateAttendeeFields.
private boolean updateAttendeeFields(final EventInfo ourCopy, final EventInfo inBoxEi, final String attUri) throws CalFacadeException {
BwEvent ourEv = ourCopy.getEvent();
BwEvent inEv = inBoxEi.getEvent();
boolean flagNeedsReply = false;
ChangeTable chg = ourCopy.getChangeset(getPrincipalHref());
for (PropertyInfoIndex ipi : PropertyInfoIndex.values()) {
BwIcalPropertyInfoEntry bipie = BwIcalPropertyInfo.getPinfo(ipi);
if (bipie == null) {
continue;
}
if ((ourEv.getEntityType() == IcalDefs.entityTypeEvent) && !bipie.getEventProperty()) {
continue;
}
if ((ourEv.getEntityType() == IcalDefs.entityTypeTodo) && !bipie.getTodoProperty()) {
continue;
}
switch(ipi) {
case UNKNOWN_PROPERTY:
break;
case CLASS:
if (chg.changed(ipi, ourEv.getClassification(), inEv.getClassification())) {
ourEv.setClassification(inEv.getClassification());
}
break;
case COMPLETED:
/* Todo only */
if (chg.changed(ipi, ourEv.getCompleted(), inEv.getCompleted())) {
ourEv.setCompleted(inEv.getCompleted());
}
break;
case CREATED:
break;
case DESCRIPTION:
/*
for (BwLongString s: inEv.getDescriptions()) {
chg.addValue(Property.DESCRIPTION, s);
}
*/
if (chg.changed(ipi, ourEv.getDescription(), inEv.getDescription())) {
ourEv.setDescription(inEv.getDescription());
}
break;
case DTEND:
/* Event only */
case DUE:
/* Todo only */
BwDateTime dt = inEv.getDtend();
if (!CalFacadeUtil.eqObjval(ourEv.getDtend(), dt)) {
ourEv.setDtend(dt);
chg.changed(ipi, ourEv.getDtend(), dt);
}
char c = inEv.getEndType();
if (c != ourEv.getEndType()) {
ourEv.setEndType(c);
chg.changed(PropertyInfoIndex.END_TYPE, ourEv.getEndType(), c);
}
break;
case DTSTAMP:
break;
case DTSTART:
dt = inEv.getDtstart();
if (!CalFacadeUtil.eqObjval(ourEv.getDtstart(), dt)) {
ourEv.setDtstart(dt);
chg.changed(ipi, ourEv.getDtstart(), dt);
}
break;
case DURATION:
if (chg.changed(ipi, ourEv.getDuration(), inEv.getDuration())) {
ourEv.setDuration(inEv.getDuration());
}
break;
case GEO:
if (chg.changed(ipi, ourEv.getGeo(), inEv.getGeo())) {
ourEv.setGeo(inEv.getGeo());
}
break;
case LAST_MODIFIED:
break;
case LOCATION:
if (chg.changed(ipi, ourEv.getLocation(), inEv.getLocation())) {
ourEv.setLocation((BwLocation) inEv.getLocation().clone());
}
break;
case ORGANIZER:
if (chg.changed(ipi, ourEv.getOrganizer(), inEv.getOrganizer())) {
ourEv.setOrganizer((BwOrganizer) inEv.getOrganizer().clone());
}
break;
case PRIORITY:
if (chg.changed(ipi, ourEv.getPriority(), inEv.getPriority())) {
ourEv.setPriority(inEv.getPriority());
}
break;
case RECURRENCE_ID:
break;
case SEQUENCE:
if (chg.changed(ipi, ourEv.getSequence(), inEv.getSequence())) {
ourEv.setSequence(inEv.getSequence());
}
break;
case STATUS:
if (chg.changed(ipi, ourEv.getStatus(), inEv.getStatus())) {
ourEv.setStatus(inEv.getStatus());
}
break;
case SUMMARY:
/*
for (BwString s: inEv.getSummaries()) {
chg.addValue(Property.SUMMARY, s);
}
*/
if (chg.changed(ipi, ourEv.getSummary(), inEv.getSummary())) {
ourEv.setSummary(inEv.getSummary());
}
break;
case PERCENT_COMPLETE:
/* Todo only */
if (chg.changed(ipi, ourEv.getPercentComplete(), inEv.getPercentComplete())) {
ourEv.setPercentComplete(inEv.getPercentComplete());
}
break;
case UID:
break;
case URL:
if (chg.changed(ipi, ourEv.getLink(), inEv.getLink())) {
ourEv.setLink(inEv.getLink());
}
break;
case TRANSP:
/* Event only - done with attendee */
break;
case ATTACH:
break;
case ATTENDEE:
String transparency = ourEv.getTransparency();
BwAttendee ourAtt = null;
for (BwAttendee inAtt : inEv.getAttendees()) {
BwAttendee att = (BwAttendee) inAtt.clone();
att.setScheduleStatus(null);
String inAttUri = att.getAttendeeUri();
BwAttendee evAtt = ourEv.findAttendee(inAttUri);
if (inAttUri.equals(attUri)) {
// It's ours
ourAtt = att;
if ((att.getPartstat() == null) || att.getPartstat().equals(IcalDefs.partstatValNeedsAction)) {
transparency = IcalDefs.transparencyTransparent;
// Apple ical seems to expect an x-prop.
flagNeedsReply = true;
}
// att.setScheduleStatus(IcalDefs.deliveryStatusSuccess);
}
/* See if it's in the current set and if anything significant changed
for (BwAttendee calAtt: ourEv.getAttendees()) {
if (calAtt.getAttendeeUri().equals(inAttUri)) {
if (calAtt.changedBy(inAtt, false)) {
ourEv.setSignificantChange(true);
}
}
}*/
final ChangeTableEntry cte = chg.getEntry(PropertyInfoIndex.ATTENDEE);
if (evAtt != null) {
cte.addChangedValue(att);
} else {
cte.addAddedValue(att);
}
}
if (ourAtt == null) {
// Error?
if (debug) {
trace("InSchedule - no attendee for " + ourEv.getOwnerHref());
}
return false;
}
if (chg.changed(PropertyInfoIndex.TRANSP, ourEv.getTransparency(), transparency)) {
ourEv.setTransparency(transparency);
}
break;
case CATEGORIES:
if (!Util.isEmpty(inEv.getCategories())) {
for (BwCategory cat : inEv.getCategories()) {
chg.addValue(ipi, cat);
}
}
break;
case COMMENT:
for (BwString s : inEv.getComments()) {
chg.addValue(ipi, s);
}
break;
case CONTACT:
for (final BwContact ct : inEv.getContacts()) {
chg.addValue(ipi, ct.clone());
}
break;
case EXDATE:
// Don't updaye exdate - we add cancelled overrides
break;
case EXRULE:
// Only for master events
if (ourEv instanceof BwEventProxy) {
break;
}
for (final String s : inEv.getExrules()) {
chg.addValue(ipi, s);
}
break;
case REQUEST_STATUS:
break;
case RELATED_TO:
if (chg.changed(ipi, ourEv.getRelatedTo(), inEv.getRelatedTo())) {
ourEv.setRelatedTo(inEv.getRelatedTo());
}
break;
case RESOURCES:
for (BwString bs : inEv.getResources()) {
chg.addValue(ipi, bs);
}
break;
case RDATE:
// Only for master events
if (ourEv instanceof BwEventProxy) {
break;
}
for (BwDateTime bdt : inEv.getRdates()) {
chg.addValue(ipi, bdt);
}
break;
case RRULE:
// Only for master events
if (ourEv instanceof BwEventProxy) {
break;
}
for (String s : inEv.getRrules()) {
chg.addValue(ipi, s);
}
break;
case XPROP:
for (BwXproperty x : inEv.getXproperties()) {
chg.addValue(ipi, x);
}
break;
case FREEBUSY:
case TZID:
case TZNAME:
case TZOFFSETFROM:
case TZOFFSETTO:
case TZURL:
case ACTION:
case REPEAT:
case TRIGGER:
break;
// non ical
case COLLECTION:
// non ical
case COST:
// non ical
case CREATOR:
// non ical
case OWNER:
case // non ical
ENTITY_TYPE:
break;
case // Component
VALARM:
break;
// Param
case LANG:
case // Param
TZIDPAR:
break;
case PUBLISH_URL:
case POLL_ITEM_ID:
case END_TYPE:
case ETAG:
case HREF:
case XBEDEWORK_COST:
case CALSCALE:
case METHOD:
case PRODID:
case VERSION:
case ACL:
case AFFECTS_FREE_BUSY:
case ALIAS_URI:
case ATTENDEE_SCHEDULING_OBJECT:
case CALTYPE:
case COL_PROPERTIES:
case COLPATH:
case CTOKEN:
case DISPLAY:
case DOCTYPE:
case EVENTREG_END:
case EVENTREG_MAX_TICKETS:
case EVENTREG_MAX_TICKETS_PER_USER:
case EVENTREG_START:
case EVENTREG_WAIT_LIST_LIMIT:
case FILTER_EXPR:
case IGNORE_TRANSP:
case IMAGE:
case INDEX_END:
case INDEX_START:
case INSTANCE:
case LAST_REFRESH:
case LAST_REFRESH_STATUS:
case LOCATION_UID:
case LOCATION_STR:
break;
default:
warn("Not handling icalendar property " + ipi);
}
// switch
}
if (chg.changed(PropertyInfoIndex.COST, ourEv.getCost(), inEv.getCost())) {
ourEv.setCost(inEv.getCost());
}
/* Now see if we need to flag a schedule-tag change. We do so only if
* a. A property other than the attendee changed
* b. An attendee was added or removed
*/
Collection<ChangeTableEntry> changes = chg.getEntries();
ChangeTableEntry attChanges = null;
ourEv.setSignificantChange(false);
for (ChangeTableEntry cte : changes) {
if (!cte.getChanged()) {
continue;
}
if (cte.getIndex() == PropertyInfoIndex.ATTENDEE) {
attChanges = cte;
continue;
}
ourEv.setSignificantChange(true);
}
if (debug) {
trace("After change check getSignificantChange=" + ourEv.getSignificantChange());
}
if (flagNeedsReply) {
// Apple ical seems to expect an x-prop.
// chg.addValue(PropertyInfoIndex.XPROP,
// new BwXproperty(BwXproperty.appleNeedsReply,
// null, "TRUE"));
}
chg.processChanges(ourEv, true);
if (debug) {
trace(chg.toString());
}
/* The attendee change entry will now reflect the changes made to the
* attendee list. See if any significant change was made there.
*/
if (attChanges != null) {
if (!Util.isEmpty(attChanges.getAddedValues()) || !Util.isEmpty(attChanges.getRemovedValues())) {
ourEv.setSignificantChange(true);
} else {
/* TODO - go through the changed entries and look for our entry. See
* if we are being asked to reply - this can probably be done earlier.
*/
}
}
if (debug) {
trace("After attendee change check getSignificantChange=" + ourEv.getSignificantChange());
}
return true;
}
use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.
the class ImplicitSchedulingHandler method implicitSchedule.
@Override
public void implicitSchedule(final EventInfo ei, final boolean noInvites) throws CalFacadeException {
UpdateResult uer = ei.getUpdResult();
if (debug) {
dump(uer);
}
BwEvent ev = ei.getEvent();
boolean organizerSchedulingObject = ev.getOrganizerSchedulingObject();
boolean attendeeSchedulingObject = ev.getAttendeeSchedulingObject();
if (ev.getSuppressed()) {
if (!Util.isEmpty(ei.getOverrides())) {
for (EventInfo oei : ei.getOverrides()) {
uer = oei.getUpdResult();
if (debug) {
dump(uer);
}
BwEvent oev = oei.getEvent();
if (oev.getOrganizerSchedulingObject()) {
organizerSchedulingObject = true;
}
if (oev.getAttendeeSchedulingObject()) {
attendeeSchedulingObject = true;
}
}
}
}
if (!organizerSchedulingObject && !attendeeSchedulingObject) {
// Not a scheduling event
if (debug) {
trace("No a scheduling object: just return");
}
return;
}
if (ev.getOrganizer() == null) {
throw new CalFacadeBadRequest(CalFacadeException.missingEventProperty);
}
if (ev.getOriginator() == null) {
ev.setOriginator(ev.getOrganizer().getOrganizerUri());
}
if (uer.reply) {
int meth;
if (ei.getReplyAttendeeURI() != null) {
meth = ScheduleMethods.methodTypeRefresh;
} else {
meth = ScheduleMethods.methodTypeReply;
}
ev.setScheduleMethod(meth);
uer.schedulingResult = attendeeRespond(ei, meth);
return;
}
if (uer.deleting) {
if (organizerSchedulingObject) {
// if (schedMethod == Icalendar.methodTypeCancel) {
// /* We already canceled this one */
// return;
// }
ev.setScheduleMethod(ScheduleMethods.methodTypeCancel);
} else {
// Reply from attendee setting partstat
ev.setScheduleMethod(ScheduleMethods.methodTypeReply);
}
} else {
ev.setScheduleMethod(ScheduleMethods.methodTypeRequest);
}
if (!noInvites) {
uer.schedulingResult = schedule(ei, ei.getReplyAttendeeURI(), uer.fromAttUri, false);
}
if (!uer.adding && !Util.isEmpty(uer.deletedAttendees)) {
/* Send cancel to removed attendees */
for (BwAttendee att : uer.deletedAttendees) {
if (Util.compareStrings(att.getPartstat(), IcalDefs.partstats[IcalDefs.partstatDeclined]) == 0) {
// Already declined - send nothing
continue;
}
/* Clone is adequate here. For a CANCEL we just send either the master
* or the particular instance.
*/
BwEvent cncl = (BwEvent) ev.clone();
cncl.setAttendees(null);
cncl.addAttendee((BwAttendee) att.clone());
cncl.setRecipients(null);
cncl.addRecipient(att.getAttendeeUri());
cncl.setScheduleMethod(ScheduleMethods.methodTypeCancel);
cncl.setOrganizerSchedulingObject(true);
cncl.setAttendeeSchedulingObject(false);
EventInfo cei = new EventInfo(cncl);
ScheduleResult cnclr = schedule(cei, null, null, false);
if (debug) {
trace(cnclr.toString());
}
}
}
if (ei.getInboxEventName() != null) {
// Delete the given event from the inbox.
EventsI events = getSvc().getEventsHandler();
BwCalendar inbox = getSvc().getCalendarsHandler().getSpecial(BwCalendar.calTypeInbox, true);
final EventInfo inboxei = events.get(inbox.getPath(), ei.getInboxEventName());
if (inboxei != null) {
events.delete(inboxei, false);
}
}
}
use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.
the class SchedulingBase method copyEvent.
protected BwEvent copyEvent(final BwEvent origEv, final BwEvent masterEv, final BwPrincipal owner) throws CalFacadeException {
final BwEvent newEv;
BwEventProxy proxy = null;
final String ownerHref = owner.getPrincipalRef();
if (origEv instanceof BwEventProxy) {
proxy = (BwEventProxy) origEv;
if (masterEv == null) {
/* we are being asked to copy an instance of a recurring event - rather than
* a complete recurring event + all overrides - clone the master
*/
newEv = new BwEventObj();
origEv.copyTo(newEv);
newEv.setRecurring(false);
// Return the instance copy
proxy = null;
} else {
// Clone the annotation and set the master and target to our new master
// ANNOTATION
proxy = proxy.clone(masterEv, masterEv);
newEv = proxy.getRef();
}
} else {
// getSvc().reAttach(origEv);
newEv = (BwEvent) origEv.clone();
}
if (!Util.isEmpty(newEv.getAttendees())) {
for (BwAttendee att : newEv.getAttendees()) {
att.setScheduleStatus(null);
}
}
if (newEv.getOrganizer() != null) {
newEv.getOrganizer().setScheduleStatus(null);
}
newEv.setOwnerHref(ownerHref);
newEv.setCreatorHref(ownerHref);
newEv.setDtstamps(getCurrentTimestamp());
if (owner.equals(getPrincipal())) {
if (proxy != null) {
return proxy;
}
return newEv;
}
/* Copy event entities */
BwLocation loc = newEv.getLocation();
if (loc != null) {
loc = (BwLocation) loc.clone();
loc.setOwnerHref(ownerHref);
loc.setCreatorHref(ownerHref);
loc.initUid();
newEv.setLocation(loc);
}
BwContact contact = newEv.getContact();
if (contact != null) {
contact = (BwContact) contact.clone();
contact.setOwnerHref(ownerHref);
contact.setCreatorHref(ownerHref);
contact.initUid();
newEv.setContact(contact);
}
if (proxy != null) {
return proxy;
}
return newEv;
}
use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.
the class SchedulingBase method setupReschedule.
/* (non-Javadoc)
* @see org.bedework.calsvci.SchedulingI#setupReschedule(org.bedework.calfacade.svc.EventInfo)
*/
@Override
public void setupReschedule(final EventInfo ei) throws CalFacadeException {
BwEvent event = ei.getEvent();
BwAttendee userAttendee = findUserAttendee(event);
/* Set the PARTSTAT to needs action for all attendees - except us */
for (BwAttendee att : event.getAttendees()) {
if ((userAttendee != null) && att.equals(userAttendee)) {
continue;
}
att.setPartstat(IcalDefs.partstatValNeedsAction);
att.setRsvp(true);
}
}
Aggregations