[Bedework-commit] r469 - in trunk/calendar3: calCore/src/org/bedework/calcore/hibernate calFacade/src/org/bedework/calfacade/base calFacade/src/org/bedework/calfacade/ifs caldav/src/edu/rpi/cct/uwcal/caldav calsvc/src/org/bedework/calsvc config/configs icalendar/src/org/bedework/icalendar

svnadmin at bedework.org svnadmin at bedework.org
Fri May 12 12:37:23 EDT 2006


Author: douglm
Date: 2006-05-12 12:37:23 -0400 (Fri, 12 May 2006)
New Revision: 469

Modified:
   trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java
   trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
   trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java
   trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java
   trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java
   trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java
   trunk/calendar3/config/configs/democal.options.xml
   trunk/calendar3/config/configs/democal.properties
   trunk/calendar3/icalendar/src/org/bedework/icalendar/IcalTranslator.java
Log:
Change getSpecialCalendar to optionally create. Avoids hibernate problem.

Change free/busy response to be at caldav12

Modified: trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java
===================================================================
--- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java	2006-05-12 16:37:23 UTC (rev 469)
@@ -284,7 +284,8 @@
   }
 
   public BwCalendar getSpecialCalendar(BwUser user,
-                                       int calType) throws CalFacadeException {
+                                       int calType,
+                                       boolean create) throws CalFacadeException {
     StringBuffer sb = new StringBuffer();
     String name;
     BwSystem sys = getSyspars();
@@ -315,7 +316,7 @@
 
     BwCalendar cal = getCalendar(sb.toString(), privRead);
 
-    if (cal != null) {
+    if ((cal != null) || !create) {
       return cal;
     }
 

Modified: trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
===================================================================
--- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java	2006-05-12 16:37:23 UTC (rev 469)
@@ -870,8 +870,9 @@
   }
 
   public BwCalendar getSpecialCalendar(BwUser user,
-                                       int calType) throws CalFacadeException {
-    return calendars.getSpecialCalendar(user, calType);
+                                       int calType,
+                                       boolean create) throws CalFacadeException {
+    return calendars.getSpecialCalendar(user, calType, create);
   }
 
   public void addCalendar(BwCalendar val, String parentPath) throws CalFacadeException {
@@ -1122,10 +1123,10 @@
   }
 
   public Collection getDeletedProxies() throws CalFacadeException {
-    BwCalendar cal = getSpecialCalendar(user, BwCalendar.calTypeDeleted);
+    BwCalendar cal = getSpecialCalendar(user, BwCalendar.calTypeDeleted, false);
 
     if (cal == null) {
-      // Not supported
+      // Not supported or never deleted anything
       return new ArrayList();
     }
 

Modified: trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java
===================================================================
--- trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java	2006-05-12 16:37:23 UTC (rev 469)
@@ -472,7 +472,8 @@
   }
 
   public BwCalendar getSpecialCalendar(BwUser user,
-                                       int calType) throws CalFacadeException {
+                                       int calType,
+                                       boolean create) throws CalFacadeException {
     throw new CalFacadeUnimplementedException();
   }
 

Modified: trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java
===================================================================
--- trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java	2006-05-12 16:37:23 UTC (rev 469)
@@ -187,11 +187,13 @@
    *
    * @param  user
    * @param  calType   int special calendar type.
+   * @param  create    true if we shoudl create it if non-existant.
    * @return BwCalendar null for unknown calendar
    * @throws CalFacadeException
    */
   public BwCalendar getSpecialCalendar(BwUser user,
-                                       int calType) throws CalFacadeException;
+                                       int calType,
+                                       boolean create) throws CalFacadeException;
 
   /** Add a calendar object
    *

Modified: trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java
===================================================================
--- trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/ReportMethod.java	2006-05-12 16:37:23 UTC (rev 469)
@@ -75,6 +75,8 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import java.io.Reader;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -139,7 +141,11 @@
       trace("ReportMethod: depth=" + depth);
     }
 
-    processResp(req, resp, depth);
+    if (reportType == reportTypeFreeBusy) {
+      processFbResp(req, resp);
+    } else {
+      processResp(req, resp, depth);
+    }
   }
 
   /* ====================================================================
@@ -385,15 +391,6 @@
           }
         }
       }
-    } else if (reportType == reportTypeFreeBusy) {
-      try {
-        nodes = intf.getFreeBusy(node, freeBusy);
-      } catch (WebdavException wde) {
-        if (debug) {
-          trace("intf.getFreeBusy exception");
-        }
-        status = wde.getStatusCode();
-      }
     } else if (reportType == reportTypeExpandProperty) {
     }
 
@@ -418,6 +415,122 @@
     flush();
   }
 
+  /** Handle free/busy response
+   *
+   * @param req
+   * @param resp
+   * @param depth
+   * @throws WebdavException
+   */
+  public void processFbResp(HttpServletRequest req,
+                            HttpServletResponse resp) throws WebdavException {
+    resp.setStatus(HttpServletResponse.SC_OK);
+    resp.setContentType("text/calendar; charset=UTF-8");
+
+    String resourceUri = getResourceUri(req);
+
+    CaldavBWIntf intf = (CaldavBWIntf)getNsIntf();
+    WebdavNsNode node = intf.getNode(resourceUri);
+
+    int status = HttpServletResponse.SC_OK;
+
+    Collection nodes = null;
+
+    try {
+      nodes = intf.getFreeBusy(node, freeBusy);
+    } catch (WebdavException wde) {
+      if (debug) {
+        trace("intf.getFreeBusy exception");
+      }
+      status = wde.getStatusCode();
+    }
+
+    if (status != HttpServletResponse.SC_OK) {
+      if (debug) {
+        trace("REPORT status " + status);
+      }
+      // Entire request failed.
+      node.setStatus(status);
+      doNode(node);
+    } else if (nodes != null) {
+      Iterator it = nodes.iterator();
+
+      // XXX Only one node?
+      while (it.hasNext()) {
+        WebdavNsNode curnode = (WebdavNsNode)it.next();
+
+        if (!(node instanceof CaldavCalNode)) {
+          if (debug) {
+            trace("Expected CaldavCalNode - got " + node);
+          }
+          status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+        } else {
+          CaldavCalNode cnode = (CaldavCalNode)node;
+
+          Writer out;
+          try {
+            out = resp.getWriter();
+          } catch (Throwable t) {
+            throw new WebdavException(t);
+          }
+
+          /** Get the content now to set up length, type etc.
+           */
+          Reader in = getNsIntf().getContent(node);
+          resp.setContentLength(node.getContentLen());
+          if (in == null) {
+            if (debug) {
+              debugMsg("status: " + HttpServletResponse.SC_NO_CONTENT);
+            }
+
+            resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+          } else {
+            if (debug) {
+              debugMsg("send content - length=" + node.getContentLen());
+            }
+
+            writeContent(in, out);
+          }
+        }
+      }
+    }
+
+    flush();
+  }
+
+  // XXX Make the following part of the interface.
+
+  /** size of buffer used for copying content to response.
+   */
+  private static final int bufferSize = 4096;
+
+  private void writeContent(Reader in, Writer out)
+      throws WebdavException {
+    try {
+      char[] buff = new char[bufferSize];
+      int len;
+
+      while (true) {
+        len = in.read(buff);
+
+        if (len < 0) {
+          break;
+        }
+
+        out.write(buff, 0, len);
+      }
+    } catch (Throwable t) {
+      throw new WebdavException(t);
+    } finally {
+      try {
+        in.close();
+      } catch (Throwable t) {}
+      try {
+        out.close();
+      } catch (Throwable t) {}
+    }
+  }
+
   /* Apply a node to a parsed request - or the other way - whatever.
    */
   private void doNode(WebdavNsNode node) throws WebdavException {
@@ -439,17 +552,6 @@
             error(wde);
           }
         }
-      } else if (reportType == reportTypeFreeBusy) {
-        if (!(node instanceof CaldavCalNode)) {
-          if (debug) {
-            trace("Expected CaldavCalNode - got " + node);
-          }
-          status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
-        } else {
-          CaldavCalNode cnode = (CaldavCalNode)node;
-
-          content = cnode.getContentString();
-        }
       }
     }
 

Modified: trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java
===================================================================
--- trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java	2006-05-12 16:37:23 UTC (rev 469)
@@ -1701,7 +1701,8 @@
       // Have write access - just set the flag and move it into the owners trash
       event.setDeleted(true);
       event.setCalendar(getCal().getSpecialCalendar(event.getOwner(),
-                                                    BwCalendar.calTypeTrash));
+                                                    BwCalendar.calTypeTrash,
+                                                    true));
       updateEvent(event);
       return;
     }
@@ -1711,10 +1712,10 @@
     BwEventProxy proxy = BwEventProxy.makeAnnotation(event, event.getOwner());
 
     // Where does the ref go? Not in the same calendar - we have no access
-    // Put it in the trash - but don't delete on empty trash
 
     BwCalendar cal = getCal().getSpecialCalendar(getUser(),
-                                                 BwCalendar.calTypeTrash);
+                                                 BwCalendar.calTypeDeleted,
+                                                 true);
     proxy.setOwner(getUser());
     proxy.setDeleted(true);
     proxy.setCalendar(cal);

Modified: trunk/calendar3/config/configs/democal.options.xml
===================================================================
--- trunk/calendar3/config/configs/democal.options.xml	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/config/configs/democal.options.xml	2006-05-12 16:37:23 UTC (rev 469)
@@ -37,7 +37,7 @@
 
         <defaultUserViewName>All</defaultUserViewName>
 
-        <publicUser>user</publicUser>
+        <publicUser>public-user</publicUser>
 
         <httpConnectionsPerUser>10</httpConnectionsPerUser>
         <httpConnectionsPerHost>50</httpConnectionsPerHost>

Modified: trunk/calendar3/config/configs/democal.properties
===================================================================
--- trunk/calendar3/config/configs/democal.properties	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/config/configs/democal.properties	2006-05-12 16:37:23 UTC (rev 469)
@@ -213,7 +213,6 @@
 org.bedework.app.dumpres.zip.name=dumpres
 org.bedework.app.dumpres.description=Bedework dump/restore utility
 org.bedework.app.dumpres.version=3.1
-org.bedework.app.dumpres.dumpfile=${calendar.dir}/dumprestore/initcaldata.xml
 org.bedework.app.dumpres.hibernate.dialect=org.hibernate.dialect.HSQLDialect
 org.bedework.app.dumpres.jdbcdriver=org.hsqldb.jdbcDriver
 org.bedework.app.dumpres.jdbcurl=jdbc:hsqldb:hsql://localhost:8887

Modified: trunk/calendar3/icalendar/src/org/bedework/icalendar/IcalTranslator.java
===================================================================
--- trunk/calendar3/icalendar/src/org/bedework/icalendar/IcalTranslator.java	2006-05-11 20:09:15 UTC (rev 468)
+++ trunk/calendar3/icalendar/src/org/bedework/icalendar/IcalTranslator.java	2006-05-12 16:37:23 UTC (rev 469)
@@ -56,6 +56,7 @@
 
 import org.bedework.calfacade.BwCalendar;
 import org.bedework.calfacade.BwEvent;
+import org.bedework.calfacade.BwFreeBusy;
 import org.bedework.calfacade.BwUser;
 import org.bedework.calfacade.CalFacadeException;
 import org.bedework.calfacade.svc.EventInfo;
@@ -68,6 +69,7 @@
 //import net.fortuna.ical4j.data.UnfoldingReader;
 import net.fortuna.ical4j.model.Calendar;
 import net.fortuna.ical4j.model.component.VEvent;
+import net.fortuna.ical4j.model.component.VFreeBusy;
 import net.fortuna.ical4j.model.component.VTimeZone;
 import net.fortuna.ical4j.model.Component;
 import net.fortuna.ical4j.model.ComponentList;
@@ -80,6 +82,7 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -259,11 +262,9 @@
     }
   }
 
-  /** Convert the given string representation of an Icalendar object to an EventVO
+  /** Convert the given string representation of an Icalendar object to a
+   * Collection of Calendar objects
    *
-   * <p>Because an icalendar object can contain 0 or more VEvents we return
-   * a collection of events which may be empty.
-   *
    * @param cal       calendar
    * @param val
    * @return Collection
@@ -271,24 +272,6 @@
    */
   public Collection fromIcal(BwCalendar cal, String val) throws CalFacadeException {
     return fromIcal(cal, new StringReader(val));
-    /*
-    try {
-      CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl());
-
-      UnfoldingReader ufrdr = new UnfoldingReader(new StringReader(val), true);
-
-      //return fromIcal(cal, bldr.build(new UnfoldingReader(new StringReader(val))));
-      return fromIcal(cal, bldr.build(ufrdr));
-    } catch (ParserException pe) {
-      if (debug) {
-        error(pe);
-      }
-      throw new IcalMalformedException(pe.getMessage());
-    } catch (CalFacadeException cfe) {
-      throw cfe;
-    } catch (Throwable t) {
-      throw new CalFacadeException(t);
-    }*/
   }
 
   /** Convert the Icalendar reader to a Collection of Calendar objects
@@ -325,7 +308,7 @@
    * @throws CalFacadeException
    */
   public Collection fromIcal(BwCalendar cal, Calendar val) throws CalFacadeException {
-    Vector objs = new Vector();
+    ArrayList objs = new ArrayList();
 
     if (val == null) {
       return objs;
@@ -344,6 +327,14 @@
         if (ev != null) {
           objs.add(ev);
         }
+      } else if (o instanceof VFreeBusy) {
+        BwFreeBusy fb = BwFreeBusyUtil.toFreeBusy(cb,
+                                                  (VFreeBusy)o,
+                                                  debug);
+
+        if (fb != null) {
+          objs.add(fb);
+        }
       } else if (o instanceof VTimeZone) {
         doTimeZone((VTimeZone)o);
       }



More information about the Bedework-commit mailing list