[Bedework-commit] r441 - in trunk/calendar3: calCore/resources/hbms calCore/src/org/bedework/calcore/hibernate webclient/src/org/bedework/webclient webclient/war/WEB-INF

svnadmin at bedework.org svnadmin at bedework.org
Tue May 2 16:27:22 EDT 2006


Author: douglm
Date: 2006-05-02 16:27:21 -0400 (Tue, 02 May 2006)
New Revision: 441

Modified:
   trunk/calendar3/calCore/resources/hbms/EventAnnotation.hbm.xml
   trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java
   trunk/calendar3/webclient/src/org/bedework/webclient/BwAddEventRefAction.java
   trunk/calendar3/webclient/src/org/bedework/webclient/BwEventAction.java
   trunk/calendar3/webclient/war/WEB-INF/struts-config.xml
Log:
Fix dup eventref

Modified: trunk/calendar3/calCore/resources/hbms/EventAnnotation.hbm.xml
===================================================================
--- trunk/calendar3/calCore/resources/hbms/EventAnnotation.hbm.xml	2006-05-02 19:48:52 UTC (rev 440)
+++ trunk/calendar3/calCore/resources/hbms/EventAnnotation.hbm.xml	2006-05-02 20:27:21 UTC (rev 441)
@@ -219,5 +219,9 @@
       where ev.name = :name and ev.calendar = :cal
   ]]></query>
   -->
+  <query name="getGuidCountCalendarAnnotation"><![CDATA[
+    select count(*) from org.bedework.calfacade.BwEventAnnotation as ev
+      where ev.calendar=:cal and ev.guid = :guid
+  ]]></query>
 </hibernate-mapping>
 

Modified: trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java
===================================================================
--- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java	2006-05-02 19:48:52 UTC (rev 440)
+++ trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java	2006-05-02 20:27:21 UTC (rev 441)
@@ -332,14 +332,8 @@
      *
      * It also ensures our guid allocation is working OK
      */
-    sess.namedQuery("getGuidCountCalendar");
-    sess.setEntity("cal", val.getCalendar());
-    sess.setString("guid", val.getGuid());
-
-    Collection refs = sess.getList();
-
-    Integer ct = (Integer)refs.iterator().next();
-    if (ct.intValue() > 0) {
+    if ((countCalendarGuids("getGuidCountCalendar", val) > 0) ||
+        (countCalendarGuids("getGuidCountCalendarAnnotation", val) > 0)) {
       throw new CalFacadeException(CalFacadeException.duplicateGuid);
     }
 
@@ -437,6 +431,19 @@
     sess.saveOrUpdate(val);
   }
 
+  private int countCalendarGuids(String queryName, BwEvent val) throws CalFacadeException {
+    HibSession sess = getSess();
+
+    sess.namedQuery(queryName);
+    sess.setEntity("cal", val.getCalendar());
+    sess.setString("guid", val.getGuid());
+
+    Collection refs = sess.getList();
+
+    Integer ct = (Integer)refs.iterator().next();
+    return ct.intValue();
+  }
+
   public void updateEvent(BwEvent val) throws CalFacadeException {
     HibSession sess = getSess();
     if (!(val instanceof BwEventProxy)) {

Modified: trunk/calendar3/webclient/src/org/bedework/webclient/BwAddEventRefAction.java
===================================================================
--- trunk/calendar3/webclient/src/org/bedework/webclient/BwAddEventRefAction.java	2006-05-02 19:48:52 UTC (rev 440)
+++ trunk/calendar3/webclient/src/org/bedework/webclient/BwAddEventRefAction.java	2006-05-02 20:27:21 UTC (rev 441)
@@ -57,6 +57,7 @@
 import org.bedework.appcommon.BedeworkDefs;
 import org.bedework.calfacade.BwCalendar;
 import org.bedework.calfacade.BwEventProxy;
+import org.bedework.calfacade.CalFacadeException;
 import org.bedework.calfacade.svc.EventInfo;
 import org.bedework.calsvci.CalSvcI;
 
@@ -69,6 +70,7 @@
  * <p>Forwards to:<ul>
  *      <li>"doNothing"    when request seems wrong.</li>
  *      <li>"notPersonal"  when this is not a personal calendar.</li>
+ *      <li>"duplicate"    duplicate guid.</li>
  *      <li>"success"      added ok.</li>
  * </ul>
  */
@@ -99,17 +101,26 @@
 
     BwCalendar cal = svci.getPreferredCalendar();
     proxy.setOwner(svci.getUser());
-    svci.addEvent(cal, proxy, null);
 
-    form.getMsg().emit("org.bedework.client.message.added.eventrefs", 1);
+    try {
+      svci.addEvent(cal, proxy, null);
+      form.getMsg().emit("org.bedework.client.message.added.eventrefs", 1);
 
-    BwGoToAction.gotoDateView(this, form,
-                  proxy.getDtstart().getDate().substring(0, 8),
-                  BedeworkDefs.dayView,
-                  debug);
+      BwGoToAction.gotoDateView(this, form,
+                                proxy.getDtstart().getDate().substring(0, 8),
+                                BedeworkDefs.dayView,
+                                debug);
 
-    form.refreshIsNeeded();
+      form.refreshIsNeeded();
 
-    return "success";
+      return "success";
+    } catch (CalFacadeException cfe) {
+      if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
+        form.getErr().emit("org.bedework.client.error.duplicate.guid");
+        return "duplicate";
+      }
+
+      throw cfe;
+    }
   }
 }

Modified: trunk/calendar3/webclient/src/org/bedework/webclient/BwEventAction.java
===================================================================
--- trunk/calendar3/webclient/src/org/bedework/webclient/BwEventAction.java	2006-05-02 19:48:52 UTC (rev 440)
+++ trunk/calendar3/webclient/src/org/bedework/webclient/BwEventAction.java	2006-05-02 20:27:21 UTC (rev 441)
@@ -63,6 +63,7 @@
  * Action to set up an event for display.
  * <p>Request parameters<ul>
  *      <li>"subid"    subscription id for event.</li>
+ *      <li>"calPath"  calendar for event.</li>
  *      <li>"guid"     guid of event.</li>
  *      <li>"recurrenceId"   recurrence-id of event instance - possibly null.</li>
  * </ul>

Modified: trunk/calendar3/webclient/war/WEB-INF/struts-config.xml
===================================================================
--- trunk/calendar3/webclient/war/WEB-INF/struts-config.xml	2006-05-02 19:48:52 UTC (rev 440)
+++ trunk/calendar3/webclient/war/WEB-INF/struts-config.xml	2006-05-02 20:27:21 UTC (rev 441)
@@ -265,7 +265,7 @@
     </action>
 
     <action    path="/addEventRef"
-               type="org.bedework.webclient.BwInitEventAction"
+               type="org.bedework.webclient.BwEventAction"
                name="calForm"
                scope="session"
                validate="false">
@@ -277,6 +277,7 @@
                name="calForm"
                scope="session"
                validate="false">
+      <forward name="duplicate" path="/showMain.rdo" redirect="true" />
     </action>
 
     <action    path="/event/selectCalForEvent"



More information about the Bedework-commit mailing list