[CalendarServer-changes] [11038] CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav /storebridge.py

source_changes at macosforge.org source_changes at macosforge.org
Fri Apr 12 17:58:21 PDT 2013


Revision: 11038
          http://trac.calendarserver.org//changeset/11038
Author:   cdaboo at apple.com
Date:     2013-04-12 17:58:21 -0700 (Fri, 12 Apr 2013)
Log Message:
-----------
POST CRUD uses new store api.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py

Modified: CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py	2013-04-12 20:32:36 UTC (rev 11037)
+++ CalendarServer/branches/users/cdaboo/store-scheduling/twistedcaldav/storebridge.py	2013-04-13 00:58:21 UTC (rev 11038)
@@ -49,7 +49,6 @@
     InvalidICalendarDataError, iCalendarProductID, allowedComponents, Component
 from twistedcaldav.memcachelock import MemcacheLockTimeoutError
 from twistedcaldav.method.put_addressbook_common import StoreAddressObjectResource
-from twistedcaldav.method.put_common import StoreCalendarObjectResource
 from twistedcaldav.notifications import NotificationCollectionResource, NotificationResource
 from twistedcaldav.resource import CalDAVResource, GlobalAddressBookResource, \
     DefaultAlarmPropertyMixin
@@ -654,7 +653,7 @@
                 # Get a resource for the new item
                 newchildURL = joinURL(request.path, name)
                 newchild = (yield request.locateResource(newchildURL))
-                dataChanged = (yield self.storeResourceData(request, newchild, newchildURL, component, returnData=return_changed))
+                dataChanged = (yield self.storeResourceData(newchild, component, returnData=return_changed))
 
             except HTTPError, e:
                 # Extract the pre-condition
@@ -826,7 +825,7 @@
             # Get a resource for the new item
             newchildURL = joinURL(request.path, name)
             newchild = (yield request.locateResource(newchildURL))
-            yield self.storeResourceData(request, newchild, newchildURL, component, componentdata)
+            yield self.storeResourceData(newchild, component, componentdata)
 
             # FIXME: figure out return_changed behavior
 
@@ -887,7 +886,7 @@
             if ifmatch and ifmatch != etag.generate():
                 raise HTTPError(PRECONDITION_FAILED)
 
-            yield self.storeResourceData(request, updateResource, href, component, componentdata)
+            yield self.storeResourceData(updateResource, component, componentdata)
 
             # FIXME: figure out return_changed behavior
 
@@ -1213,19 +1212,14 @@
 
 
     @inlineCallbacks
-    def storeResourceData(self, request, newchild, newchildURL, component, returnData=False):
-        storer = StoreCalendarObjectResource(
-            request=request,
-            destination=newchild,
-            destination_uri=newchildURL,
-            destinationcal=True,
-            destinationparent=self,
-            calendar=component,
-            returnData=returnData,
-        )
-        yield storer.run()
+    def storeResourceData(self, newchild, component, returnData=False):
 
-        returnValue(storer.storeddata if hasattr(storer, "storeddata") else None)
+        yield newchild.storeComponent(component)
+        if returnData:
+            result = (yield newchild.componentForUser())
+            returnValue(str(result))
+        else:
+            returnValue(None)
 
 
     @inlineCallbacks
@@ -2320,13 +2314,6 @@
             return FORBIDDEN
 
 
-    def storeResource(self, request, parent, destination, destination_uri, destination_parent, hasSource, component):
-        """
-        Create the appropriate StoreXXX class for storing of data.
-        """
-        raise NotImplementedError
-
-
     @inlineCallbacks
     def storeStream(self, stream):
 
@@ -2339,20 +2326,34 @@
     @inlineCallbacks
     def storeComponent(self, component):
 
-        if self._newStoreObject:
-            yield self._newStoreObject.setComponent(component)
-            returnValue(NO_CONTENT)
-        else:
-            self._newStoreObject = (yield self._newStoreParent.createObjectResourceWithName(
-                self.name(), component, self._metadata
-            ))
+        try:
+            if self._newStoreObject:
+                yield self._newStoreObject.setComponent(component)
+                returnValue(NO_CONTENT)
+            else:
+                self._newStoreObject = (yield self._newStoreParent.createObjectResourceWithName(
+                    self.name(), component, self._metadata
+                ))
 
-            # Re-initialize to get stuff setup again now we have no object
-            self._initializeWithObject(self._newStoreObject, self._newStoreParent)
+                # Re-initialize to get stuff setup again now we have no object
+                self._initializeWithObject(self._newStoreObject, self._newStoreParent)
+                returnValue(CREATED)
 
-            returnValue(CREATED)
+        # Map store exception to HTTP errors
+        except Exception as err:
+            if type(err) in self.StoreExceptionsStatusErrors:
+                raise HTTPError(StatusResponse(responsecode.FORBIDDEN, str(err)))
 
+            elif type(err) in self.StoreExceptionsErrors:
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    self.StoreExceptionsErrors[type(err)],
+                    str(err),
+                ))
+            else:
+                raise
 
+
     @inlineCallbacks
     def storeMove(self, request, destinationparent, destination_name):
         """
@@ -2506,6 +2507,10 @@
     iCalendar = _CommonObjectResource.component
 
 
+    def componentForUser(self):
+        return self._newStoreObject.componentForUser()
+
+
     def validIfScheduleMatch(self, request):
         """
         Check to see if the given request's C{If-Schedule-Tag-Match} header
@@ -2667,45 +2672,13 @@
         # Handle the various store errors
         except Exception as err:
 
-            # Grab the current exception state here so we can use it in a re-raise - we need this because
-            # an inlineCallback might be called and that raises an exception when it returns, wiping out the
-            # original exception "context".
-            ex = Failure()
-
-            if type(err) in CalendarObjectResource.StoreExceptionsStatusErrors:
-                raise HTTPError(StatusResponse(responsecode.FORBIDDEN, str(err)))
-
-            elif type(err) in CalendarObjectResource.StoreExceptionsErrors:
-                raise HTTPError(ErrorResponse(
-                    responsecode.FORBIDDEN,
-                    CalendarObjectResource.StoreExceptionsErrors[type(err)],
-                    str(err),
-                ))
-            elif isinstance(err, ValueError):
+            if isinstance(err, ValueError):
                 log.err("Error while handling (calendar) PUT: %s" % (err,))
                 raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(err)))
             else:
-                # Return the original failure (exception) state
-                ex.raiseException()
+                raise
 
 
-    def storeResource(self, request, parent, destination, destination_uri, destination_parent, hasSource, component, attachmentProcessingDone=False):
-        return StoreCalendarObjectResource(
-            request=request,
-            source=self if hasSource else None,
-            source_uri=request.uri if hasSource else None,
-            sourceparent=parent if hasSource else None,
-            sourcecal=hasSource,
-            deletesource=hasSource,
-            destination=destination,
-            destination_uri=destination_uri,
-            destinationparent=destination_parent,
-            destinationcal=True,
-            calendar=component,
-            attachmentProcessingDone=attachmentProcessingDone,
-        )
-
-
     @requiresPermissions(davxml.WriteContent())
     @inlineCallbacks
     def POST_handler_attachment(self, request, action):
@@ -2943,20 +2916,14 @@
 
 
     @inlineCallbacks
-    def storeResourceData(self, request, newchild, newchildURL, component, returnData=False):
-        storer = StoreAddressObjectResource(
-            request=request,
-            sourceadbk=False,
-            destination=newchild,
-            destination_uri=newchildURL,
-            destinationadbk=True,
-            destinationparent=self,
-            vcard=component,
-            returnData=returnData,
-        )
-        yield storer.run()
+    def storeResourceData(self, newchild, component, returnData=False):
 
-        returnValue(storer.returndata if hasattr(storer, "returndata") else None)
+        yield newchild.storeComponent(component)
+        if returnData:
+            result = (yield newchild.component())
+            returnValue(str(result))
+        else:
+            returnValue(None)
 
 
     @inlineCallbacks
@@ -3043,23 +3010,7 @@
     vCard = _CommonObjectResource.component
 
 
-    def storeResource(self, request, parent, destination, destination_uri, destination_parent, hasSource, component):
-        return StoreAddressObjectResource(
-            request=request,
-            source=self if hasSource else None,
-            source_uri=request.uri if hasSource else None,
-            sourceparent=parent if hasSource else None,
-            sourceadbk=hasSource,
-            deletesource=hasSource,
-            destination=destination,
-            destination_uri=destination_uri,
-            destinationparent=destination_parent,
-            destinationadbk=True,
-            vcard=component,
-        )
 
-
-
 class _NotificationChildHelper(object):
     """
     Methods for things which are like notification objects.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130412/59dee3df/attachment-0001.html>


More information about the calendarserver-changes mailing list