[CalendarServer-changes] [11946] CalendarServer/branches/users/cdaboo/sharing-in-the-store
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:20:16 PDT 2014
Revision: 11946
http://trac.calendarserver.org//changeset/11946
Author: cdaboo at apple.com
Date: 2013-11-14 09:35:45 -0800 (Thu, 14 Nov 2013)
Log Message:
-----------
Tweak new api to pass around dict's rather than JSON encoding. JSON is only done within the low-level store api now.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/notifications.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/file.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py
CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/inotifications.py
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/notifications.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/notifications.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/notifications.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -35,6 +35,7 @@
from txdav.common.icommondatastore import SyncTokenValidException
+import json
import os
import types
@@ -92,17 +93,6 @@
return davxml.ResourceType.notification
- @inlineCallbacks
- def addNotification(self, request, uid, xmltype, xmldata):
-
- # Write data to file
- rname = uid + ".xml"
- yield self._writeNotification(request, uid, rname, xmltype, xmldata)
-
- # Update database
- self.notificationsDB().addOrUpdateRecord(NotificationRecord(uid, rname, xmltype.name))
-
-
def getNotifictionMessages(self, request, componentType=None, returnLatestVersion=True):
return succeed([])
@@ -144,10 +134,10 @@
class NotificationRecord(object):
- def __init__(self, uid, name, xmltype):
+ def __init__(self, uid, name, notificationtype):
self.uid = uid
self.name = name
- self.xmltype = xmltype
+ self.notificationtype = notificationtype if isinstance(notificationtype, dict) else json.loads(notificationtype)
@@ -184,7 +174,7 @@
self._db_execute("""insert or replace into NOTIFICATIONS (UID, NAME, TYPE)
values (:1, :2, :3)
- """, record.uid, record.name, record.xmltype,
+ """, record.uid, record.name, json.dumps(record.notificationtype),
)
self._db_execute(
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -48,9 +48,7 @@
from pycalendar.datetime import DateTime
-import json
-
# FIXME: Get rid of these imports
from twistedcaldav.directory.util import TRANSACTION_KEY
# circular import
@@ -735,11 +733,11 @@
state = notificationState if notificationState else invitation.status()
summary = invitation.summary() if displayName is None else displayName
- xmltype = {
+ notificationtype = {
"notification-type": "invite-notification",
"shared-type": self.sharedResourceType(),
}
- xmldata = {
+ notificationdata = {
"notification-type": "invite-notification",
"shared-type": self.sharedResourceType(),
"dtstamp": DateTime.getNowUTC().getText(),
@@ -752,13 +750,10 @@
"summary": summary,
}
if self.isCalendarCollection():
- xmldata["supported-components"] = self._newStoreObject.getSupportedComponents()
+ notificationdata["supported-components"] = self._newStoreObject.getSupportedComponents()
- xmltype = json.dumps(xmltype)
- xmldata = json.dumps(xmldata)
-
# Add to collections
- yield notifications.writeNotificationObject(invitation.uid(), xmltype, xmldata)
+ yield notifications.writeNotificationObject(invitation.uid(), notificationtype, notificationdata)
@inlineCallbacks
@@ -1348,11 +1343,11 @@
# Generate invite XML
notificationUID = "%s-reply" % (replytoUID,)
- xmltype = {
+ notificationtype = {
"notification-type": "invite-reply",
}
- xmldata = {
+ notificationdata = {
"notification-type": "invite-reply",
"shared-type": sharedResource.sharedResourceType(),
"dtstamp": DateTime.getNowUTC().getText(),
@@ -1364,11 +1359,8 @@
"summary": displayname if displayname is not None else "",
}
- xmltype = json.dumps(xmltype)
- xmldata = json.dumps(xmldata)
-
# Add to collections
- yield notifications.writeNotificationObject(notificationUID, xmltype, xmldata)
+ yield notifications.writeNotificationObject(notificationUID, notificationtype, notificationdata)
def _handleInviteReply(self, request, invitereplydoc):
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -86,7 +86,6 @@
import collections
from twistedcaldav.sharing import invitationBindStatusToXMLMap, \
invitationBindModeToXMLMap
-import json
"""
Wrappers to translate between the APIs in L{txdav.caldav.icalendarstore} and
@@ -3669,13 +3668,6 @@
)
- def addNotification(self, request, uid, xmltype, xmldata):
- return maybeDeferred(
- self._newStoreNotifications.writeNotificationObject,
- uid, xmltype, xmldata
- )
-
-
def deleteNotification(self, request, record):
return maybeDeferred(
self._newStoreNotifications.removeNotificationObjectWithName,
@@ -3720,8 +3712,7 @@
qname = prop.qname()
if qname == customxml.NotificationType.qname():
- jsontype = self._newStoreObject.xmlType()
- jsontype = json.loads(jsontype)
+ jsontype = self._newStoreObject.notificationType()
if jsontype["notification-type"] == "invite-notification":
typeAttr = {"shared-type": jsontype["shared-type"]}
xmltype = customxml.InviteNotification(**typeAttr)
@@ -3745,8 +3736,7 @@
@inlineCallbacks
def text(self, ignored=None):
assert ignored is None, "This is a notification object, not a notification"
- jsondata = (yield self._newStoreObject.xmldata())
- jsondata = json.loads(jsondata)
+ jsondata = (yield self._newStoreObject.notificationData())
if jsondata["notification-type"] == "invite-notification":
ownerPrincipal = self.principalForUID(jsondata["owner"])
ownerCN = ownerPrincipal.displayName()
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -377,8 +377,8 @@
notifications = yield txn.notificationsWithUID("home1")
yield notifications.writeNotificationObject(
"abc",
- "{\"notification-type\":\"invite-notification\"}",
- "{\"notification-type\":\"invite-notification\"}"
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
)
notificationObject = yield notifications.notificationObjectWithUID("abc")
returnValue(notificationObject)
@@ -402,9 +402,17 @@
"""
txn = self.transactionUnderTest()
coll = yield txn.notificationsWithUID("home1")
- yield coll.writeNotificationObject("1", "{\"notification-type\":\"invite-notification\"}", "{\"notification-type\":\"invite-notification\"}")
+ yield coll.writeNotificationObject(
+ "1",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
st = yield coll.syncToken()
- yield coll.writeNotificationObject("2", "{\"notification-type\":\"invite-notification\"}", "{\"notification-type\":\"invite-notification\"}")
+ yield coll.writeNotificationObject(
+ "2",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ )
rev = self.token2revision(st)
yield coll.removeNotificationObjectWithUID("1")
st2 = yield coll.syncToken()
@@ -428,17 +436,17 @@
)
yield notifications.writeNotificationObject(
"abc",
- "{\"notification-type\":\"invite-notification\"}",
- "{\"notification-type\":\"invite-notification\"}",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
)
yield notifications.writeNotificationObject(
"abc",
- "{\"notification-type\":\"invite-notification\"}",
- "{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}"),
)
abc = yield notifications.notificationObjectWithUID("abc")
self.assertEquals(
- json.loads((yield abc.xmldata())),
+ (yield abc.notificationData()),
json.loads("{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}"),
)
@@ -461,8 +469,8 @@
self.notifierFactory.reset()
yield notifications.writeNotificationObject(
"abc",
- "{\"notification-type\":\"invite-notification\"}",
- "{\"notification-type\":\"invite-notification\"}",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
)
# notify is called prior to commit
@@ -505,13 +513,13 @@
)
yield notifications.writeNotificationObject(
"abc",
- "{\"notification-type\":\"invite-notification\"}",
- "{\"notification-type\":\"invite-notification\"}",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
)
yield notifications.writeNotificationObject(
"def",
- "{\"notification-type\":\"invite-notification\"}",
- "{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}",
+ json.loads("{\"notification-type\":\"invite-notification\"}"),
+ json.loads("{\"notification-type\":\"invite-notification\",\"summary\":\"a summary\"}"),
)
yield self.commit()
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/file.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/file.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -58,6 +58,7 @@
from errno import EEXIST, ENOENT
from zope.interface import implements, directlyProvides
+import json
import uuid
from twistedcaldav.sql import AbstractSQLDatabase, db_prefix
import os
@@ -1499,17 +1500,17 @@
return self.notificationObjectWithName(name)
- def writeNotificationObject(self, uid, xmltype, xmldata):
+ def writeNotificationObject(self, uid, notificationtype, notificationdata):
name = uid + ".xml"
if name.startswith("."):
raise ObjectResourceNameNotAllowedError(name)
objectResource = NotificationObject(name, self)
- objectResource.setData(uid, xmltype, xmldata)
+ objectResource.setData(uid, notificationtype, notificationdata)
self._cachedObjectResources[name] = objectResource
# Update database
- self.retrieveOldIndex().addOrUpdateRecord(NotificationRecord(uid, name, xmltype))
+ self.retrieveOldIndex().addOrUpdateRecord(NotificationRecord(uid, name, notificationtype))
self.notifyChanged()
@@ -1572,15 +1573,16 @@
@writeOperation
- def setData(self, uid, xmltype, xmldata, inserting=False):
+ def setData(self, uid, notificationtype, notificationdata, inserting=False):
rname = uid + ".xml"
self._parentCollection.retrieveOldIndex().addOrUpdateRecord(
- NotificationRecord(uid, rname, xmltype)
+ NotificationRecord(uid, rname, notificationtype)
)
- self._xmldata = xmldata
- md5 = hashlib.md5(xmldata).hexdigest()
+ self._notificationdata = notificationdata
+ notificationtext = json.dumps(self._notificationdata)
+ md5 = hashlib.md5(notificationtext).hexdigest()
def do():
backup = None
@@ -1591,7 +1593,7 @@
try:
# FIXME: concurrency problem; if this write is interrupted
# halfway through, the underlying file will be corrupt.
- fh.write(xmldata)
+ fh.write(notificationtext)
finally:
fh.close()
def undo():
@@ -1610,7 +1612,7 @@
props = self.properties()
props[PropertyName(*GETContentType.qname())] = GETContentType.fromString(generateContentType(MimeType("text", "xml", params={"charset": "utf-8"})))
- props[PropertyName.fromElement(NotificationType)] = NotificationType(xmltype)
+ props[PropertyName.fromElement(NotificationType)] = NotificationType(json.dumps(notificationtype))
props[PropertyName.fromElement(TwistedGETContentMD5)] = TwistedGETContentMD5.fromString(md5)
# FIXME: the property store's flush() method may already have been
@@ -1620,11 +1622,11 @@
# manipulation methods won't work.
self._transaction.addOperation(self.properties().flush, "post-update property flush")
- _xmldata = None
+ _notificationdata = None
- def xmldata(self):
- if self._xmldata is not None:
- return self._xmldata
+ def notificationData(self):
+ if self._notificationdata is not None:
+ return self._notificationdata
try:
fh = self._path.open()
except IOError, e:
@@ -1638,14 +1640,14 @@
finally:
fh.close()
- return text
+ return json.loads(text)
def uid(self):
return self._uid
- def xmlType(self):
+ def notificationType(self):
# NB This is the NotificationType property element
return self.properties()[PropertyName.fromElement(NotificationType)]
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -77,6 +77,7 @@
from zope.interface import implements, directlyProvides
+import json
import sys
import time
@@ -4430,7 +4431,7 @@
self._size = None
self._created = None
self._modified = None
- self._objectText = None
+ self._notificationData = None
self._locked = False
@@ -4841,7 +4842,7 @@
self._size = None
self._created = None
self._modified = None
- self._objectText = None
+ self._notificationData = None
def uid(self):
@@ -4885,19 +4886,19 @@
@inlineCallbacks
def _text(self):
- if self._objectText is None:
+ if self._notificationData is None:
texts = (
yield self._textByIDQuery.on(self._txn,
resourceID=self._resourceID)
)
if texts:
text = texts[0][0]
- self._objectText = text
+ self._notificationData = text
returnValue(text)
else:
raise ConcurrentModification()
else:
- returnValue(self._objectText)
+ returnValue(self._notificationData)
@@ -5118,14 +5119,14 @@
@inlineCallbacks
- def writeNotificationObject(self, uid, xmltype, xmldata):
+ def writeNotificationObject(self, uid, notificationtype, notificationdata):
inserting = False
notificationObject = yield self.notificationObjectWithUID(uid)
if notificationObject is None:
notificationObject = NotificationObject(self, uid)
inserting = True
- yield notificationObject.setData(uid, xmltype, xmldata, inserting=inserting)
+ yield notificationObject.setData(uid, notificationtype, notificationdata, inserting=inserting)
if inserting:
yield self._insertRevision("%s.xml" % (uid,))
else:
@@ -5298,8 +5299,8 @@
self._size = None
self._created = None
self._modified = None
- self._xmlType = None
- self._objectText = None
+ self._notificationType = None
+ self._notificationData = None
def __repr__(self):
@@ -5314,7 +5315,7 @@
obj = cls._objectSchema
return Select(
[obj.RESOURCE_ID, obj.NOTIFICATION_UID, obj.MD5,
- Len(obj.XML_DATA), obj.XML_TYPE, obj.CREATED, obj.MODIFIED],
+ Len(obj.NOTIFICATION_DATA), obj.NOTIFICATION_TYPE, obj.CREATED, obj.MODIFIED],
From=obj,
Where=(obj.NOTIFICATION_HOME_RESOURCE_ID == Parameter("homeID"))
)
@@ -5354,9 +5355,13 @@
child._uid,
child._md5,
child._size,
- child._xmlType,
+ child._notificationType,
child._created,
child._modified,) = tuple(row)
+ try:
+ child._notificationType = json.loads(child._notificationType)
+ except ValueError:
+ pass
child._loadPropertyStore(
props=propertyStores.get(child._resourceID, None)
)
@@ -5372,8 +5377,8 @@
[
no.RESOURCE_ID,
no.MD5,
- Len(no.XML_DATA),
- no.XML_TYPE,
+ Len(no.NOTIFICATION_DATA),
+ no.NOTIFICATION_TYPE,
no.CREATED,
no.MODIFIED
],
@@ -5398,9 +5403,13 @@
(self._resourceID,
self._md5,
self._size,
- self._xmlType,
+ self._notificationType,
self._created,
self._modified,) = tuple(rows[0])
+ try:
+ self._notificationType = json.loads(self._notificationType)
+ except ValueError:
+ pass
self._loadPropertyStore()
returnValue(self)
else:
@@ -5451,8 +5460,8 @@
{
no.NOTIFICATION_HOME_RESOURCE_ID: Parameter("homeID"),
no.NOTIFICATION_UID: Parameter("uid"),
- no.XML_TYPE: Parameter("xmlType"),
- no.XML_DATA: Parameter("xmlData"),
+ no.NOTIFICATION_TYPE: Parameter("notificationType"),
+ no.NOTIFICATION_DATA: Parameter("notificationData"),
no.MD5: Parameter("md5"),
},
Return=[no.RESOURCE_ID, no.CREATED, no.MODIFIED]
@@ -5464,8 +5473,8 @@
no = cls._objectSchema
return Update(
{
- no.XML_TYPE: Parameter("xmlType"),
- no.XML_DATA: Parameter("xmlData"),
+ no.NOTIFICATION_TYPE: Parameter("notificationType"),
+ no.NOTIFICATION_DATA: Parameter("notificationData"),
no.MD5: Parameter("md5"),
},
Where=(no.NOTIFICATION_HOME_RESOURCE_ID == Parameter("homeID")).And(
@@ -5475,41 +5484,44 @@
@inlineCallbacks
- def setData(self, uid, xmltype, xmldata, inserting=False):
+ def setData(self, uid, notificationtype, notificationdata, inserting=False):
"""
Set the object resource data and update and cached metadata.
"""
- self._xmlType = xmltype
- self._md5 = hashlib.md5(xmldata).hexdigest()
- self._size = len(xmldata)
+ notificationtext = json.dumps(notificationdata)
+ self._notificationType = notificationtype
+ self._md5 = hashlib.md5(notificationtext).hexdigest()
+ self._size = len(notificationtext)
if inserting:
rows = yield self._newNotificationQuery.on(
self._txn, homeID=self._home._resourceID, uid=uid,
- xmlType=self._xmlType, xmlData=xmldata, md5=self._md5
+ notificationType=json.dumps(self._notificationType), notificationData=notificationtext, md5=self._md5
)
self._resourceID, self._created, self._modified = rows[0]
self._loadPropertyStore()
else:
rows = yield self._updateNotificationQuery.on(
self._txn, homeID=self._home._resourceID, uid=uid,
- xmlType=self._xmlType, xmlData=xmldata, md5=self._md5
+ notificationType=json.dumps(self._notificationType), notificationData=notificationtext, md5=self._md5
)
self._modified = rows[0][0]
- self._objectText = xmldata
+ self._notificationData = notificationdata
- _xmlDataFromID = Select(
- [_objectSchema.XML_DATA], From=_objectSchema,
+ _notificationDataFromID = Select(
+ [_objectSchema.NOTIFICATION_DATA], From=_objectSchema,
Where=_objectSchema.RESOURCE_ID == Parameter("resourceID"))
@inlineCallbacks
- def xmldata(self):
- if self._objectText is None:
- self._objectText = (
- yield self._xmlDataFromID.on(
- self._txn, resourceID=self._resourceID))[0][0]
- returnValue(self._objectText)
+ def notificationData(self):
+ if self._notificationData is None:
+ self._notificationData = (yield self._notificationDataFromID.on(self._txn, resourceID=self._resourceID))[0][0]
+ try:
+ self._notificationData = json.loads(self._notificationData)
+ except ValueError:
+ pass
+ returnValue(self._notificationData)
def contentType(self):
@@ -5527,8 +5539,8 @@
return self._size
- def xmlType(self):
- return self._xmlType
+ def notificationType(self):
+ return self._notificationType
def created(self):
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql 2013-11-14 17:35:45 UTC (rev 11946)
@@ -57,7 +57,7 @@
"RESOURCE_ID" integer primary key,
"NOTIFICATION_HOME_RESOURCE_ID" integer not null references NOTIFICATION_HOME,
"NOTIFICATION_UID" nvarchar2(255),
- "XML_TYPE" nvarchar2(255),
+ "NOTIFICATION_TYPE" nvarchar2(255),
"XML_DATA" nclob,
"MD5" nchar(32),
"CREATED" timestamp default CURRENT_TIMESTAMP at time zone 'UTC',
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql 2013-11-14 17:35:45 UTC (rev 11946)
@@ -117,8 +117,8 @@
RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
NOTIFICATION_HOME_RESOURCE_ID integer not null references NOTIFICATION_HOME,
NOTIFICATION_UID varchar(255) not null,
- XML_TYPE varchar(255) not null,
- XML_DATA text not null,
+ NOTIFICATION_TYPE varchar(255) not null,
+ NOTIFICATION_DATA text not null,
MD5 char(32) not null,
CREATED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
MODIFIED timestamp default timezone('UTC', CURRENT_TIMESTAMP),
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_28_to_29.sql 2013-11-14 17:35:45 UTC (rev 11946)
@@ -23,5 +23,10 @@
alter table NOTIFICATION_HOME
add ("DATAVERSION" integer default 0 not null);
+alter table NOTIFICATION
+ rename column XML_TYPE to NOTIFICATION_TYPE;
+alter table NOTIFICATION
+ rename column XML_DATA to NOTIFICATION_DATA;
+
-- Now update the version
update CALENDARSERVER set VALUE = '29' where NAME = 'VERSION';
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_28_to_29.sql 2013-11-14 17:35:45 UTC (rev 11946)
@@ -23,5 +23,10 @@
alter table NOTIFICATION_HOME
add column DATAVERSION integer default 0 not null;
+alter table NOTIFICATION
+ rename column XML_TYPE to NOTIFICATION_TYPE;
+alter table NOTIFICATION
+ rename column XML_DATA to NOTIFICATION_DATA;
+
-- Now update the version
update CALENDARSERVER set VALUE = '29' where NAME = 'VERSION';
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/notification_upgrade_from_0_to_1.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -27,7 +27,6 @@
from txdav.xml.parser import WebDAVDocument
from twistedcaldav.sharing import invitationBindStatusFromXMLMap, \
invitationBindModeFromXMLMap
-import json
"""
Data upgrade from database version 0 to 1
@@ -79,7 +78,7 @@
"""
# Convert the type value to JSON
- xmltype = WebDAVDocument.fromString(notification._xmlType).root_element
+ xmltype = WebDAVDocument.fromString(notification.notificationType()).root_element
shared_type = "calendar"
if xmltype.children[0].qname() == customxml.InviteNotification.qname():
jsontype = {"notification-type": "invite-notification"}
@@ -90,7 +89,7 @@
jsontype = {"notification-type": "invite-reply"}
# Convert the data value to JSON
- xmldata = (yield notification.xmldata())
+ xmldata = (yield notification.notificationData())
xmldata = WebDAVDocument.fromString(xmldata).root_element
def _extract_UID(uri):
@@ -163,6 +162,4 @@
"summary": summary,
}
- jsontype = json.dumps(jsontype)
- jsondata = json.dumps(jsondata)
yield notification.setData(notification.uid(), jsontype, jsondata)
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/upgrade/sql/upgrades/test/test_notification_upgrade_from_0_to_1.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -23,8 +23,6 @@
_BIND_MODE_WRITE, _BIND_STATUS_ACCEPTED, _BIND_MODE_READ
from txdav.common.datastore.upgrade.sql.upgrades.notification_upgrade_from_0_to_1 import doUpgrade
-import json
-
"""
Tests for L{txdav.common.datastore.upgrade.sql.upgrade}.
"""
@@ -170,9 +168,9 @@
),
)
- for uid, xmltype, _ignore_jtype, xmldata, _ignore_jdata in data:
+ for uid, notificationtype, _ignore_jtype, notificationdata, _ignore_jdata in data:
notifications = yield self.transactionUnderTest().notificationsWithUID("user01")
- yield notifications.writeNotificationObject(uid, xmltype, xmldata)
+ yield notifications.writeNotificationObject(uid, notificationtype, notificationdata)
# Force data version to previous
nh = notifications._homeSchema
@@ -188,9 +186,9 @@
version = (yield notifications.dataVersion())
self.assertEqual(version, 1)
- for uid, _ignore_xmltype, jtype, _ignore_xmldata, jdata in data:
+ for uid, _ignore_notificationtype, jtype, _ignore_notificationdata, jdata in data:
notification = (yield notifications.notificationObjectWithUID(uid))
self.assertTrue(notification is not None, msg="Failed {uid}".format(uid=uid))
- self.assertEqual(json.loads(notification.xmlType()), jtype, msg="Failed {uid}".format(uid=uid))
- data = (yield notification.xmldata())
- self.assertEqual(json.loads(data), jdata, msg="Failed {uid}".format(uid=uid))
+ self.assertEqual(notification.notificationType(), jtype, msg="Failed {uid}".format(uid=uid))
+ data = (yield notification.notificationData())
+ self.assertEqual(data, jdata, msg="Failed {uid}".format(uid=uid))
Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/inotifications.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/inotifications.py 2013-11-14 03:47:16 UTC (rev 11945)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/inotifications.py 2013-11-14 17:35:45 UTC (rev 11946)
@@ -72,10 +72,10 @@
object exists.
"""
- def writeNotificationObject(uid, xmltype, xmldata): #@NoSelf
+ def writeNotificationObject(uid, notificationtype, notificationdata): #@NoSelf
"""
Write a notification with the given C{uid} in this notification
- collection from the given C{xmldata} with given C{xmltype}. If a
+ collection from the given C{notificationdata} with given C{notificationtype}. If a
L{INotificationObject} with the same uid already exists in this
L{INotificationCollection}, it will be overwritten.
@@ -83,18 +83,12 @@
written.
@type uid: C{str}
- @param xmltype: the node within the notification payload, emptied of
- its children, to indicate the type of notification and fill out the
- C{CS:notificationtype} property.
+ @param notificationtype: the type of notification as a C{dict}.
- @type xmltype: an instance of
- L{txdav.xml.base.WebDAVElement},
- most likely a subclass like L{twistedcaldav.customxml.InviteReply},
- L{twistedcaldav.customxml.InviteRemove}, etc.
+ @type notificationtype: C{dict}
- @param xmldata: the serialized representation of the C{CS:notification}
- node.
- @type xmldata: C{str}
+ @param notificationdata: the representation of the notification data as a C{dict}.
+ @type notificationdata: C{dict}
"""
def removeNotificationObjectWithName(name): #@NoSelf
@@ -142,23 +136,23 @@
An notification object describes an XML notification.
"""
- def setData(uid, xmltype, xmldata, inserting=False): #@NoSelf
+ def setData(uid, notificationtype, notificationdata, inserting=False): #@NoSelf
"""
- Rewrite this notification object to match the given C{xmltype} and
- C{xmldata}. C{xmldata} must have the same UID as this notification object.
+ Rewrite this notification object to match the given C{notificationtype} and
+ C{notificationdata}. C{notificationdata} must have the same UID as this notification object.
- @param xmltype: a string.
- @param xmldata: a string.
+ @param notificationtype: a string.
+ @param notificationdata: a string.
@raise InvalidObjectResourceError: if the given
- C{xmltype} or C{xmldata} is not a valid for
+ C{notificationtype} or C{notificationdata} is not a valid for
an notification object.
"""
- def xmldata(): #@NoSelf
+ def notificationData(): #@NoSelf
"""
Retrieve the notification data for this notification object.
- @return: a string.
+ @return: a C{dict}.
"""
def uid(): #@NoSelf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/f3e9f5a4/attachment.html>
More information about the calendarserver-changes
mailing list