Search in sources :

Example 1 with EventsI

use of org.bedework.calsvci.EventsI 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);
        }
    }
}
Also used : CalFacadeBadRequest(org.bedework.calfacade.exc.CalFacadeBadRequest) ScheduleResult(org.bedework.calfacade.ScheduleResult) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) EventsI(org.bedework.calsvci.EventsI) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult)

Aggregations

BwAttendee (org.bedework.calfacade.BwAttendee)1 BwCalendar (org.bedework.calfacade.BwCalendar)1 BwEvent (org.bedework.calfacade.BwEvent)1 ScheduleResult (org.bedework.calfacade.ScheduleResult)1 CalFacadeBadRequest (org.bedework.calfacade.exc.CalFacadeBadRequest)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1 UpdateResult (org.bedework.calfacade.svc.EventInfo.UpdateResult)1 EventsI (org.bedework.calsvci.EventsI)1