From e7a702925101f7762e88bb23c86e6d0eb571ee95 Mon Sep 17 00:00:00 2001 From: Mathew McBride Date: Mon, 7 Dec 2009 23:11:46 +1100 Subject: [PATCH] Handle events with a DURATION (no DTEND) by calculating an equivalent DTEND. --- .../MultipleSourceICalendarObjectStore.java | 44 ++++++++++++++++------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java b/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java index 5eb269b..c6436e6 100644 --- a/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java +++ b/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java @@ -51,11 +51,13 @@ import java.util.logging.*; import net.bionicmessage.groupdav.util.icalUtilities; import net.bionicmessage.utils.HTMLFormatter; import net.bionicmessage.utils.QPDecode; +import net.fortuna.ical4j.model.Dur; import net.fortuna.ical4j.model.component.VEvent; import net.fortuna.ical4j.model.component.VJournal; import net.fortuna.ical4j.model.property.DateProperty; import net.fortuna.ical4j.model.property.DtEnd; import net.fortuna.ical4j.model.property.DtStart; +import net.fortuna.ical4j.model.property.Duration; /** * ICalendarObjectStore builds on ObjectTracking to maintain a client relationship @@ -273,15 +275,34 @@ public class MultipleSourceICalendarObjectStore { if (vcal.getName().equals(VEvent.VEVENT)) { DtStart dts = (DtStart) vcal.getProperty("DTSTART"); DtEnd dte = (DtEnd) vcal.getProperty("DTEND"); + Duration dur = (Duration) vcal.getProperty("DURATION"); // Fix all day if (dts != null) { dts = (DtStart) icalUtilities.correctAllDayTimezones(dts); ds = new Timestamp(dts.getDate().getTime()); } + // For events that have DURATION, we convert to DTEND + if (dte == null && dur != null && dts != null) { + java.util.Calendar dtc = java.util.Calendar.getInstance(); + Dur durDetail = dur.getDuration(); + dtc.setTime(ds); + dtc.add(java.util.Calendar.WEEK_OF_YEAR, durDetail.getWeeks()); + dtc.add(java.util.Calendar.DATE,durDetail.getDays()); + dtc.add(java.util.Calendar.HOUR,durDetail.getHours()); + dtc.add(java.util.Calendar.MINUTE,durDetail.getMinutes()); + dtc.add(java.util.Calendar.SECOND,durDetail.getSeconds()); + net.fortuna.ical4j.model.DateTime dtedate = + new net.fortuna.ical4j.model.DateTime(dtc.getTime()); + dte = new DtEnd(dtedate); + dte.setTimeZone(dts.getTimeZone()); + vcal.getProperties().add(dte); + vcal.getProperties().remove(dur); + } if (dte != null) { dte = (DtEnd) icalUtilities.correctAllDayTimezones(dte); de = new Timestamp(dte.getDate().getTime()); - } + } + } else { // VTODO / VJOURNAL: ds = new Timestamp(0); // just fill with empty (current time) @@ -292,7 +313,7 @@ public class MultipleSourceICalendarObjectStore { obj.getLocation(), obj.getEtag(), summ.getValue().trim(), - obj.getContent(), + cd.toString(), ds, de); logList.add(uid.getValue()); @@ -457,7 +478,6 @@ public class MultipleSourceICalendarObjectStore { while (sourceList.hasNext()) { String sourceName = sourceList.next(); String sourceLoc = sources.get(sourceName); - serverMode = this.getCollectionType(sourceLoc); int downloaderParameter = this.getDownloaderParameter(serverMode); List objectsForSource = null; List toDownload = null; @@ -465,12 +485,12 @@ public class MultipleSourceICalendarObjectStore { if (props.getProperty(StoreConstants.CALDAV_COMPARE_COMPONENT) == null) { objectsForSource = client.listObjects(sourceLoc); etags = client.getEtags(); - } else { + } /* else { etags = cDAVGetURLsEtagsByTimeRange(sourceLoc); String[] locs = new String[etags.size()]; etags.keySet().toArray(locs); objectsForSource = Arrays.asList(locs); - } + } */ HashMap urluid = obtrack.getURLUIDcache(); HashMap uidetag = obtrack.getUidEtagCache(); if (!purgemode) { @@ -502,7 +522,7 @@ public class MultipleSourceICalendarObjectStore { } if (toDownload.size() > 0) { log.info(toDownload.size() + " objects to get. Doing bulk"); - List bulkToAdd = client.getObjectsInBulk(sourceLoc, toDownload, serverMode, downloaderParameter); + List bulkToAdd = client.getObjectsInBulk(sourceLoc, toDownload, false, downloaderParameter); for (GroupDAVObject groupDAVObject : bulkToAdd) { try { addFromServerToStore(sourceName, groupDAVObject, addedToStore); @@ -592,17 +612,17 @@ public class MultipleSourceICalendarObjectStore { } /** Test method */ - public List _listURLsByTimeRange(String source, String type, DateProperty start, DateProperty end) throws Exception { + /* public List _listURLsByTimeRange(String source, String type, DateProperty start, DateProperty end) throws Exception { String actualpath = props.getProperty(StoreConstants.BASE_PROPERTY_SOURCE + source); Map urlsInTime = client.getURLsByEventEnding(actualpath, start.getValue(), end.getValue()); String[] urls = new String[urlsInTime.size()]; urlsInTime.keySet().toArray(urls); return Arrays.asList(urls); - } + } */ /** Get a map of URL's and Etag's by specified time range */ - public Map cDAVGetURLsEtagsByTimeRange(String path) throws Exception { + /* public Map cDAVGetURLsEtagsByTimeRange(String path) throws Exception { String componentType = props.getProperty(StoreConstants.CALDAV_COMPARE_COMPONENT); String comparator = props.getProperty(StoreConstants.CALDAV_COMPARE_PROPERTY); String start = props.getProperty(StoreConstants.CALDAV_COMPARE_START); @@ -611,7 +631,7 @@ public class MultipleSourceICalendarObjectStore { return client.getURLsByTimeRange(path, componentType, comparator, start, end); } return null; - } + } */ public void printDebugReport() throws Exception { StringWriter sw = new StringWriter(); @@ -720,7 +740,7 @@ public class MultipleSourceICalendarObjectStore { } } - private int getCollectionType(String path) throws Exception { + /* private int getCollectionType(String path) throws Exception { String srvMode = props.getProperty(StoreConstants.PROPERTY_SERVER_MODE); if (srvMode == null) { return client.getUseMode(path); @@ -728,7 +748,7 @@ public class MultipleSourceICalendarObjectStore { return 1; } return 0; - } + } */ private int getDownloaderParameter(int type) { if (type == 1) { -- 2.11.4.GIT