[Bedework-commit] calendarapi r246 - in trunk: calCore/resources/hbms calCore/src/org/bedework/calcore/hibernate calFacade/src/org/bedework/calfacade icalendar/src/org/bedework/icalendar

svnadmin at bedework.org svnadmin at bedework.org
Sun Apr 1 22:01:12 EDT 2007


Author: douglm
Date: 2007-04-01 22:01:05 -0400 (Sun, 01 Apr 2007)
New Revision: 246

Modified:
   trunk/calCore/resources/hbms/Alarm.hbm.xml
   trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java
   trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java
   trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java
   trunk/icalendar/src/org/bedework/icalendar/VAlarmUtil.java
Log:
Changes so that alarm time range filtering works. Can now query for all alarms with a trigger in a given time period.

Requires small schema change - alarm trigger-time and previous_trigger fields are now String(16), not long

Modified: trunk/calCore/resources/hbms/Alarm.hbm.xml
===================================================================
--- trunk/calCore/resources/hbms/Alarm.hbm.xml	2007-04-01 04:44:23 UTC (rev 245)
+++ trunk/calCore/resources/hbms/Alarm.hbm.xml	2007-04-02 02:01:05 UTC (rev 246)
@@ -109,8 +109,8 @@
                     foreign-key="bw_aa_att_fk"/>
     </set>
 
-    <property name="triggerTime" column="trigger_time" type="long" />
-    <property name="previousTrigger" column="previous_trigger" type="long" />
+    <property name="triggerTime" column="trigger_time" type="string" length="16" />
+    <property name="previousTrigger" column="previous_trigger" type="string" length="16" />
     <property name="repeatCount" column="repeat_count" type="integer" />
 
     <property name="expired" type="true_false">

Modified: trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java
===================================================================
--- trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java	2007-04-01 04:44:23 UTC (rev 245)
+++ trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java	2007-04-02 02:01:05 UTC (rev 246)
@@ -353,7 +353,7 @@
           String subfld = "unknown";
 
           if (pi.getPindex() == PropertyInfoIndex.VALARM) {
-            subfld = "trigger";
+            subfld = "triggerTime";
           }
 
           doTimeRange((BwTimeRangeFilter)pf, false, fld, subfld);

Modified: trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java	2007-04-01 04:44:23 UTC (rev 245)
+++ trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java	2007-04-02 02:01:05 UTC (rev 246)
@@ -62,14 +62,12 @@
 import org.bedework.calfacade.util.CalFacadeUtil;
 
 import net.fortuna.ical4j.model.Dur;
+import net.fortuna.ical4j.model.property.Duration;
 import net.fortuna.ical4j.model.property.Trigger;
 
 import java.io.Serializable;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.StringTokenizer;
 import java.util.TreeSet;
 
 /** An alarm in bedework representing an rfc2445 valarm object.
@@ -111,8 +109,8 @@
   protected String duration;
   protected int repeat;
 
-  protected long triggerTime;
-  protected long previousTrigger;
+  protected String triggerTime;
+  protected String previousTrigger;
   protected int repeatCount;
   protected boolean expired;
 
@@ -146,9 +144,7 @@
    * @param triggerDateTime  true if trigger is a date time value
    * @param duration      External form of duration
    * @param repeat        number of repetitions
-   * @param triggerTime   This specifies the time for the next alarm
-   *                      converted to internal format - if 0 has not been
-   *                      calculated
+   * @param triggerTime   This specifies the time for the next alarm in UTC
    * @param previousTrigger   Used to determine if we missed an alarm
    * @param repeatCount   Repetition we are currently handling
    * @param expired       Set to true when we're done
@@ -156,6 +152,8 @@
    * @param description   String description
    * @param summary       String summary (email)
    * @param attendees     Collection of attendees
+   * @param timezones
+   * @throws CalFacadeException
    */
   public BwAlarm(BwEvent event,
                  BwUser owner,
@@ -165,14 +163,15 @@
                  boolean triggerDateTime,
                  String duration,
                  int repeat,
-                 long triggerTime,
-                 long previousTrigger,
+                 String triggerTime,
+                 String previousTrigger,
                  int repeatCount,
                  boolean expired,
                  String attach,
                  String description,
                  String summary,
-                 Collection<BwAttendee> attendees) {
+                 Collection<BwAttendee> attendees,
+                 CalTimezones timezones) throws CalFacadeException {
     super(owner, false);
     setEvent(event);
     this.alarmType = alarmType;
@@ -189,6 +188,10 @@
     addDescription(null, description);
     addSummary(null, summary);
     setAttendees(attendees);
+
+    if (timezones != null) {
+      setTriggerTime(CalFacadeUtil.isoDateTimeUTC(getTriggerDate(timezones)));
+    }
   }
 
   /* ====================================================================
@@ -308,40 +311,40 @@
     return repeat;
   }
 
-  /** set the long trigger time value
+  /** set the trigger time value
    *
-   *  @param val     long trigger time value in millisecs
+   *  @param val     UTC trigger time
    *  @throws CalFacadeException
    */
-  public void setTriggerTime(long val) throws CalFacadeException {
+  public void setTriggerTime(String val) throws CalFacadeException {
     triggerTime = val;
   }
 
-  /** Get the long trigger time value. This is the next time for the
+  /** Get the UTC trigger time value. This is the next time for the
    * alarm.
    *
-   *  @return long   trigger time value in millisecs
+   *  @return String   UTC trigger time
    *  @throws CalFacadeException
    */
-  public long getTriggerTime() throws CalFacadeException {
+  public String getTriggerTime() throws CalFacadeException {
     return triggerTime;
   }
 
-  /** set the long previousTrigger time value
+  /** set the UTC previousTrigger time value
    *
-   *  @param val     long lastTrigger time value in millisecs
+   *  @param val     UTC lastTrigger time
    *  @throws CalFacadeException
    */
-  public void setPreviousTrigger(long val) throws CalFacadeException {
+  public void setPreviousTrigger(String val) throws CalFacadeException {
     previousTrigger = val;
   }
 
-  /** get the long previousTrigger time value
+  /** get the UTC previousTrigger time value
    *
-   *  @return long    previousTrigger time value in millisecs
+   *  @return String    previousTrigger time
    *  @throws CalFacadeException
    */
-  public long getPreviousTrigger() throws CalFacadeException {
+  public String getPreviousTrigger() throws CalFacadeException {
     return previousTrigger;
   }
 
@@ -729,12 +732,12 @@
    *  @throws CalFacadeException
    */
   public Date getNextTriggerDate(CalTimezones timezones) throws CalFacadeException {
-    if (previousTrigger == 0) {
+    if (previousTrigger == null) {
       // First time
       return getTriggerDate(timezones);
     }
 
-    triggerTime = 0; // Force refresh
+    triggerTime = null; // Force refresh
 
     if (repeat == 0) {
       // No next trigger
@@ -746,75 +749,8 @@
       return null;
     }
 
-    // Parse duration into components
-    int plusMinus = 1;
-    int days = 0;
-    int hours = 0;
-    int minutes = 0;
-    int seconds = 0;
-    int weeks = 0;
-
-    StringTokenizer st = new StringTokenizer(duration, "+-PDTHMSW", true);
-    String svToken;
-    String token = null;
-
-    while (st.hasMoreTokens()) {
-      svToken = token;
-      token = st.nextToken();
-
-      if ("-".equals(token)) {
-        plusMinus = -1;
-      } else if ("D".equals(token)) {
-        days = Integer.parseInt(svToken);
-      } else if ("H".equals(token)) {
-        hours = Integer.parseInt(svToken);
-      } else if ("M".equals(token)) {
-        minutes = Integer.parseInt(svToken);
-      } else if ("S".equals(token)) {
-        seconds = Integer.parseInt(svToken);
-      } else if ("W".equals(token)) {
-        weeks = Integer.parseInt(svToken);
-      }
-    }
-
-    boolean hadNonZero = false;
-
-    GregorianCalendar cal = new GregorianCalendar();
-    cal.setTime(getTriggerDate(timezones));
-
-    for (int i = 0; i < repeatCount; i++) {
-      if (weeks != 0) {
-        cal.add(Calendar.WEEK_OF_YEAR, plusMinus * weeks);
-        hadNonZero = true;
-      }
-
-      if (days != 0) {
-        cal.add(Calendar.DATE, plusMinus * days);
-        hadNonZero = true;
-      }
-
-      if (hours != 0) {
-        cal.add(Calendar.HOUR, plusMinus * hours);
-        hadNonZero = true;
-      }
-
-      if (minutes != 0) {
-        cal.add(Calendar.MINUTE, plusMinus * minutes);
-        hadNonZero = true;
-      }
-
-      if (seconds != 0) {
-        cal.add(Calendar.SECOND, plusMinus * seconds);
-        hadNonZero = true;
-      }
-    }
-
-    // Watch for bogus duration
-    if (!hadNonZero) {
-      throw new CalFacadeException("Invalid duration");
-    }
-
-    return cal.getTime();
+    Dur dur = new Duration(null, duration).getDuration();
+    return dur.getTime(getTriggerDate(timezones));
   }
 
   /** Get the trigger Date value. This is the earliest time for the
@@ -889,6 +825,8 @@
    * @param duration
    * @param repeat
    * @param attach
+   * @param timezones
+   * @throws CalFacadeException
    * @return BwEventAlarm
    */
   public static BwAlarm audioAlarm(BwEvent event,
@@ -898,13 +836,15 @@
                                         boolean triggerDateTime,
                                         String duration,
                                         int repeat,
-                                        String attach) {
+                                        String attach,
+                                        CalTimezones timezones) throws CalFacadeException {
     return new BwAlarm(event, owner, alarmTypeAudio,
                             trigger, triggerStart, triggerDateTime,
                             duration, repeat,
-                            0, 0, 0, false,
+                            null, null, 0, false,
                             attach,
-                            null, null, null);
+                            null, null, null,
+                            timezones);
   }
 
   /** Make a display alarm
@@ -917,6 +857,8 @@
    * @param duration
    * @param repeat
    * @param description
+   * @param timezones
+   * @throws CalFacadeException
    * @return BwEventAlarm
    */
   public static BwAlarm displayAlarm(BwEvent event,
@@ -926,12 +868,14 @@
                                           boolean triggerDateTime,
                                           String duration,
                                           int repeat,
-                                          String description) {
+                                          String description,
+                                          CalTimezones timezones) throws CalFacadeException {
     return new BwAlarm(event, owner, alarmTypeDisplay,
                             trigger, triggerStart, triggerDateTime,
                             duration, repeat,
-                            0, 0, 0, false,
-                            null, description, null, null);
+                            null, null, 0, false,
+                            null, description, null, null,
+                            timezones);
   }
 
   /** Make an email alarm
@@ -947,6 +891,8 @@
    * @param description
    * @param summary
    * @param attendees
+   * @param timezones
+   * @throws CalFacadeException
    * @return BwEventAlarm
    */
   public static BwAlarm emailAlarm(BwEvent event,
@@ -959,13 +905,15 @@
                                         String attach,
                                         String description,
                                         String summary,
-                                        Collection<BwAttendee> attendees) {
+                                        Collection<BwAttendee> attendees,
+                                        CalTimezones timezones) throws CalFacadeException {
     return new BwAlarm(event, owner, alarmTypeEmail,
                             trigger, triggerStart, triggerDateTime,
                             duration, repeat,
-                            0, 0, 0, false,
+                            null, null, 0, false,
                             attach,
-                            description, summary, attendees);
+                            description, summary, attendees,
+                            timezones);
   }
 
   /** Make a procedure alarm
@@ -979,6 +927,8 @@
    * @param repeat
    * @param attach
    * @param description
+   * @param timezones
+   * @throws CalFacadeException
    * @return BwEventAlarm
    */
   public static BwAlarm procedureAlarm(BwEvent event,
@@ -989,13 +939,15 @@
                                             String duration,
                                             int repeat,
                                             String attach,
-                                            String description) {
+                                            String description,
+                                            CalTimezones timezones) throws CalFacadeException {
     return new BwAlarm(event, owner, alarmTypeProcedure,
                             trigger, triggerStart, triggerDateTime,
                             duration, repeat,
-                            0, 0, 0, false,
+                            null, null, 0, false,
                             attach,
-                            description, null, null);
+                            description, null, null,
+                            timezones);
   }
 
   /*
@@ -1146,11 +1098,7 @@
     }
 
     try {
-      if (that.getTriggerTime() > getTriggerTime()) {
-        return -1;
-      }
-
-      return 1;
+      return getTriggerTime().compareTo(that.getTriggerTime());
     } catch (Throwable t) {
       throw new RuntimeException(t);
     }
@@ -1232,8 +1180,11 @@
                               getAttach(),
                               getDescription(),
                               getSummary(),
-                              cloneAttendees());
+                              cloneAttendees(),
+                              null);
 
+      a.setTriggerTime(getTriggerTime());
+
       // Don't clone event , they are cloning us
 
       if (getOwner() != null) {

Modified: trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java
===================================================================
--- trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java	2007-04-01 04:44:23 UTC (rev 245)
+++ trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java	2007-04-02 02:01:05 UTC (rev 246)
@@ -659,7 +659,7 @@
         }
       }
 
-      VAlarmUtil.processComponentAlarms(val, ev);
+      VAlarmUtil.processComponentAlarms(val, ev, ctz);
 
       chg.processChanges(ev, true);
 

Modified: trunk/icalendar/src/org/bedework/icalendar/VAlarmUtil.java
===================================================================
--- trunk/icalendar/src/org/bedework/icalendar/VAlarmUtil.java	2007-04-01 04:44:23 UTC (rev 245)
+++ trunk/icalendar/src/org/bedework/icalendar/VAlarmUtil.java	2007-04-02 02:01:05 UTC (rev 246)
@@ -58,6 +58,7 @@
 import org.bedework.calfacade.BwAttendee;
 import org.bedework.calfacade.BwEvent;
 import org.bedework.calfacade.exc.CalFacadeException;
+import org.bedework.calfacade.timezones.CalTimezones;
 
 import net.fortuna.ical4j.model.component.CalendarComponent;
 import net.fortuna.ical4j.model.component.VAlarm;
@@ -93,10 +94,12 @@
    *
    * @param val
    * @param ev
+   * @param timezones
    * @throws CalFacadeException
    */
   public static void processComponentAlarms(CalendarComponent val,
-                                         BwEvent ev) throws CalFacadeException {
+                                            BwEvent ev,
+                                            CalTimezones timezones) throws CalFacadeException {
     try {
       ComponentList als = null;
 
@@ -152,7 +155,7 @@
                                   getOptStr(pl, "ATTACH"),
                                   getReqStr(pl, "DESCRIPTION"),
                                   getReqStr(pl, "SUMMARY"),
-                                  null);
+                                  null, timezones);
 
           Iterator atts = getReqStrs(pl, "ATTENDEE");
 
@@ -163,18 +166,18 @@
           al = BwAlarm.audioAlarm(ev, ev.getCreator(),
                                   tr.trigger, tr.triggerStart, tr.triggerDateTime,
                                   dr.duration, dr.repeat,
-                                  getOptStr(pl, "ATTACH"));
+                                  getOptStr(pl, "ATTACH"), timezones);
         } else if ("DISPLAY".equals(actionStr)) {
           al = BwAlarm.displayAlarm(ev, ev.getCreator(),
                                     tr.trigger, tr.triggerStart, tr.triggerDateTime,
                                     dr.duration, dr.repeat,
-                                    getReqStr(pl, "DESCRIPTION"));
+                                    getReqStr(pl, "DESCRIPTION"), timezones);
         } else if ("PROCEDURE".equals(actionStr)) {
           al = BwAlarm.procedureAlarm(ev, ev.getCreator(),
                                       tr.trigger, tr.triggerStart, tr.triggerDateTime,
                                       dr.duration, dr.repeat,
                                       getReqStr(pl, "ATTACH"),
-                                      getOptStr(pl, "DESCRIPTION"));
+                                      getOptStr(pl, "DESCRIPTION"), timezones);
         } else {
           throw new IcalMalformedException("Invalid alarm - bad type");
         }



More information about the Bedework-commit mailing list