Search in sources :

Example 1 with ScheduleResult

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

the class BwSysIntfImpl method requestFreeBusy.

@Override
public Collection<SchedRecipientResult> requestFreeBusy(final CalDAVEvent val, final boolean iSchedule) throws WebdavException {
    try {
        ScheduleResult sr;
        BwEvent ev = getEvent(val);
        if (currentPrincipal != null) {
            ev.setOwnerHref(currentPrincipal.getPrincipalRef());
        }
        if (Icalendar.itipReplyMethodType(ev.getScheduleMethod())) {
            sr = getSvci().getScheduler().scheduleResponse(getEvinfo(val));
        } else {
            sr = getSvci().getScheduler().schedule(getEvinfo(val), null, null, iSchedule);
        }
        return checkStatus(sr);
    } catch (CalFacadeAccessException cfae) {
        if (debug) {
            error(cfae);
        }
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ScheduleResult(org.bedework.calfacade.ScheduleResult) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with ScheduleResult

use of org.bedework.calfacade.ScheduleResult 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)

Example 3 with ScheduleResult

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

the class OrganizerSchedulingHandler method schedule.

@Override
public ScheduleResult schedule(final EventInfo ei, final String recipient, final String fromAttUri, final boolean iSchedule) throws CalFacadeException {
    /* A request (that is we are (re)sending a meeting request) or a publish
     *
     * <p>We handle the following iTIP methods<ul>
     * <li>ADD</li>
     * <li>CANCEL</li>
     * <li>DECLINECOUNTER</li>
     * <li>PUBLISH</li>
     * <li>REQUEST</li>
     * </ul>
     *
     * <p>That is, messages from organizer to attendee(s)
     *
     * <pre>
     * Do the usual checks and init
     * For each recipient
     *    If internal to system, add to their inbox
     *    otherwise add to list of external recipients
     *
     * If any external recipients - leave in outbox with unprocessed status.
     * </pre>
     */
    final ScheduleResult sr = new ScheduleResult();
    final BwEvent ev = ei.getEvent();
    try {
        if (!Icalendar.itipRequestMethodType(ev.getScheduleMethod())) {
            sr.errorCode = CalFacadeException.schedulingBadMethod;
            return sr;
        }
        /* For each recipient within this system add the event to their inbox.
       *
       * If there are any external users add it to the outbox and it will be
       * mailed to the recipients.
       */
        final int outAccess;
        final boolean freeBusyRequest = ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy;
        if (freeBusyRequest) {
            // freebusy
            outAccess = PrivilegeDefs.privScheduleFreeBusy;
        } else {
            outAccess = PrivilegeDefs.privScheduleRequest;
        }
        if (!initScheduleEvent(ei, false, iSchedule)) {
            return sr;
        }
        /* Do this here to check we have access. We might need the outbox later
       */
        BwCalendar outBox = null;
        final BwPrincipal currentUser = getPrincipal();
        if (!currentUser.getUnauthenticated()) {
            outBox = getSpecialCalendar(getPrincipal(), BwCalendar.calTypeOutbox, true, outAccess);
        }
        sendSchedule(sr, ei, recipient, fromAttUri, true);
        if ((sr.errorCode != null) || sr.ignored) {
            return sr;
        }
        // if (freeBusyRequest && !imipFreeBusyOk) {
        if (freeBusyRequest) {
            // Don't ever email freebusy requests
            return sr;
        }
        if (!iSchedule && // We have something to mail
        (outBox != null) && (!Util.isEmpty(sr.externalRcs))) {
            sr.errorCode = addToOutBox(ei, outBox, sr.externalRcs);
        }
        return sr;
    } catch (final Throwable t) {
        getSvc().rollbackTransaction();
        if (t instanceof CalFacadeException) {
            throw (CalFacadeException) t;
        }
        throw new CalFacadeException(t);
    }
}
Also used : ScheduleResult(org.bedework.calfacade.ScheduleResult) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 4 with ScheduleResult

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

the class BwSysIntfImpl method schedule.

@Override
public Collection<SchedRecipientResult> schedule(final CalDAVEvent ev) throws WebdavException {
    try {
        ScheduleResult sr;
        BwEvent event = getEvent(ev);
        event.setOwnerHref(currentPrincipal.getPrincipalRef());
        if (Icalendar.itipReplyMethodType(event.getScheduleMethod())) {
            sr = getSvci().getScheduler().scheduleResponse(getEvinfo(ev));
        } else {
            sr = getSvci().getScheduler().schedule(getEvinfo(ev), null, null, // iSchedule
            true);
        }
        return checkStatus(sr);
    } catch (WebdavException we) {
        throw we;
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ScheduleResult(org.bedework.calfacade.ScheduleResult) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 5 with ScheduleResult

use of org.bedework.calfacade.ScheduleResult 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;
}
Also used : ScheduleResult(org.bedework.calfacade.ScheduleResult) EventInfo(org.bedework.calfacade.svc.EventInfo) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)9 ScheduleResult (org.bedework.calfacade.ScheduleResult)9 EventInfo (org.bedework.calfacade.svc.EventInfo)6 BwAttendee (org.bedework.calfacade.BwAttendee)5 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 BwCalendar (org.bedework.calfacade.BwCalendar)3 BwRequestStatus (org.bedework.calfacade.BwRequestStatus)3 BwString (org.bedework.calfacade.BwString)3 BwEventObj (org.bedework.calfacade.BwEventObj)2 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)2 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)1 CalFacadeBadRequest (org.bedework.calfacade.exc.CalFacadeBadRequest)1 UpdateResult (org.bedework.calfacade.svc.EventInfo.UpdateResult)1 SchedulingIntf (org.bedework.calsvc.scheduling.SchedulingIntf)1 EventsI (org.bedework.calsvci.EventsI)1