[Bedework-commit] calendarapi r1229 - in trunk:
calFacade/src/org/bedework/calfacade/svc
calsvc/src/org/bedework/calsvc icalendar/src/org/bedework/icalendar
svnadmin at bedework.org
svnadmin at bedework.org
Wed Mar 31 10:42:00 EDT 2010
Author: douglm
Date: 2010-03-31 10:42:00 -0400 (Wed, 31 Mar 2010)
New Revision: 1229
Modified:
trunk/calFacade/src/org/bedework/calfacade/svc/EventInfo.java
trunk/calsvc/src/org/bedework/calsvc/Indexing.java
trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java
Log:
First step in fixing a bug in updating overrides. This correctly updates the collection of overrides when a new copy has less overrides than the existing version. However a following fix is needed to ensure the event actually gets updated when only overrides change.
Modified: trunk/calFacade/src/org/bedework/calfacade/svc/EventInfo.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/svc/EventInfo.java 2010-03-30 19:45:56 UTC (rev 1228)
+++ trunk/calFacade/src/org/bedework/calfacade/svc/EventInfo.java 2010-03-31 14:42:00 UTC (rev 1229)
@@ -32,11 +32,14 @@
import org.bedework.calfacade.util.ChangeTable;
import edu.rpi.cmt.access.Acl.CurrentAccess;
+import edu.rpi.sss.util.Util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
import java.util.TreeSet;
/** This class provides information about an event for a specific user and
@@ -94,6 +97,10 @@
*/
private Collection<EventInfo> overrides;
+ /** This is where we put the overrides when we are updating the event
+ */
+ private Map<String, EventInfo> overrideMap;
+
/** If the event is a master recurring event and we asked for a full
* expansion, this will hold all the instances for that event in the form of
* EventInfo objects.
@@ -132,14 +139,14 @@
/**
* @param event
*/
- public EventInfo(BwEvent event) {
+ public EventInfo(final BwEvent event) {
setEvent(event);
}
/**
* @param val
*/
- public void setEvent(BwEvent val) {
+ public void setEvent(final BwEvent val) {
event = val;
fromRef = val instanceof BwEventAnnotation;
setPrevLastmod(val.getLastmod());
@@ -160,7 +167,7 @@
*
* @param val
*/
- public void setEditable(boolean val) {
+ public void setEditable(final boolean val) {
editable = val;
}
@@ -182,7 +189,7 @@
/**
* @param val
*/
- public void setKind(int val) {
+ public void setKind(final int val) {
kind = val;
}
@@ -201,7 +208,7 @@
*
* @param val boolean true if a new event
*/
- public void setNewEvent(boolean val) {
+ public void setNewEvent(final boolean val) {
newEvent = val;
}
@@ -217,7 +224,7 @@
*
* @param val lastmod
*/
- public void setPrevLastmod(String val) {
+ public void setPrevLastmod(final String val) {
prevLastmod = val;
}
@@ -233,7 +240,7 @@
*
* @param val sequence number
*/
- public void setPrevSeq(int val) {
+ public void setPrevSeq(final int val) {
prevSeq = val;
}
@@ -249,7 +256,7 @@
*
* @param val recurrence id
*/
- public void setRecurrenceId(String val) {
+ public void setRecurrenceId(final String val) {
recurrenceId = val;
}
@@ -265,7 +272,7 @@
*
* @param val CurrentAccess
*/
- public void setCurrentAccess(CurrentAccess val) {
+ public void setCurrentAccess(final CurrentAccess val) {
currentAccess = val;
}
@@ -281,7 +288,7 @@
*
* @param val
*/
- public void setChangeset(ChangeTable val) {
+ public void setChangeset(final ChangeTable val) {
changeSet = val;
}
@@ -301,7 +308,7 @@
/**
* @param val
*/
- public void setAlarms(Collection<BwAlarm> val) {
+ public void setAlarms(final Collection<BwAlarm> val) {
alarms = val;
}
@@ -336,7 +343,7 @@
/**
* @param val
*/
- public void addAlarm(BwAlarm val) {
+ public void addAlarm(final BwAlarm val) {
Collection<BwAlarm> as = getAlarms();
if (as == null) {
as = new TreeSet<BwAlarm>();
@@ -355,7 +362,7 @@
*
* @param val Collection of overrides
*/
- public void setOverrides(Collection<EventInfo> val) {
+ public void setOverrides(final Collection<EventInfo> val) {
overrides = val;
}
@@ -382,7 +389,7 @@
/**
* @param val
*/
- public void addOverride(EventInfo val) {
+ public void addOverride(final EventInfo val) {
Collection<EventInfo> os = getOverrides();
if (os == null) {
os = new TreeSet<EventInfo>();
@@ -398,7 +405,7 @@
* @param val
* @return boolean true if removed.
*/
- public boolean removeOverride(BwEventAnnotation val) {
+ public boolean removeOverride(final BwEventAnnotation val) {
Collection<EventInfo> os = getOverrides();
if (os == null) {
return false;
@@ -425,6 +432,32 @@
return proxies;
}
+ /** On first call transfers any overrides to a map. Used when updating
+ *
+ * @return map of overrides, empty for none.
+ */
+ public Map<String, EventInfo> getOverrideMap() {
+ if (overrideMap != null) {
+ return overrideMap;
+ }
+
+ overrideMap = new HashMap<String, EventInfo>();
+
+ if (Util.isEmpty(overrides)) {
+ return overrideMap;
+ }
+
+ overrideMap = new HashMap<String, EventInfo>();
+
+ for (EventInfo ei: getOverrides()) {
+ overrideMap.put(ei.getEvent().getRecurrenceId(), ei);
+ }
+
+ setOverrides(null);
+
+ return overrideMap;
+ }
+
/* ====================================================================
* Instances methods
* ==================================================================== */
@@ -433,7 +466,7 @@
*
* @param val Collection of instances
*/
- public void setInstances(Collection<EventInfo> val) {
+ public void setInstances(final Collection<EventInfo> val) {
instances = val;
}
@@ -460,7 +493,7 @@
/**
* @param val
*/
- public void addInstance(EventInfo val) {
+ public void addInstance(final EventInfo val) {
Collection<EventInfo> is = getInstances();
if (is == null) {
is = new TreeSet<EventInfo>();
@@ -476,7 +509,7 @@
* @param val
* @return boolean true if removed.
*/
- public boolean removeInstance(EventInfo val) {
+ public boolean removeInstance(final EventInfo val) {
Collection<EventInfo> is = getInstances();
if (is == null) {
return false;
@@ -493,7 +526,7 @@
*
* @param val Collection of EventInfo all marked as entityTypeAvailable
*/
- public void setAvailable(Collection<EventInfo> val) {
+ public void setAvailable(final Collection<EventInfo> val) {
available = val;
}
@@ -509,7 +542,7 @@
*
* @param val
*/
- public void addAvailable(EventInfo val) {
+ public void addAvailable(final EventInfo val) {
Collection<EventInfo> avl = getAvailable();
if (avl == null) {
@@ -525,7 +558,7 @@
*
* @param val uri
*/
- public void setReplyAttendeeURI(String val) {
+ public void setReplyAttendeeURI(final String val) {
replyAttendeeURI = val;
}
@@ -540,7 +573,7 @@
/**
* @param val event name
*/
- public void setInboxEventName(String val) {
+ public void setInboxEventName(final String val) {
inboxEventName = val;
}
@@ -555,7 +588,7 @@
* Object methods
* ==================================================================== */
- public int compare(Object o1, Object o2) {
+ public int compare(final Object o1, final Object o2) {
if (!(o1 instanceof EventInfo)) {
return -1;
}
@@ -574,15 +607,17 @@
return e1.getEvent().compare(e1.getEvent(), e2.getEvent());
}
- public int compareTo(Object o2) {
+ public int compareTo(final Object o2) {
return compare(this, o2);
}
+ @Override
public int hashCode() {
return getEvent().hashCode();
}
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
@@ -594,8 +629,9 @@
return compareTo(obj) == 0;
}
+ @Override
public String toString() {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append("EventInfo{eventid=");
@@ -616,7 +652,7 @@
}
}
sb.append(", recurrenceId=");
- sb.append(getRecurrenceId());
+ sb.append(getEvent().getRecurrenceId());
sb.append("}");
return sb.toString();
Modified: trunk/calsvc/src/org/bedework/calsvc/Indexing.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Indexing.java 2010-03-30 19:45:56 UTC (rev 1228)
+++ trunk/calsvc/src/org/bedework/calsvc/Indexing.java 2010-03-31 14:42:00 UTC (rev 1229)
@@ -118,7 +118,7 @@
}
}
- if (val.getRecurrenceId() != null) {
+ if (val.getEvent().getRecurrenceId() != null) {
// Indexing an override. Reindex the master event
BwEventProxy proxy = (BwEventProxy)val.getEvent();
Modified: trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java
===================================================================
--- trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java 2010-03-30 19:45:56 UTC (rev 1228)
+++ trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java 2010-03-31 14:42:00 UTC (rev 1229)
@@ -132,9 +132,16 @@
* <p>Recurring events present some challenges. If there is no recurrence
* id the vevent represents the master entity which defines the recurrence
* rules. If a recurrence id is present then the vevent represents a
- * recurrence instance and we should not attempt to retrieve the actual
- * object but the referenced instance.
+ * recurrence instance override and we should not attempt to retrieve the
+ * actual object but the referenced instance.
*
+ * <p>Also, note that we sorted the components first so we get the master
+ * before any instances.
+ *
+ * <p>If DTSTART, RRULE, EXRULE have changed (also RDATE, EXDATE?) then any
+ * existing overrides are unusable. We should delete all overrides and replace
+ * with new ones.
+ *
* <p>For an update we have to keep track of which fields were present in
* the vevent and set all absent fields to null in the BwEvent.
*
@@ -315,7 +322,7 @@
}
if (rid != null) {
- String evrid = evinfo.getRecurrenceId();
+ String evrid = evinfo.getEvent().getRecurrenceId();
if ((evrid == null) || (!evrid.equals(rid))) {
warn("Mismatched rid ev=" + evrid + " expected " + rid);
@@ -846,34 +853,25 @@
return null;
}
- /* See if the master event has an annotation with the given recurrence id.
+ /* See if the master event has an override with the given recurrence id.
* If not create one.
*/
private static EventInfo findOverride(final EventInfo ei, final String rid,
final boolean debug) throws CalFacadeException {
- Collection<EventInfo> os = ei.getOverrides();
- EventInfo oei = null;
+ EventInfo oei = ei.getOverrideMap().get(rid);
- if (os != null) {
- for (EventInfo e: os) {
- if (e.getEvent().getRecurrenceId().equals(rid)) {
- oei = e;
- break;
- }
- }
- }
+ if (oei == null) {
+ // Create a new override
- if (oei != null) {
- return oei;
+ oei = new EventInfo();
+ BwEventProxy proxy = BwEventProxy.makeAnnotation(ei.getEvent(), null, true);
+ proxy.setRecurring(new Boolean(false));
+ oei.setEvent(proxy);
+ proxy.setRecurrenceId(rid);
+ oei.setRecurrenceId(rid);
}
- oei = new EventInfo();
- BwEventProxy proxy = BwEventProxy.makeAnnotation(ei.getEvent(), null, true);
- proxy.setRecurring(new Boolean(false));
- oei.setEvent(proxy);
- proxy.setRecurrenceId(rid);
- oei.setRecurrenceId(rid);
-
+ // Add it or add it back
ei.addOverride(oei);
if (debug) {
debugMsg("TRANS-TO_EVENT: Created override for rid " + rid +
More information about the Bedework-commit
mailing list