[Bedework-commit] calendarapi r226 - in trunk: calCore/src/org/bedework/calcore/hibernate calFacade/src/org/bedework/calfacade/base calFacade/src/org/bedework/calfacade/filter calFacade/src/org/bedework/calfacade/util

svnadmin at bedework.org svnadmin at bedework.org
Fri Mar 9 21:25:03 EST 2007


Author: douglm
Date: 2007-03-09 21:24:59 -0500 (Fri, 09 Mar 2007)
New Revision: 226

Added:
   trunk/calFacade/src/org/bedework/calfacade/base/TimeRange.java
   trunk/calFacade/src/org/bedework/calfacade/filter/BwTimeRangeFilter.java
Modified:
   trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java
   trunk/calFacade/src/org/bedework/calfacade/filter/BwObjectFilter.java
   trunk/calFacade/src/org/bedework/calfacade/filter/BwUserFilter.java
   trunk/calFacade/src/org/bedework/calfacade/util/PropertyIndex.java
Log:
Move TimeRange into CalFacade

Define a timerange filter and add code to use it in Filters

Create the above filter for CalDAV timerange prop-filter

Modified: trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java
===================================================================
--- trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java	2007-03-07 20:54:08 UTC (rev 225)
+++ trunk/calCore/src/org/bedework/calcore/hibernate/Filters.java	2007-03-10 02:24:59 UTC (rev 226)
@@ -55,14 +55,17 @@
 
 import org.bedework.calcorei.CoreEventInfo;
 import org.bedework.calcorei.HibSession;
+import org.bedework.calfacade.BwDateTime;
 import org.bedework.calfacade.BwEvent;
 import org.bedework.calfacade.base.BwDbentity;
+import org.bedework.calfacade.base.TimeRange;
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calfacade.filter.BwAndFilter;
 import org.bedework.calfacade.filter.BwCategoryFilter;
 import org.bedework.calfacade.filter.BwObjectFilter;
 import org.bedework.calfacade.filter.BwFilter;
 import org.bedework.calfacade.filter.BwOrFilter;
+import org.bedework.calfacade.filter.BwTimeRangeFilter;
 import org.bedework.calfacade.util.PropertyIndex;
 import org.bedework.calfacade.util.PropertyIndex.PropertyInfo;
 
@@ -338,6 +341,43 @@
           qseg.append(fieldName);
           qseg.append("))");
         }
+      } else if (ef instanceof BwTimeRangeFilter) {
+        BwTimeRangeFilter trf = (BwTimeRangeFilter)ef;
+        TimeRange tr = trf.getEntity();
+
+        qseg.append('(');
+
+        if (tr.getStart() != null) {
+          qseg.append('(');
+          qseg.append(evName);
+          qseg.append(".");
+          qseg.append(fieldName);
+
+          if (pi.getValClass().getName().equals(BwDateTime.class.getName())) {
+            qseg.append(".date");
+          }
+
+          qseg.append(">=");
+          qseg.append(tr.getStart());
+        }
+
+        if (tr.getEnd() != null) {
+          if (tr.getStart() != null) {
+            qseg.append(" and ");
+          }
+
+          qseg.append('(');
+          qseg.append(evName);
+          qseg.append(".");
+          qseg.append(fieldName);
+
+          if (pi.getValClass().getName().equals(BwDateTime.class.getName())) {
+            qseg.append(".date");
+          }
+
+          qseg.append("<");
+          qseg.append(tr.getEnd());
+        }
       } else {
         qseg.append('(');
         qseg.append(evName);

Added: trunk/calFacade/src/org/bedework/calfacade/base/TimeRange.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/base/TimeRange.java	                        (rev 0)
+++ trunk/calFacade/src/org/bedework/calfacade/base/TimeRange.java	2007-03-10 02:24:59 UTC (rev 226)
@@ -0,0 +1,149 @@
+/* **********************************************************************
+    Copyright 2007 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
+
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
+
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
+package org.bedework.calfacade.base;
+
+import org.bedework.calfacade.BwDateTime;
+
+import net.fortuna.ical4j.model.property.DateProperty;
+import net.fortuna.ical4j.model.Property;
+
+import org.apache.log4j.Logger;
+
+/** Timerange element for filters. Either start or end may be absent but
+ * not both.
+ *
+ *   @author Mike Douglass   douglm  rpi.edu
+ */
+public class TimeRange {
+  private BwDateTime start;
+  private BwDateTime end;
+
+  /** Constructor
+   */
+  public TimeRange() {
+  }
+
+  /** Constructor
+   *
+   * @param start
+   * @param end
+   */
+  public TimeRange(BwDateTime start, BwDateTime end) {
+    this.start = start;
+    this.end = end;
+  }
+
+  /**
+   * @param val BwDateTime start
+   */
+  public void setStart(BwDateTime val) {
+    start = val;
+  }
+
+  /**
+   * @return BwDateTime start
+   */
+  public BwDateTime getStart() {
+    return start;
+  }
+
+  /**
+   * @param val BwDateTime end
+   */
+  public void setEnd(BwDateTime val) {
+    end = val;
+  }
+
+  /**
+   * @return BwDateTime end
+   */
+  public BwDateTime getEnd() {
+    return end;
+  }
+
+  /** merge that into this
+   *
+   * @param that TimeRange to merge
+   */
+  public void merge(TimeRange that) {
+    if (getStart().before(that.getStart())) {
+      setStart(that.getStart());
+    }
+
+    if (getEnd().after(that.getEnd())) {
+      setEnd(that.getEnd());
+    }
+  }
+
+  /** Test if the given property falls in the timerange
+   *
+   * @param candidate
+   * @return boolean true if in range
+   */
+  public boolean matches(Property candidate) {
+    if (!(candidate instanceof DateProperty)) {
+      return false;
+    }
+
+    // XXX later
+    return true;
+  }
+
+  /** Debug
+   *
+   * @param log
+   * @param indent
+   */
+  public void dump(Logger log, String indent) {
+    log.debug(indent + toString());
+  }
+
+  protected void toStringSegment(StringBuffer sb) {
+    if (start != null) {
+      sb.append("start=");
+      sb.append(start);
+    }
+
+    if (end != null) {
+      if (start != null) {
+        sb.append(" ");
+      }
+      sb.append("end=");
+      sb.append(end);
+    }
+  }
+
+  public String toString() {
+    StringBuffer sb = new StringBuffer();
+
+    sb.append("<time-range ");
+    toStringSegment(sb);
+    sb.append("/>");
+
+    return sb.toString();
+  }
+}
+


Property changes on: trunk/calFacade/src/org/bedework/calfacade/base/TimeRange.java
___________________________________________________________________
Name: svn:eol-style
   + LF

Modified: trunk/calFacade/src/org/bedework/calfacade/filter/BwObjectFilter.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/filter/BwObjectFilter.java	2007-03-07 20:54:08 UTC (rev 225)
+++ trunk/calFacade/src/org/bedework/calfacade/filter/BwObjectFilter.java	2007-03-10 02:24:59 UTC (rev 226)
@@ -25,6 +25,7 @@
 */
 package org.bedework.calfacade.filter;
 
+import org.bedework.calfacade.base.TimeRange;
 import org.bedework.calfacade.util.CalFacadeUtil;
 import org.bedework.calfacade.util.PropertyIndex.PropertyInfoIndex;
 
@@ -303,6 +304,24 @@
 
     return filter;
   }
+
+  /** Create a timerange filter for the given index and value
+   *
+   * @param name
+   * @param propertyIndex
+   * @param val     TimeRange
+   * @return BwObjectFilter
+   */
+  public static BwObjectFilter makeFilter(String name,
+                                          PropertyInfoIndex propertyIndex,
+                                          TimeRange val) {
+    BwTimeRangeFilter trf = new BwTimeRangeFilter(name, propertyIndex);
+
+    trf.setEntity(val);
+
+    return trf;
+  }
+
   /* ====================================================================
    *                   Object methods
    * ==================================================================== */

Added: trunk/calFacade/src/org/bedework/calfacade/filter/BwTimeRangeFilter.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/filter/BwTimeRangeFilter.java	                        (rev 0)
+++ trunk/calFacade/src/org/bedework/calfacade/filter/BwTimeRangeFilter.java	2007-03-10 02:24:59 UTC (rev 226)
@@ -0,0 +1,45 @@
+/* **********************************************************************
+    Copyright 2007 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
+
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
+
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
+package org.bedework.calfacade.filter;
+
+import org.bedework.calfacade.base.TimeRange;
+import org.bedework.calfacade.util.PropertyIndex.PropertyInfoIndex;
+
+/** A filter that selects events that have a certain category
+ *
+ * @author Mike Douglass
+ * @version 1.0
+ */
+public class BwTimeRangeFilter extends BwObjectFilter<TimeRange> {
+  /** Match a created date.
+   *
+   * @param name - null one will be created
+   * @param propertyIndex
+   */
+  public BwTimeRangeFilter(String name, PropertyInfoIndex propertyIndex) {
+    super(name, propertyIndex);
+  }
+}


Property changes on: trunk/calFacade/src/org/bedework/calfacade/filter/BwTimeRangeFilter.java
___________________________________________________________________
Name: svn:eol-style
   + LF

Modified: trunk/calFacade/src/org/bedework/calfacade/filter/BwUserFilter.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/filter/BwUserFilter.java	2007-03-07 20:54:08 UTC (rev 225)
+++ trunk/calFacade/src/org/bedework/calfacade/filter/BwUserFilter.java	2007-03-10 02:24:59 UTC (rev 226)
@@ -1,31 +1,28 @@
-/*
- Copyright (c) 2000-2005 University of Washington.  All rights reserved.
+/* **********************************************************************
+    Copyright 2007 Rensselaer Polytechnic Institute. All worldwide rights reserved.
 
- Redistribution and use of this distribution in source and binary forms,
- with or without modification, are permitted provided that:
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
 
-   The above copyright notice and this permission notice appear in
-   all copies and supporting documentation;
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
 
-   The name, identifiers, and trademarks of the University of Washington
-   are not used in advertising or publicity without the express prior
-   written permission of the University of Washington;
-
-   Recipients acknowledge that this distribution is made available as a
-   research courtesy, "as is", potentially with defects, without
-   any obligation on the part of the University of Washington to
-   provide support, services, or repair;
-
-   THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR
-   IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION
-   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-   PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
-   WASHINGTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-   DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
-   PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING
-   NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
-   THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
 package org.bedework.calfacade.filter;
 
 import org.bedework.calfacade.BwUser;
@@ -33,12 +30,11 @@
 
 /** A filter that selects events that have a certain category
  *
- * @author Greg Barnes
  * @author Mike Douglass
  * @version 1.0
  */
 public class BwUserFilter extends BwObjectFilter<BwUser> {
-  /** Match on any of the categories.
+  /** Match on a user.
    *
    * @param name - null one will be created
    * @param propertyIndex

Modified: trunk/calFacade/src/org/bedework/calfacade/util/PropertyIndex.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/util/PropertyIndex.java	2007-03-07 20:54:08 UTC (rev 225)
+++ trunk/calFacade/src/org/bedework/calfacade/util/PropertyIndex.java	2007-03-10 02:24:59 UTC (rev 226)
@@ -58,6 +58,7 @@
 import org.bedework.calfacade.BwFreeBusyComponent;
 import org.bedework.calfacade.BwGeo;
 import org.bedework.calfacade.BwUser;
+import org.bedework.calfacade.base.TimeRange;
 
 import net.fortuna.ical4j.model.Property;
 
@@ -373,7 +374,7 @@
 
     addPinfo(PropertyInfoIndex.CREATED,
              etjProperty(PropertyInfoIndex.CREATED, Property.CREATED,
-                         "created", String.class));
+                         "created", TimeRange.class));
 
     addPinfo(PropertyInfoIndex.DESCRIPTION,
              etjPropertyPlus(PropertyInfoIndex.DESCRIPTION, Property.DESCRIPTION,
@@ -382,7 +383,7 @@
 
     addPinfo(PropertyInfoIndex.DTSTAMP,
              etjPropertyPlus(PropertyInfoIndex.DTSTAMP, Property.DTSTAMP,
-                             "dtstamp", String.class,
+                             "dtstamp", TimeRange.class,
                              true, false, false));
 
 
@@ -405,7 +406,7 @@
 
     addPinfo(PropertyInfoIndex.LAST_MODIFIED,
              etjPropertyPlus(PropertyInfoIndex.LAST_MODIFIED, Property.LAST_MODIFIED,
-                                            "lastmod", String.class,
+                                            "lastmod", TimeRange.class,
                                             false, true, false));
 
     addPinfo(PropertyInfoIndex.LOCATION,



More information about the Bedework-commit mailing list