Search in sources :

Example 66 with BwEvent

use of org.bedework.calfacade.BwEvent 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 67 with BwEvent

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

the class OrganizerSchedulingHandler method declineCounter.

@Override
public ScheduleResult declineCounter(final EventInfo ei, final String comment, final BwAttendee fromAtt) throws CalFacadeException {
    final EventInfo outEi = copyEventInfo(ei, getPrincipal());
    final BwEvent ev = outEi.getEvent();
    ev.setScheduleMethod(ScheduleMethods.methodTypeDeclineCounter);
    if (comment != null) {
        ev.addComment(null, comment);
    }
    return schedule(outEi, fromAtt.getAttendeeUri(), null, false);
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent)

Example 68 with BwEvent

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

the class OutboundSchedulingHandler method addToInbox.

/**
 * Add a copy of senderEi to the users inbox and add to the autoschedule queue.
 * The 'sender' may be the organizer of a meeting, if it's REQUEST etc, or the
 * attendee replying.
 *
 * @param inboxPath - eventual destination
 * @param attPrincipal - attendees principal
 * @param senderEi the event
 * @param fromOrganizer - true if it's coming from the organizer
 * @return null for ok, errorcode otherwise
 * @throws CalFacadeException
 */
private String addToInbox(final String inboxPath, final BwPrincipal attPrincipal, final EventInfo senderEi, final boolean fromOrganizer) throws CalFacadeException {
    final EventInfo ei = copyEventInfo(senderEi, fromOrganizer, attPrincipal);
    final BwEvent ev = ei.getEvent();
    if (senderEi.getReplyUpdate()) {
        // Flag as a trivial update to attendee status
        ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedulingReplyUpdate, null, "true"));
    }
    if (!Util.isEmpty(ev.getRecipients())) {
        ev.getRecipients().clear();
    }
    ev.addRecipient(getSvc().getDirectories().principalToCaladdr(attPrincipal));
    /*
    if (destAtt != null) {
      String attPartStat = destAtt.getPartstat();

      if ((attPartStat == null) ||   // default - needs-action
          (!attPartStat.equalsIgnoreCase(IcalDefs.partstatValAccepted) &&
           !attPartStat.equalsIgnoreCase(IcalDefs.partstatValCompleted) &&
           !attPartStat.equalsIgnoreCase(IcalDefs.partstatValDelegated))) {
        ev.setTransparency(IcalDefs.transparencyTransparent);
      }
    }*/
    final String evDtstamp = ev.getDtstamp();
    ev.setScheduleState(BwEvent.scheduleStateNotProcessed);
    ev.setColPath(inboxPath);
    if (ei.getNumContainedItems() > 0) {
        for (final EventInfo cei : ei.getContainedItems()) {
            cei.getEvent().setColPath(inboxPath);
        }
    }
    /* Before we add this we should see if there is an earlier one we can
     * discard. As attendees update their status we get many requests sent to
     * each attendee.
     *
     * Also this current message may be earlier than one already in the inbox.
     *
     * TODO - fix recurrences
     *
     * We could get separate messages for the same uid but with different
     * recurrence ids if we are an attendee to some instances only.
     *
     * In the inbox these will be separate events with the same uid -
     * possibly, They probably need to be combined in the users
     * calendar as a single recurring event.
     */
    final int smethod = ev.getScheduleMethod();
    if (Icalendar.itipRequestMethodType(smethod)) {
        final Collection<EventInfo> inevs = getEventsByUid(inboxPath, ev.getUid());
        for (final EventInfo inei : inevs) {
            final BwEvent inev = inei.getEvent();
            final int cres = evDtstamp.compareTo(inev.getDtstamp());
            if (cres <= 0) {
                // Discard the new one
                return null;
            }
            /* Discard the earlier message */
            /* XXX What if this message is currently being processed by the inbox
         * handler process? Does it matter - will it reappear?
         *
         * Probably need to handle stale-state exceptions at the other end.
         */
            deleteEvent(inei, true, false);
        }
    }
    /* Add it and post to the autoscheduler */
    final String ecode = addEvent(ei, "In-" + Uid.getUid() + "-" + evDtstamp, BwCalendar.calTypePendingInbox, true);
    if (ecode != null) {
        return ecode;
    }
    if (debug) {
        trace("Add event with name " + ev.getName() + " and summary " + ev.getSummary() + " to " + ev.getColPath());
    }
    addAutoScheduleMessage(true, attPrincipal.getPrincipalRef(), ev.getName());
    return null;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwEvent(org.bedework.calfacade.BwEvent)

Example 69 with BwEvent

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

the class Scheduling method getStoredMeeting.

/* (non-Javadoc)
   * @see org.bedework.calsvci.SchedulingI#getStoredMeeting(org.bedework.calfacade.BwEvent)
   */
@Override
public EventInfo getStoredMeeting(final BwEvent ev) throws CalFacadeException {
    final String preferred = getSvc().getCalendarsHandler().getPreferred(IcalDefs.entityTypeIcalNames[ev.getEntityType()]);
    if (preferred == null) {
        throw new CalFacadeException(CalFacadeException.schedulingNoCalendar);
    }
    if (debug) {
        debug("Look for event " + ev.getUid() + " in " + preferred);
    }
    final Collection<EventInfo> evs = getSvc().getEventsHandler().getByUid(preferred, ev.getUid(), null, RecurringRetrievalMode.overrides);
    if (Util.isEmpty(evs)) {
        return null;
    }
    for (final EventInfo ei : evs) {
        final BwEvent e = ei.getEvent();
        // Skip anything other than a calendar collection
        final BwCalendar evcal = getSvc().getCalendarsHandler().get(e.getColPath());
        if (!evcal.getCollectionInfo().scheduling) {
            continue;
        }
        if (e.getOrganizerSchedulingObject() || e.getAttendeeSchedulingObject()) {
            return ei;
        }
        if (e.getSuppressed()) {
            // See if the overrrides are scheduling objects
            for (final BwEvent oe : ei.getOverrideProxies()) {
                if (oe.getOrganizerSchedulingObject() || oe.getAttendeeSchedulingObject()) {
                    return ei;
                }
            }
        }
    }
    // Not found.
    return null;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 70 with BwEvent

use of org.bedework.calfacade.BwEvent 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;
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) BwEvent(org.bedework.calfacade.BwEvent) BwContact(org.bedework.calfacade.BwContact) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10