[CalendarServer-changes] [12882] CalendarServer/branches/users/sagen/move2who-2/txdav

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 12:59:21 PDT 2014


Revision: 12882
          http://trac.calendarserver.org//changeset/12882
Author:   sagen at apple.com
Date:     2014-03-12 12:59:21 -0700 (Wed, 12 Mar 2014)
Log Message:
-----------
recordsMatchingFields now works accross AMP

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-2/txdav/dps/client.py
    CalendarServer/branches/users/sagen/move2who-2/txdav/dps/commands.py
    CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py
    CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py

Modified: CalendarServer/branches/users/sagen/move2who-2/txdav/dps/client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-2/txdav/dps/client.py	2014-03-12 18:49:18 UTC (rev 12881)
+++ CalendarServer/branches/users/sagen/move2who-2/txdav/dps/client.py	2014-03-12 19:59:21 UTC (rev 12882)
@@ -20,6 +20,7 @@
 from twext.python.log import Logger
 from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
 from twext.who.directory import DirectoryService as BaseDirectoryService
+from twext.who.expression import Operand
 from twext.who.idirectory import RecordType, IDirectoryService
 import twext.who.idirectory
 from twext.who.util import ConstantsContainer
@@ -33,7 +34,7 @@
 from txdav.dps.commands import (
     RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
     RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
-    RecordsMatchingTokensCommand,
+    RecordsMatchingTokensCommand, RecordsMatchingFieldsCommand,
     MembersCommand, GroupsCommand, SetMembersCommand,
     VerifyPlaintextPasswordCommand, VerifyHTTPDigestCommand
 )
@@ -244,15 +245,33 @@
         )
 
 
-    def recordsMatchingFields(self, fields, operand="or", recordType=None):
-        # MOVE2WHO FIXME: Need to add an AMP command
-        raise NotImplementedError
+    def recordsMatchingFields(self, fields, operand=Operand.OR, recordType=None):
 
+        newFields = []
+        for fieldName, searchTerm, matchFlags, matchType in fields:
+            newFields.append(
+                (
+                    fieldName.encode("utf-8"),
+                    searchTerm.encode("utf-8"),
+                    matchFlags.name.encode("utf-8"),
+                    matchType.name.encode("utf-8")
+                )
+            )
+        if recordType is not None:
+            recordType = recordType.name.encode("utf-8")
 
+        return self._call(
+            RecordsMatchingFieldsCommand,
+            self._processMultipleRecords,
+            fields=newFields,
+            operand=operand.name.encode("utf-8"),
+            recordType=recordType
+        )
 
 
 
 
+
 @implementer(ICalendarStoreDirectoryRecord)
 class DirectoryRecord(BaseDirectoryRecord, CalendarDirectoryRecordMixin):
 

Modified: CalendarServer/branches/users/sagen/move2who-2/txdav/dps/commands.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-2/txdav/dps/commands.py	2014-03-12 18:49:18 UTC (rev 12881)
+++ CalendarServer/branches/users/sagen/move2who-2/txdav/dps/commands.py	2014-03-12 19:59:21 UTC (rev 12882)
@@ -77,6 +77,17 @@
     ]
 
 
+class RecordsMatchingFieldsCommand(amp.Command):
+    arguments = [
+        ('fields', amp.ListOf(amp.ListOf(amp.String()))),
+        ('operand', amp.String()),
+        ('recordType', amp.String(optional=True)),
+    ]
+    response = [
+        ('fieldsList', amp.String()),
+    ]
+
+
 class UpdateRecordsCommand(amp.Command):
     arguments = [
         ('fieldsList', amp.String()),

Modified: CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py	2014-03-12 18:49:18 UTC (rev 12881)
+++ CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py	2014-03-12 19:59:21 UTC (rev 12882)
@@ -21,6 +21,7 @@
 from calendarserver.tap.util import getDBPool, storeFromConfig
 from twext.python.log import Logger
 from twext.who.aggregate import DirectoryService as AggregateDirectoryService
+from twext.who.expression import MatchType, MatchFlags, Operand
 from twext.who.idirectory import RecordType
 from twext.who.ldap import DirectoryService as LDAPDirectoryService
 from twisted.application import service
@@ -39,7 +40,7 @@
 from txdav.dps.commands import (
     RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
     RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
-    RecordsMatchingTokensCommand,
+    RecordsMatchingTokensCommand, RecordsMatchingFieldsCommand,
     MembersCommand, GroupsCommand, SetMembersCommand,
     VerifyPlaintextPasswordCommand, VerifyHTTPDigestCommand,
     # UpdateRecordsCommand, RemoveRecordsCommand
@@ -190,6 +191,33 @@
         returnValue(response)
 
 
+    @RecordsMatchingFieldsCommand.responder
+    @inlineCallbacks
+    def recordsMatchingFields(self, fields, operand="OR", recordType=None):
+        log.debug("RecordsMatchingFields")
+        newFields = []
+        for fieldName, searchTerm, matchFlags, matchType in fields:
+            fieldName = fieldName.decode("utf-8")
+            searchTerm = searchTerm.decode("utf-8")
+            matchFlags = MatchFlags.lookupByName(matchFlags.decode("utf-8"))
+            matchType = MatchType.lookupByName(matchType.decode("utf-8"))
+            newFields.append((fieldName, searchTerm, matchFlags, matchType))
+        operand = Operand.lookupByName(operand)
+        if recordType:
+            recordType = RecordType.lookupByName(recordType)
+        records = yield self._directory.recordsMatchingFields(
+            newFields, operand=operand, recordType=recordType
+        )
+        fieldsList = []
+        for record in records:
+            fieldsList.append(self.recordToDict(record))
+        response = {
+            "fieldsList": pickle.dumps(fieldsList),
+        }
+        log.debug("Responding with: {response}", response=response)
+        returnValue(response)
+
+
     @MembersCommand.responder
     @inlineCallbacks
     def members(self, uid):

Modified: CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py	2014-03-12 18:49:18 UTC (rev 12881)
+++ CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py	2014-03-12 19:59:21 UTC (rev 12882)
@@ -134,14 +134,14 @@
         """
         subExpressions = []
         for fieldName, searchTerm, matchFlags, matchType in fields:
-            subExpressions.append(
-                MatchExpression(
-                    self.fieldName.lookupByName(fieldName),
-                    searchTerm,
-                    matchType,
-                    matchFlags
-                )
+            subExpression = MatchExpression(
+                self.fieldName.lookupByName(fieldName),
+                searchTerm,
+                matchType,
+                matchFlags
             )
+            subExpressions.append(subExpression)
+
         expression = CompoundExpression(subExpressions, operand)
         return self.recordsFromExpression(expression)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/394ddbec/attachment.html>


More information about the calendarserver-changes mailing list