[Bedework-commit] calendarapi r627 - in trunk: calCore/resources/hbms calCore/src/org/bedework/calcore/hibernate calFacade/src/org/bedework/calfacade/exc calsvc/src/org/bedework/calsvc calsvc/src/org/bedework/calsvc/indexing calsvci/src/org/bedework/calsvci icalendar/src/org/bedework/icalendar

svnadmin at bedework.org svnadmin at bedework.org
Wed May 21 14:55:00 EDT 2008


Author: douglm
Date: 2008-05-21 14:54:56 -0400 (Wed, 21 May 2008)
New Revision: 627

Modified:
   trunk/calCore/resources/hbms/Calendar.hbm.xml
   trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java
   trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java
   trunk/calsvc/src/org/bedework/calsvc/Calendars.java
   trunk/calsvc/src/org/bedework/calsvc/Users.java
   trunk/calsvc/src/org/bedework/calsvc/Views.java
   trunk/calsvc/src/org/bedework/calsvc/indexing/BwIndexLuceneImpl.java
   trunk/calsvci/src/org/bedework/calsvci/CalendarsI.java
   trunk/calsvci/src/org/bedework/calsvci/UsersI.java
   trunk/calsvci/src/org/bedework/calsvci/ViewsI.java
   trunk/icalendar/src/org/bedework/icalendar/IcalTranslator.java
Log:
Fix bug in lucene indexing which caused failure for collections

All a noindexing option on restore

Speed up indexing on restore by batching user indexers.

Index collections on restore

Show time spent indexing

Remove cascades option in schema for calendar children. Requires we manage that collection ourselves but avoids inefficiencies.

Add some more tests and tidy up some of the api methods.

Add code to delete a user entry.

Modified: trunk/calCore/resources/hbms/Calendar.hbm.xml
===================================================================
--- trunk/calCore/resources/hbms/Calendar.hbm.xml	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calCore/resources/hbms/Calendar.hbm.xml	2008-05-21 18:54:56 UTC (rev 627)
@@ -73,7 +73,7 @@
       <column name="parent" />
     </many-to-one>
 
-    <set name="children" inverse="true" cascade="save-update"
+    <set name="children" inverse="true"
          lazy="true"
          order-by="calname" >
       <cache usage="read-write"/>

Modified: trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java
===================================================================
--- trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -460,6 +460,7 @@
     }
 
     parent.removeChild(val);
+    sess.delete(val);
     sess.update(parent);
 
     return true;
@@ -585,6 +586,9 @@
 
     parent.addChild(val);
 
+    // No cascades - explicitly save child
+    sess.save(val);
+
     sess.update(parent);
 
     notifications.post(SysEvent.makeCalendarChangeEvent(SysEvent.SysCode.CALENDAR_ADDED,

Modified: trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -174,6 +174,10 @@
   public static final String cannotDeleteCalendarRoot =
       "org.bedework.exception.cannotdeletecalendarroot";
 
+  /** */
+  public static final String cannotDeleteDefaultCalendar =
+      "org.bedework.exception.cannotdeletedefaultcalendar";
+
   /* ****************** Subscriptions ****************************** */
 
   /** Somebody tried to create a duplicate subscription */

Modified: trunk/calsvc/src/org/bedework/calsvc/Calendars.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Calendars.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calsvc/src/org/bedework/calsvc/Calendars.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -220,19 +220,19 @@
   /* (non-Javadoc)
    * @see org.bedework.calsvci.CalendarsI#delete(org.bedework.calfacade.BwCalendar, boolean)
    */
-  public int delete(BwCalendar val,
+  public boolean delete(BwCalendar val,
                     boolean emptyIt) throws CalFacadeException {
     if (!emptyIt) {
       /** Only allow delete if not in use
        */
       if (!getSvc().getCal().isEmpty(val)) {
-        return 2;
+        throw new CalFacadeException(CalFacadeException.calendarNotEmpty);
       }
     }
 
     BwPreferences prefs = getSvc().getPrefsHandler().get(val.getOwner());
     if (val.getPath().equals(prefs.getDefaultCalendarPath())) {
-      return 2;
+      throw new CalFacadeException(CalFacadeException.cannotDeleteDefaultCalendar);
     }
 
     /* Remove from preferences */
@@ -249,21 +249,18 @@
       }
 
       for (BwCalendar cal: getChildren(val)) {
-        int res = delete(cal, true);
-        if (res != 0) {
+        if (!delete(cal, true)) {
+          // Somebody else at it
           getSvc().rollbackTransaction();
-          return res;
+          throw new CalFacadeException(CalFacadeException.calendarNotFound,
+                                       cal.getPath());
         }
       }
     }
 
     /* Attempt to delete
      */
-    if (getSvc().getCal().deleteCalendar(val)) {
-      return 0;
-    }
-
-    return 1; //doesn't exist
+    return getSvc().getCal().deleteCalendar(val);
   }
 
   /* (non-Javadoc)

Modified: trunk/calsvc/src/org/bedework/calsvc/Users.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Users.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calsvc/src/org/bedework/calsvc/Users.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -26,6 +26,7 @@
 package org.bedework.calsvc;
 
 import org.bedework.calcorei.HibSession;
+import org.bedework.calfacade.BwCalendar;
 import org.bedework.calfacade.BwUser;
 import org.bedework.calfacade.CalFacadeDefs;
 import org.bedework.calfacade.exc.CalFacadeException;
@@ -117,6 +118,51 @@
     initUser(user);
   }
 
+  /* (non-Javadoc)
+   * @see org.bedework.calsvci.UsersI#remove(org.bedework.calfacade.BwUser)
+   */
+  public void remove(BwUser user) throws CalFacadeException {
+    String userRoot = getUserRootPath(user);
+
+    /* views */
+
+    Collection<BwView> views = getSvc().getViewsHandler().getAll(user);
+    for (BwView view: views) {
+      Collection<BwSubscription> subs = view.getSubscriptions();
+      for (BwSubscription sub: subs) {
+        getSvc().getViewsHandler().removeSubscription(view.getName(), user, sub);
+      }
+      getSvc().getViewsHandler().remove(view);
+    }
+
+    /* Subscriptions */
+
+    Collection<BwSubscription> subs = getSvc().getSubscriptionsHandler().getAll(user);
+    for (BwSubscription sub: subs) {
+      getSvc().getSubscriptionsHandler().delete(sub);
+    }
+
+    /* Set default calendar to null so we don't get blocked. */
+    BwPreferences prefs = getSvc().getPrefsHandler().get(user);
+
+    if (prefs != null) {
+      prefs.setDefaultCalendarPath(null);
+      getSvc().getPrefsHandler().update(prefs);
+    }
+
+    /* collections and user home */
+
+    BwCalendar home = getSvc().getCalendarsHandler().get(userRoot);
+    if (home != null) {
+      getSvc().getCalendarsHandler().delete(home, true);
+    }
+
+    /* Remove preferences */
+    getSvc().getPrefsHandler().delete(prefs);
+
+    getSess().delete(user);
+  }
+
   public Collection<BwUser> getInstanceOwners() throws CalFacadeException {
     HibSession sess = getSess();
 

Modified: trunk/calsvc/src/org/bedework/calsvc/Views.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Views.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calsvc/src/org/bedework/calsvc/Views.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -79,10 +79,10 @@
       return false;
     }
 
-    BwPreferences prefs = getSvc().getPrefsHandler().get();
+    BwPreferences prefs = getSvc().getPrefsHandler().get(val.getOwner());
     checkOwnerOrSuper(prefs);
 
-    setupOwnedEntity(val, getUser());
+    //setupOwnedEntity(val, getUser());
 
     Collection<BwView> views = prefs.getViews();
     if ((views == null) || (!views.contains(val))) {
@@ -151,7 +151,13 @@
    */
   public boolean removeSubscription(String name,
                                     BwSubscription sub) throws CalFacadeException {
-    BwPreferences prefs = getSvc().getPrefsHandler().get();
+    return removeSubscription(name, getUser(), sub);
+  }
+
+  public boolean removeSubscription(String name,
+                                    BwUser user,
+                                    BwSubscription sub) throws CalFacadeException {
+    BwPreferences prefs = getSvc().getPrefsHandler().get(user);
     checkOwnerOrSuper(prefs);
 
     BwView view = find(name);
@@ -177,4 +183,15 @@
     }
     return c;
   }
+
+  /* (non-Javadoc)
+   * @see org.bedework.calsvci.ViewsI#getAll(org.bedework.calfacade.BwUser)
+   */
+  public Collection<BwView> getAll(BwUser user) throws CalFacadeException {
+    Collection<BwView> c = getSvc().getPrefsHandler().get(user).getViews();
+    if (c == null) {
+      c = new TreeSet<BwView>();
+    }
+    return c;
+  }
 }

Modified: trunk/calsvc/src/org/bedework/calsvc/indexing/BwIndexLuceneImpl.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/indexing/BwIndexLuceneImpl.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calsvc/src/org/bedework/calsvc/indexing/BwIndexLuceneImpl.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -451,10 +451,15 @@
     rec.addField(BwIndexLuceneDefs.owner, owner.getAccount());
     rec.addField(BwIndexLuceneDefs.summary, summary);
 
-    rec.addField(BwIndexLuceneDefs.startDate, start.substring(0, 8));
-    rec.addField(BwIndexLuceneDefs.endDate, end.substring(0, 8));
-    rec.addField(BwIndexLuceneDefs.dueDate, end.substring(0, 8));
+    if (start != null) {
+      rec.addField(BwIndexLuceneDefs.startDate, start.substring(0, 8));
+    }
 
+    if (end != null) {
+      rec.addField(BwIndexLuceneDefs.endDate, end.substring(0, 8));
+      rec.addField(BwIndexLuceneDefs.dueDate, end.substring(0, 8));
+    }
+
     if (recurringStarts != null) {
       for (String dt: recurringStarts) {
         rec.addField(BwIndexLuceneDefs.startDate, dt.substring(0, 8));

Modified: trunk/calsvci/src/org/bedework/calsvci/CalendarsI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/CalendarsI.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calsvci/src/org/bedework/calsvci/CalendarsI.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -204,13 +204,12 @@
    *
    * @param val      BwCalendar calendar
    * @param emptyIt  true to delete contents
-   * @return int     0 if it was deleted.
-   *                 1 if it didn't exist
-   *                 2 if in use
-   * @throws CalFacadeException
+   * @return boolean  true if it was deleted.
+   *                  false if it didn't exist
+   * @throws CalFacadeException for in use or marked as default calendar
    */
-  public int delete(BwCalendar val,
-                    boolean emptyIt) throws CalFacadeException;
+  public boolean delete(BwCalendar val,
+                        boolean emptyIt) throws CalFacadeException;
 
   /** Return true if cal != null and it represents a (local) user root
    *

Modified: trunk/calsvci/src/org/bedework/calsvci/UsersI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/UsersI.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calsvci/src/org/bedework/calsvci/UsersI.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -60,6 +60,13 @@
    */
   public void add(String account) throws CalFacadeException;
 
+  /** Remove a user. This will delete all traces of the user from the system.
+   *
+   * @param user
+   * @throws CalFacadeException
+   */
+  public void remove(BwUser user) throws CalFacadeException;
+
   /** Returns a Collection of instance owners.
    *
    * @return Collection    of BwUser

Modified: trunk/calsvci/src/org/bedework/calsvci/ViewsI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/ViewsI.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/calsvci/src/org/bedework/calsvci/ViewsI.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -25,6 +25,7 @@
 */
 package org.bedework.calsvci;
 
+import org.bedework.calfacade.BwUser;
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calfacade.svc.BwSubscription;
 import org.bedework.calfacade.svc.BwView;
@@ -39,55 +40,75 @@
  */
 public interface ViewsI extends Serializable {
   /** Add a view.
-  *
-  * @param  val           BwView to add
-  * @param  makeDefault   boolean true for make this the default.
-  * @return boolean false view not added, true - added.
-  * @throws CalFacadeException
-  */
- public boolean add(BwView val,
-                    boolean makeDefault) throws CalFacadeException;
+   *
+   * @param  val           BwView to add
+   * @param  makeDefault   boolean true for make this the default.
+   * @return boolean false view not added, true - added.
+   * @throws CalFacadeException
+   */
+  public boolean add(BwView val,
+                     boolean makeDefault) throws CalFacadeException;
 
- /** Remove the view.
-  *
-  * @param  val     BwView
-  * @return boolean false - view not found.
-  * @throws CalFacadeException
-  */
- public boolean remove(BwView val) throws CalFacadeException;
+  /** Remove the view for the owner of the object.
+   *
+   * @param  val     BwView
+   * @return boolean false - view not found.
+   * @throws CalFacadeException
+   */
+  public boolean remove(BwView val) throws CalFacadeException;
 
- /** Find the named view.
-  *
-  * @param  val     String view name - null means default
-  * @return BwView  null view not found.
-  * @throws CalFacadeException
-  */
- public BwView find(String val) throws CalFacadeException;
+  /** Find the named view.
+   *
+   * @param  val     String view name - null means default
+   * @return BwView  null view not found.
+   * @throws CalFacadeException
+   */
+  public BwView find(String val) throws CalFacadeException;
 
- /** Add a subscription to the named view.
-  *
-  * @param  name    String view name - null means default
-  * @param  sub     BwSubscription to add
-  * @return boolean false view not found, true - subscription added.
-  * @throws CalFacadeException
-  */
- public boolean addSubscription(String name,
-                                BwSubscription sub) throws CalFacadeException;
+  /** Add a subscription to the named view.
+   *
+   * @param  name    String view name - null means default
+   * @param  sub     BwSubscription to add
+   * @return boolean false view not found, true - subscription added.
+   * @throws CalFacadeException
+   */
+  public boolean addSubscription(String name,
+                                 BwSubscription sub) throws CalFacadeException;
 
- /** Remove a subscription from the named view.
-  *
-  * @param  name    String view name - null means default
-  * @param  sub     BwSubscription to add
-  * @return boolean false view not found, true - subscription added.
-  * @throws CalFacadeException
-  */
- public boolean removeSubscription(String name,
-                                   BwSubscription sub) throws CalFacadeException;
+  /** Remove a subscription from the named view.
+   *
+   * @param  name    String view name - null means default
+   * @param  sub     BwSubscription to add
+   * @return boolean false view not found, true - subscription added.
+   * @throws CalFacadeException
+   */
+  public boolean removeSubscription(String name,
+                                    BwSubscription sub) throws CalFacadeException;
 
- /** Return the collection of views - named collections of subscriptions
-  *
-  * @return collection of views
-  * @throws CalFacadeException
-  */
- public Collection<BwView> getAll() throws CalFacadeException;
+  /** Remove a subscription from the named view for the given user.
+   *
+   * @param  name    String view name - null means default
+   * @param  user
+   * @param  sub     BwSubscription to add
+   * @return boolean false view not found, true - subscription added.
+   * @throws CalFacadeException
+   */
+  public boolean removeSubscription(String name,
+                                    BwUser user,
+                                    BwSubscription sub) throws CalFacadeException;
+
+  /** Return the collection of views - named collections of subscriptions
+   *
+   * @return collection of views
+   * @throws CalFacadeException
+   */
+  public Collection<BwView> getAll() throws CalFacadeException;
+
+  /** Return the collection of views - named collections of subscriptions
+   *
+   * @param user
+   * @return collection of views
+   * @throws CalFacadeException
+   */
+  public Collection<BwView> getAll(BwUser user) throws CalFacadeException;
 }

Modified: trunk/icalendar/src/org/bedework/icalendar/IcalTranslator.java
===================================================================
--- trunk/icalendar/src/org/bedework/icalendar/IcalTranslator.java	2008-05-21 18:52:28 UTC (rev 626)
+++ trunk/icalendar/src/org/bedework/icalendar/IcalTranslator.java	2008-05-21 18:54:56 UTC (rev 627)
@@ -120,7 +120,7 @@
 
   /* This needs to come from a property updated with each release.
    */
-  protected static final String prodId = "BedeWork V3.4";
+  protected static final String prodId = "BedeWork V3.5";
 
   protected transient Logger log;
 



More information about the Bedework-commit mailing list