[Bedework-commit] calendarapi r227 - in trunk:
calsvc/src/org/bedework/calsvc calsvci/src/org/bedework/calsvci
svnadmin at bedework.org
svnadmin at bedework.org
Mon Mar 12 23:30:11 EDT 2007
Author: douglm
Date: 2007-03-12 23:30:09 -0400 (Mon, 12 Mar 2007)
New Revision: 227
Modified:
trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
Log:
Add a copyMove svci method to handle copying or moving of a single entity
Use it in the caldav copy/move code.
Modified: trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/CalSvc.java 2007-03-10 02:24:59 UTC (rev 226)
+++ trunk/calsvc/src/org/bedework/calsvc/CalSvc.java 2007-03-13 03:30:09 UTC (rev 227)
@@ -2250,7 +2250,8 @@
/* This event was really deleted so we need to set any synch states to
* indicate this is the case.
*/
- dbi.setSynchState(event, BwSynchState.DELETED);
+ // SYNCH disabled
+ // dbi.setSynchState(event, BwSynchState.DELETED);
der.eventDeleted = true;
der.alarmsDeleted = cider.alarmsDeleted;
@@ -2357,6 +2358,89 @@
return getCal().findCalendars(guid, rid);
}
+ /* (non-Javadoc)
+ * @see org.bedework.calsvci.CalSvcI#copyMoveNamed(org.bedework.calfacade.BwEvent, java.util.Collection, org.bedework.calfacade.BwCalendar, java.lang.String, boolean, boolean)
+ */
+ public CopyMoveStatus copyMoveNamed(BwEvent from,
+ Collection<BwEventProxy>overrides,
+ BwCalendar to,
+ String name,
+ boolean copy,
+ boolean overwrite) throws CalFacadeException {
+ boolean sameCal = from.getCalendar().equals(to);
+
+ if (name == null) {
+ name = from.getName();
+ }
+
+ if (sameCal && name.equals(from.getName())) {
+ // No-op
+ return CopyMoveStatus.noop;
+ }
+
+ try {
+ // Get the target
+ RecurringRetrievalMode rrm =
+ new RecurringRetrievalMode(Rmode.overrides);
+
+ EventInfo destEi = getEvent(to, name, rrm);
+
+ if (destEi != null) {
+ if (!overwrite) {
+ return CopyMoveStatus.destinationExists;
+ }
+
+ if (!destEi.getEvent().getUid().equals(from.getUid())) {
+ // Not allowed to change uid.
+ return CopyMoveStatus.changedUid;
+ }
+
+ //deleteEvent(destEi.getEvent(), true);
+ }
+
+ BwEvent newEvent = (BwEvent)from.clone();
+ newEvent.setName(name);
+
+ if (!copy) {
+ // Moving the event.
+
+ if (!sameCal) {
+ deleteEvent(from, true);
+
+ // XXX overrides should be cloned
+ addEvent(to, newEvent, overrides, true);
+ } else {
+ // Just changing name
+ from.setName(name);
+ updateEvent(from, overrides, null);
+ }
+ } else {
+ // Copying the event.
+
+ if (sameCal) {
+ // Assign a new guid
+ newEvent.setUid(null);
+ assignGuid(newEvent);
+ }
+
+ // XXX overrides should be cloned
+ addEvent(to, newEvent, overrides, true);
+ }
+
+ if (destEi != null) {
+ return CopyMoveStatus.ok;
+ }
+
+ return CopyMoveStatus.created;
+ } catch (CalFacadeException cfe) {
+ if (cfe.getMessage().equals(CalFacadeException.duplicateGuid)) {
+ return CopyMoveStatus.duplicateUid;
+ }
+
+ throw cfe;
+ }
+ }
+
/* ====================================================================
* Scheduling
* ==================================================================== */
Modified: trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java 2007-03-10 02:24:59 UTC (rev 226)
+++ trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java 2007-03-13 03:30:09 UTC (rev 227)
@@ -1602,6 +1602,45 @@
String rid)
throws CalFacadeException;
+ /** Result from copy or move operations. */
+ public static enum CopyMoveStatus {
+ /** */
+ ok,
+
+ /** Nothing happened */
+ noop,
+
+ /** Destination was created (i.e. didn't exist previously) */
+ created,
+
+ /** copy/move would create duplicate uid */
+ duplicateUid,
+
+ /** changing uids is illegal */
+ changedUid,
+
+ /** destination exists and overwrite not set. */
+ destinationExists,
+ }
+ /** Copy or move the given named entity to the destination calendar and give it
+ * the supplied name.
+ *
+ * @param from Source named entity
+ * @param overrides Associated event overrides.
+ * @param to Destination calendar
+ * @param name String name of new entity
+ * @param copy true for copying
+ * @param overwrite if destination exists replace it.
+ * @return CopyMoveStatus
+ * @throws CalFacadeException
+ */
+ public abstract CopyMoveStatus copyMoveNamed(BwEvent from,
+ Collection<BwEventProxy>overrides,
+ BwCalendar to,
+ String name,
+ boolean copy,
+ boolean overwrite) throws CalFacadeException;
+
/* ====================================================================
* Scheduling
* ==================================================================== */
More information about the Bedework-commit
mailing list