[Bedework-commit] webapps r371 - in trunk/webcommon/src/org/bedework/webcommon: . event schedule

svnadmin at bedework.org svnadmin at bedework.org
Wed May 16 13:46:01 EDT 2007


Author: douglm
Date: 2007-05-16 13:46:00 -0400 (Wed, 16 May 2007)
New Revision: 371

Modified:
   trunk/webcommon/src/org/bedework/webcommon/BwAbstractAction.java
   trunk/webcommon/src/org/bedework/webcommon/event/AttendeeAction.java
   trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeReply.java
   trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeRespond.java
Log:
Allow logins with accounts of the form /principals/resources/room301

For resource principals auto-respond to meeting requests. 

Incomplete, we should check for a preference rather than principal type. Also we should accept or refuse based on busy status of time period.


Modified: trunk/webcommon/src/org/bedework/webcommon/BwAbstractAction.java
===================================================================
--- trunk/webcommon/src/org/bedework/webcommon/BwAbstractAction.java	2007-05-15 14:57:55 UTC (rev 370)
+++ trunk/webcommon/src/org/bedework/webcommon/BwAbstractAction.java	2007-05-16 17:46:00 UTC (rev 371)
@@ -64,7 +64,6 @@
 import org.bedework.appcommon.MyCalendarVO;
 import org.bedework.appcommon.TimeView;
 import org.bedework.appcommon.ValidationError;
-import org.bedework.calfacade.BwAttendee;
 import org.bedework.calfacade.BwCalendar;
 import org.bedework.calfacade.BwCategory;
 import org.bedework.calfacade.BwDateTime;
@@ -448,15 +447,50 @@
 
   protected void emitScheduleStatus(BwActionFormBase form,
                                     ScheduleResult sr) {
+    if (sr.badMethod) {
+      form.getErr().emit(ValidationError.invalidSchedRequestMethod);
+    }
+
+    if (sr.badResponseMethod) {
+      form.getErr().emit(ValidationError.invalidSchedRespondMethod);
+    }
+
+    if (sr.badSourceCalendar) {
+      form.getErr().emit(ClientError.onlyFromInbox);
+    }
+
+    if (sr.noOriginator) {
+      form.getErr().emit(ValidationError.missingOriginator);
+    }
+
+    if (sr.unknownAttendee) {
+      form.getErr().emit(ClientError.unknownAttendee);
+    }
+
+    if (sr.invalidPartStatus) {
+      form.getErr().emit(ValidationError.invalidSchedPartStatus);
+    }
+
+    if (sr.multipleEvents) {
+      form.getErr().emit(ClientError.multipleEvents);
+    }
+
+    if (sr.duplicateUid) {
+      form.getErr().emit(ClientError.duplicateUid);
+    }
+
     if (sr.ignored) {
       form.getMsg().emit(ClientMessage.scheduleIgnored);
     }
+
     if (sr.reschedule) {
       form.getMsg().emit(ClientMessage.scheduleRescheduled);
     }
+
     if (sr.update) {
       form.getMsg().emit(ClientMessage.scheduleUpdated);
     }
+
     if (sr.added) {
       form.getMsg().emit(ClientMessage.scheduleAdded);
     }
@@ -1871,106 +1905,9 @@
   }
 
   /* ********************************************************************
-                             scheduling methods
+                             view methods
      ******************************************************************** */
 
-  protected int updateScheduleCalendar(BwCalendar cal,
-                                       BwEvent ev,
-                                       BwAttendee att,
-                                       BwActionFormBase form) throws CalFacadeException {
-    /* Add or update a copy of this event in the given calendar.
-     * Note: we could use an event reference but this would be incompatible
-     * with any caldav client
-     */
-    CalSvcI svc = form.fetchSvci();
-
-    // DORECUR is this right?
-    RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.overrides);
-    Collection evs = svc.getEvent(null, cal, ev.getUid(), ev.getRecurrenceId(),
-                                  rrm);
-    if (evs.size() > 1) {
-      form.getErr().emit(ClientError.multipleEvents);
-      svc.rollbackTransaction();
-      return forwardError;
-    }
-
-    if (evs.size() == 1) {
-      // Update
-
-      EventInfo ei = (EventInfo)evs.iterator().next();
-      BwEvent calEv = ei.getEvent();
-
-      // XXX We need some way of determining what changes were made - a
-      // change list?
-      calEv.updateFrom(ev);
-
-      CalFacadeUtil.updateCollection(ev.getAttendees(), calEv.getAttendees());
-
-      for (BwAttendee calAtt: calEv.getAttendees()) {
-        if (calAtt.equals(att)) {
-          att.copyTo(calAtt);
-          break;
-        }
-      }
-
-      svc.updateEvent(calEv, null, null);
-    } else {
-      BwEvent calEv = (BwEvent)ev.clone();
-      calEv.setOwner(svc.getUser());
-      calEv.setCalendar(cal);
-
-      try {
-        svc.addEvent(cal, calEv, null, false);
-      } catch (CalFacadeException cfe) {
-        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
-          form.getErr().emit(ClientError.duplicateUid);
-          svc.rollbackTransaction();
-          return forwardDuplicate;
-        }
-
-        throw cfe;
-      }
-    }
-
-    return forwardSuccess;
-  }
-
-  /** Find an attendee entry for the given user.
-   *
-   * @param svc
-   * @param ev
-   * @param cu
-   * @return BwAttendee or null if none exists
-   * @throws CalFacadeException
-   */
-  protected BwAttendee findAttendee(CalSvcI svc,
-                                    BwEvent ev,
-                                    BwUser cu) throws CalFacadeException {
-    return findAttendee(ev, svc.getDirectories().userToCaladdr(cu.getAccount()));
-  }
-
-  /** Find an attendee entry for the given uri (calendar address).
-   *
-   * @param ev
-   * @param uri
-   * @return BwAttendee or null if none exists
-   * @throws CalFacadeException
-   */
-  protected BwAttendee findAttendee(BwEvent ev,
-                                    String uri) throws CalFacadeException {
-    if (ev.getNumAttendees() == 0) {
-      return null;
-    }
-
-    for (BwAttendee att: ev.getAttendees()) {
-      if (uri.equals(att.getAttendeeUri())) {
-        return att;
-      }
-    }
-
-    return null;
-  }
-
   /** Set the current date and/or view. The date may be null indicating we
    * should switch to a new view based on the current date.
    *

Modified: trunk/webcommon/src/org/bedework/webcommon/event/AttendeeAction.java
===================================================================
--- trunk/webcommon/src/org/bedework/webcommon/event/AttendeeAction.java	2007-05-15 14:57:55 UTC (rev 370)
+++ trunk/webcommon/src/org/bedework/webcommon/event/AttendeeAction.java	2007-05-16 17:46:00 UTC (rev 371)
@@ -77,27 +77,32 @@
       return forwardNoAction;
     }
 
-    /* check for something that looks like mailto:somebody at somewhere.com,
+    if (svc.getDirectories().isPrincipal(uri)) {
+      // Leave as is
+      isAccount = true;
+    } else {
+      /* check for something that looks like mailto:somebody at somewhere.com,
        scheduleto:, etc.  If exists, is not an internal Bedework account. */
-    int colonPos = uri.indexOf(":");
-    int atPos = uri.indexOf("@");
+      int colonPos = uri.indexOf(":");
+      int atPos = uri.indexOf("@");
 
-    if (colonPos > 0) {
-      if (atPos < colonPos) {
+      if (colonPos > 0) {
+        if (atPos < colonPos) {
+          form.getErr().emit(ValidationError.invalidUser, uri);
+          return forwardNoAction;
+        }
+
+        isAccount = false;
+      } else if (atPos > 0) {
+        uri = "mailto:" + uri;
+      }
+
+      if (!BwWebUtil.validateUserHref(svc, uri)) {
         form.getErr().emit(ValidationError.invalidUser, uri);
         return forwardNoAction;
       }
-
-      isAccount = false;
-    } else if (atPos > 0) {
-      uri = "mailto:" + uri;
     }
 
-    if (!BwWebUtil.validateUserHref(svc, uri)) {
-      form.getErr().emit(ValidationError.invalidUser, uri);
-      return forwardNoAction;
-    }
-
     if (isAccount) {
       uri = svc.getDirectories().userToCaladdr(uri);
     }

Modified: trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeReply.java
===================================================================
--- trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeReply.java	2007-05-15 14:57:55 UTC (rev 370)
+++ trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeReply.java	2007-05-16 17:46:00 UTC (rev 371)
@@ -158,7 +158,7 @@
       } else if (calEv.getCalendar().getCalType() == BwCalendar.calTypeCollection) {
         /* Update the participation status from the incoming attendee */
 
-        BwAttendee outAtt = findAttendee(calEv, att.getAttendeeUri());
+        BwAttendee outAtt = calEv.findAttendee(att.getAttendeeUri());
         if (att == null) {
           form.getErr().emit(ClientError.unknownAttendee, cu);
           return forwardNoAction;

Modified: trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeRespond.java
===================================================================
--- trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeRespond.java	2007-05-15 14:57:55 UTC (rev 370)
+++ trunk/webcommon/src/org/bedework/webcommon/schedule/AttendeeRespond.java	2007-05-16 17:46:00 UTC (rev 371)
@@ -26,21 +26,14 @@
 package org.bedework.webcommon.schedule;
 
 import org.bedework.appcommon.ClientError;
-import org.bedework.appcommon.ValidationError;
-import org.bedework.calfacade.BwAttendee;
 import org.bedework.calfacade.BwCalendar;
 import org.bedework.calfacade.BwEvent;
-import org.bedework.calfacade.BwUser;
 import org.bedework.calfacade.ScheduleResult;
 import org.bedework.calsvci.CalSvcI;
-import org.bedework.icalendar.Icalendar;
 import org.bedework.webcommon.BwAbstractAction;
 import org.bedework.webcommon.BwActionFormBase;
 import org.bedework.webcommon.BwRequest;
 
-import java.util.Collection;
-import java.util.TreeSet;
-
 /**
  * Action to handle responses to scheduling requests - that is the schedule
  * method was REQUEST. We, as an attendee are going to resond to that request.
@@ -87,192 +80,36 @@
 
     CalSvcI svc = form.fetchSvci();
     BwEvent ev = form.getEvent();
+    String newCalPath = request.getReqPar("newCalPath");
+    BwCalendar evCal = null;
 
+    if (newCalPath != null) {
+      evCal = svc.getCalendar(newCalPath);
+      if (evCal == null) {
+        form.getErr().emit(ClientError.unknownCalendar, newCalPath);
+        return forwardValidationError;
+      }
+    } else {
+      // Use preferred calendar
+      evCal = svc.getPreferredCalendar();
+    }
+
     /* The event should have a calendar set to the inbox it came from.
      * That inbox may be owned by somebody other than the current user if a
      * calendar user has delegated control of their inbox to some other user
      * e.g. secretary.
      */
 
-    if ((ev == null) || (ev.getScheduleMethod() != Icalendar.methodTypeRequest)) {
-      form.getErr().emit(ValidationError.invalidSchedRequestMethod);
-      return forwardNoAction;
-    }
+    ScheduleResult sr = svc.attendeeRespond(ev,
+                                            ev.getCalendar(),
+                                            request.getReqPar("delegate"),
+                                            request.getReqPar("method"),
+                                            request.getReqPar("partstat"),
+                                            evCal,
+                                            request.getReqPar("comment"),
+                                            request.getBooleanReqPar("rsvp", false));
 
-    BwCalendar inbox = ev.getCalendar();
-
-    if (inbox.getCalType() != BwCalendar.calTypeInbox) {
-      form.getErr().emit(ClientError.onlyFromInbox);
-      return forwardNoAction;
-    }
-
-    if (ev.getOriginator() == null) {
-      form.getErr().emit(ValidationError.missingOriginator);
-      return forwardNoAction;
-    }
-
-    BwUser cu = inbox.getOwner();
-
-    String delegate = request.getReqPar("delegate");
-    int method = Icalendar.methodTypeNone;
-
-    if (delegate == null) {
-      method = Icalendar.findMethodType(request.getReqPar("method"));
-
-      if (!Icalendar.itipReplyMethodType(method)) {
-        form.getErr().emit(ValidationError.invalidSchedRespondMethod);
-        return forwardNoAction;
-      }
-    }
-
-    BwEvent outEv = (BwEvent)ev.clone();
-
-    // Non-null if user wants event put in a calendar
-    BwCalendar evCal = null;
-
-    int fwdi = setEventCalendar(request, form, outEv);
-    if ((fwdi != forwardNoAction) &&
-        (fwdi != forwardSuccess)) {
-      return fwdi;
-    }
-
-    if (fwdi == forwardSuccess) {
-      // event calendar was specified and has been embedded in the event.
-      evCal = outEv.getCalendar();
-      if (evCal.equals(inbox)) {
-        // Didn't really change
-        evCal = null;
-      }
-    }
-
-    String comment = request.getReqPar("comment");
-    if (comment != null) {
-      // Just add for the moment
-      ev.addComment(null, comment);
-    }
-
-    BwAttendee att = findAttendee(svc, outEv, cu);
-    if (att == null) {
-      form.getErr().emit(ClientError.unknownAttendee, cu);
-      return forwardNoAction;
-    }
-
-    outEv.setRecipients(new TreeSet<String>());
-    outEv.addRecipient(outEv.getOriginator());
-    outEv.setOriginator(svc.getDirectories().userToCaladdr(cu.getAccount()));
-    outEv.updateDtstamp();
-
-    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);
-
-      String dcalAddr = svc.getDirectories().userToCaladdr(delegate);
-      att.setParticipationStatus(BwAttendee.partstatdelegated);
-      att.setDelegatedTo(dcalAddr);
-
-      // Additonal attendee
-      BwAttendee delAtt = new BwAttendee();
-      delAtt.setAttendeeUri(dcalAddr);
-      delAtt.setDelegatedFrom(att.getAttendeeUri());
-      delAtt.setParticipationStatus(BwAttendee.partstatNeedsAction);
-      delAtt.setRole(att.getRole());
-      outEv.addAttendee(delAtt);
-
-      /* The attendee may indicate they wish to continue to receive
-       * notification by setting rsvp = true
-       */
-      att.setRsvp(request.getBooleanReqPar("rsvp", false));
-
-      // ev is 'original "REQUEST"'. */
-      BwEvent delEv = (BwEvent)ev.clone();
-
-      delEv.setRecipients(new TreeSet<String>());
-      delEv.addRecipient(dcalAddr);
-      delEv.addAttendee((BwAttendee)delAtt.clone()); // Not in RFC
-
-      att = findAttendee(svc, delEv, cu);
-      if (att == null) {
-        form.getErr().emit(ClientError.unknownAttendee, cu);
-        return forwardNoAction;
-      }
-
-      att.setParticipationStatus(BwAttendee.partstatdelegated);
-      att.setDelegatedTo(dcalAddr);
-
-      // Not sure if this is correct
-      svc.schedule(delEv);
-    } else if (method == Icalendar.methodTypeRefresh) {
-      // We're just sending it back to the originator with a refresh method
-
-      outEv.setScheduleMethod(Icalendar.methodTypeRefresh);
-    } else if (method == Icalendar.methodTypeReply) {
-      // Expect a valid partstat for the attendee corresponding to the inbox
-      // the event came from.
-      int partStat = BwAttendee.checkPartstat(request.getReqPar("partstat"));
-
-      if ((partStat != BwAttendee.partstatAccepted) &&
-          (partStat != BwAttendee.partstatDeclined) &&
-          (partStat != BwAttendee.partstatTentative)) {
-        form.getErr().emit(ValidationError.invalidSchedPartStatus, partStat);
-        return forwardNoAction;
-      }
-
-      // Update the status - will affect incoming event object.
-      att.setParticipationStatus(partStat);
-
-      // Remove all participants except us
-
-      outEv.setAttendees(null);
-      outEv.addAttendee((BwAttendee)att.clone());
-
-      outEv.setScheduleMethod(Icalendar.methodTypeReply);
-    } else if (method == Icalendar.methodTypeCounter) {
-      /* Not sure how much we can change - at least times of the meeting.
-       */
-    } else {
-      throw new RuntimeException("Never get here");
-    }
-
-    ScheduleResult sr = svc.scheduleResponse(outEv);
-    outEv.setScheduleState(BwEvent.scheduleStateProcessed);
-    emitScheduleStatus(form, sr);
-
-    if (evCal != null) {
-      int res = updateScheduleCalendar(evCal, ev, att, form);
-      if (res != forwardSuccess) {
-        return res;
-      }
-    }
-
-    ev.setScheduleState(BwEvent.scheduleStateProcessed);
-    svc.updateEvent(ev, null, null);
-
+    /*
     Collection<String> cals = request.getReqPars("updateCals");
 
     if (cals == null) {
@@ -290,6 +127,8 @@
         }
       }
     }
+    */
+    emitScheduleStatus(form, sr);
 
     return forwardSuccess;
   }



More information about the Bedework-commit mailing list