Search in sources :

Example 41 with BwAttendee

use of org.bedework.calfacade.BwAttendee in project bw-calendar-engine by Bedework.

the class SchedAttendeeUpdate method attendeeRespond.

private ScheduleResult attendeeRespond(final EventInfo ei, final int method) throws CalFacadeException {
    ScheduleResult sr = new ScheduleResult();
    final BwEvent ev = ei.getEvent();
    final SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
    final String attUri = getSvc().getDirectories().principalToCaladdr(getSvc().getPrincipal());
    check: {
        /* Check that the current user is actually an attendee of the event.
       * Note we may have a suppressed master and/or multiple overrides
       */
        BwAttendee att = null;
        if (!ev.getSuppressed()) {
            att = ev.findAttendee(attUri);
            if (att == null) {
                sr.errorCode = CalFacadeException.schedulingNotAttendee;
                break check;
            }
        }
        if (ei.getNumOverrides() > 0) {
            for (final EventInfo oei : ei.getOverrides()) {
                att = oei.getEvent().findAttendee(attUri);
                if (att == null) {
                    sr.errorCode = CalFacadeException.schedulingNotAttendee;
                    break check;
                }
            }
        }
        if (ev.getOriginator() == null) {
            sr.errorCode = CalFacadeException.schedulingNoOriginator;
            break check;
        }
        // EventInfo outEi = makeReplyEventInfo(ei, getUser().getPrincipalRef());
        final EventInfo outEi = sched.copyEventInfo(ei, getPrincipal());
        final BwEvent outEv = outEi.getEvent();
        if (!Util.isEmpty(outEv.getRecipients())) {
            outEv.getRecipients().clear();
        }
        if (!Util.isEmpty(outEv.getAttendees())) {
            outEv.getAttendees().clear();
        }
        // XXX we should get a comment from non db field in event
        // if (comment != null) {
        // // Just add for the moment
        // outEv.addComment(null, comment);
        // }
        outEv.addRecipient(outEv.getOrganizer().getOrganizerUri());
        outEv.setOriginator(att.getAttendeeUri());
        outEv.updateDtstamp();
        outEv.getOrganizer().setDtstamp(outEv.getDtstamp());
        final String delegate = att.getDelegatedTo();
        if (delegate != null) {
            /* RFC 2446 4.2.5 - Delegating an event
         *
         * When delegating an event request to another "Calendar User", the
         * "Delegator" must both update the "Organizer" with a "REPLY" and send
         * a request to the "Delegate". There is currently no protocol
         * limitation to delegation depth. It is possible for the original
         * delegate to delegate the meeting to someone else, and so on. When a
         * request is delegated from one CUA to another there are a number of
         * responsibilities required of the "Delegator". The "Delegator" MUST:
         *
         *   .  Send a "REPLY" to the "Organizer" with the following updates:
         *   .  The "Delegator's" "ATTENDEE" property "partstat" parameter set
         *      to "delegated" and the "delegated-to" parameter is set to the
         *      address of the "Delegate"
         *   .  Add an additional "ATTENDEE" property for the "Delegate" with
         *      the "delegated-from" property parameter set to the "Delegator"
         *   .  Indicate whether they want to continue to receive updates when
         *      the "Organizer" sends out updated versions of the event.
         *      Setting the "rsvp" property parameter to "TRUE" will cause the
         *      updates to be sent, setting it to "FALSE" causes no further
         *      updates to be sent. Note that in either case, if the "Delegate"
         *      declines the invitation the "Delegator" will be notified.
         *   .  The "Delegator" MUST also send a copy of the original "REQUEST"
         *      method to the "Delegate".
         */
            // outEv is the reply
            outEv.setScheduleMethod(Icalendar.methodTypeReply);
            // Additional attendee
            final BwAttendee delAtt = new BwAttendee();
            delAtt.setAttendeeUri(delegate);
            delAtt.setDelegatedFrom(att.getAttendeeUri());
            delAtt.setPartstat(IcalDefs.partstatValNeedsAction);
            delAtt.setRsvp(true);
            delAtt.setRole(att.getRole());
            outEv.addAttendee(delAtt);
            // ei is 'original "REQUEST"'. */
            final EventInfo delegateEi = sched.copyEventInfo(ei, getPrincipal());
            final BwEvent delegateEv = delegateEi.getEvent();
            delegateEv.addRecipient(delegate);
            // Not in RFC
            delegateEv.addAttendee((BwAttendee) delAtt.clone());
            delegateEv.setScheduleMethod(Icalendar.methodTypeRequest);
            att.setPartstat(IcalDefs.partstatValDelegated);
            att.setRsvp(false);
            att.setDelegatedTo(delegate);
            // XXX Not sure if this is correct
            sched.schedule(delegateEi, null, null, false);
        } else if (method == Icalendar.methodTypeReply) {
            // Only attendee should be us
            ei.setOnlyAttendee(outEi, att.getAttendeeUri());
            outEv.setScheduleMethod(Icalendar.methodTypeReply);
        } else if (method == Icalendar.methodTypeCounter) {
            // Only attendee should be us
            ei.setOnlyAttendee(outEi, att.getAttendeeUri());
            /* Not sure how much we can change - at least times of the meeting.
         */
            outEv.setScheduleMethod(Icalendar.methodTypeCounter);
        } else {
            throw new RuntimeException("Never get here");
        }
        outEv.addRequestStatus(new BwRequestStatus(IcalDefs.requestStatusSuccess.getCode(), IcalDefs.requestStatusSuccess.getDescription()));
        sr = sched.scheduleResponse(outEi);
        outEv.setScheduleState(BwEvent.scheduleStateProcessed);
        ev.getOrganizer().setScheduleStatus(IcalDefs.deliveryStatusDelivered);
    }
    return sr;
}
Also used : ScheduleResult(org.bedework.calfacade.ScheduleResult) EventInfo(org.bedework.calfacade.svc.EventInfo) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) BwEvent(org.bedework.calfacade.BwEvent) SchedulingIntf(org.bedework.calsvc.scheduling.SchedulingIntf) BwAttendee(org.bedework.calfacade.BwAttendee)

Aggregations

BwAttendee (org.bedework.calfacade.BwAttendee)41 BwEvent (org.bedework.calfacade.BwEvent)25 EventInfo (org.bedework.calfacade.svc.EventInfo)19 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)17 BwString (org.bedework.calfacade.BwString)10 BwOrganizer (org.bedework.calfacade.BwOrganizer)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 Period (net.fortuna.ical4j.model.Period)6 BwDateTime (org.bedework.calfacade.BwDateTime)6 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)6 PropertyList (net.fortuna.ical4j.model.PropertyList)5 BwEventObj (org.bedework.calfacade.BwEventObj)5 TreeSet (java.util.TreeSet)4 DateTime (net.fortuna.ical4j.model.DateTime)4 PeriodList (net.fortuna.ical4j.model.PeriodList)4 Property (net.fortuna.ical4j.model.Property)4 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)4 FreeBusy (net.fortuna.ical4j.model.property.FreeBusy)4 BwCalendar (org.bedework.calfacade.BwCalendar)4 BwCategory (org.bedework.calfacade.BwCategory)4