]> git.parisson.com Git - telemeta.git/commitdiff
#67: let the OAI-PMH and Dublin Core identifiers be one and the same
authorolivier <>
Fri, 3 Apr 2009 14:55:16 +0000 (14:55 +0000)
committerolivier <>
Fri, 3 Apr 2009 14:55:16 +0000 (14:55 +0000)
telemeta/interop/oai.py
telemeta/interop/oaitest.py

index 2c77a0d6ebfbcc3c638d03d5c0373fc72bb55ca3..bea62f974db11f37d88a5e180816d4db61c1a5e0 100644 (file)
@@ -46,23 +46,25 @@ class IDataSource(object):
         pass
 
     def get_record(self, id):
-        """Must return a tuple with :
-             - record as (dict,timestamp) of Dublin Core elements
-             - last changetime as a datetime object
-           or None if the record doesn't exist"""
+        """Must return a tuple of the form (dublin core dict, change time)
+           or None if the record doesn't exist.
+           
+           The dublin core data must contain an 'identifier' element, which is the same
+           as the id parameter."""
         pass
 
     def count_records(self, from_time = None, until_time = None):
-        """Must return the number of record identifiers between (optional) from and 
-           until change time."""
+        """Must return the number of records between (optional) from and until change time."""
         pass
 
     def list_records(self, offset, limit, from_time = None, until_time = None):
         """Must return the list of records between (optional) from and 
            until change time, starting from record at offset, with a maximum of limit
-           entries. Each entry of the list must be a tuple containing the identifier, a dict
-           containing dublin core data, and the change time. If no record matches, should return
-           an empty list."""
+           entries. Each entry of the list must be a tuple of the form:
+           (dublin core dict, change time)
+
+           If no record matches, should return an empty list. The dublin core data must
+           contain an 'identifier' element, which can be used as a parameter to get_record()."""
         pass
 
 def iso_time(date_time = None):
@@ -338,6 +340,12 @@ class Response(object):
             self.error('idDoesNotExist')
         else:
             dc, ctime = record
+            if not dc.get('identifier'):
+                raise Exception("DataSource.get_record() didn't provide an 'identifier' dublin core element")
+            elif dc["identifier"] != id:
+                raise Exception("DataSource.get_record() returned an 'identifier' dublin core element "
+                                "which is different from the requested identifier")
+                
             self.set_attributes(self.request, {'identifier': id, 'metadataPrefix': 'oai_dc'})
             container = self.root.appendChild(self.doc.createElement(self.verb))
             container.appendChild(self.make_record(id, dc, ctime))
@@ -367,7 +375,11 @@ class Response(object):
         if len(data):
             container = self.root.appendChild(self.doc.createElement(self.verb))
             for item in data:
-                id, dc, ctime = item
+                dc, ctime = item
+                if not dc.get('identifier'):
+                    raise Exception("DataSource.list_records() didn't provide an 'identifier' dublin core element")
+
+                id = dc['identifier']    
                 if ids_only:
                     container.appendChild(self.make_record_header(id, ctime))
                 else:
index a830baa5acb5aacaa6793f2be09c4f57bc2af1b8..fcd75239e8dd0d63747bf8649cd8649e95be9208 100644 (file)
@@ -19,7 +19,10 @@ class DataSource(object):
         return self.oldest
 
     def get_record(self, id):
-        return self.data.get(id)
+        record = self.data.get(id)
+        if record:
+            record['identifier'] = id
+        return record
 
     def count_records(self, from_time = None, until_time = None):        
         result = 0
@@ -36,9 +39,10 @@ class DataSource(object):
         n = 0
         for k in self.data:
             dc, ctime = self.data[k]
+            dc['identifier'] = k
             if ((not from_time) or ctime >= from_time) and ((not until_time) or ctime <= until_time):
                 if (i >= offset) and (n < limit):
-                    result.append((k, dc, ctime))
+                    result.append((dc, ctime))
                     n += 1
                 i += 1
         return result