changeset 2:9dbb9354abbe

getPublications erweitert nach Typ ausserdem erh?lt man jetzt auch einzelne Publicationen nach escidoc:id
author dwinter
date Mon, 29 Apr 2013 15:58:16 +0200
parents c6478f155400
children 602b6e46b176
files zopePubmanConnector.py
diffstat 1 files changed, 117 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/zopePubmanConnector.py	Sat Apr 27 10:05:39 2013 +0200
+++ b/zopePubmanConnector.py	Mon Apr 29 15:58:16 2013 +0200
@@ -58,33 +58,142 @@
             return pt()
         
         
-    def getPublications(self,personID):
+    def getPublications(self,personID,limit=None,publicationType=None):
         """get all publications der personID"""
         h = httplib2.Http()
         
         
-        self.connectorString+="cqlQuery=escidoc.any-identifier=%22"+personID+"%22&"
-        self.connectorString+="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
+        
+        if publicationType is None:
+            cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22&"
+        else:
+            cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22"
+            cn +="%20and%20escidoc.publication.type=%22"+publicationType+"%22&"
+        
+        cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
+        if limit:
+            cn+="&maximumRecords=%s"%limit
   
-        logging.debug(self.connectorString)
-        resp, content = h.request(self.connectorString)
+        logging.debug(cn)
+        resp, content = h.request(cn)
+    
+        logging.debug(content)
+    
         ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
 
         root = ET.fromstring(content)
         
+        #<escidocItem:item objid="escidoc:630782" 
+        
         citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
         
-        citations=root.findall(citationxpath)
+        objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
+        citations=root.findall(objxpath)
         
         ret=[]
-
         for citation in citations:
-            ret.append(citation.text)
+            objId = citation.get('objid')
+            
+            text = citation.find(citationxpath)
+            
+            ret.append((objId,text.text))
 
         
         
         return ret
     
+    
+    def search(self,values,exact=False):
+        
+        """search pubman
+        @values map mit field->value
+        @return map mit escidocId -> XML-formatted snippeds
+        """
+        
+        fieldToEscidoc={"title":"escidoc.any-title",
+                        "author":"escidoc.publication.any.publication-creator-names",
+                        "any":"escidoc.any-metadata"}
+        
+             
+        cn = self.connectorString+"cqlQuery=%s&"
+        cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
+        
+       
+       
+        querys = []
+        for field in values.keys():
+        
+            searchField = fieldToEscidoc.get(field,None)
+            if searchField is None:
+                logging.debug("search, don't know field: %s"%field)
+                continue
+            
+            
+            value = values[field]
+            
+            if value == '':
+                continue
+            logging.debug("%s=%s"%(field,value))
+            if not exact:
+                value=value+"*"
+   
+        
+            querys.append("%s=%%22%s%%22"%(searchField,value))
+        
+        
+        query=" AND ".join(querys)
+        h = httplib2.Http()
+       
+        logging.debug(cn%query)
+        resp, content = h.request(cn%query)
+       
+        ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
+
+        root = ET.fromstring(content)
+        
+        #<escidocItem:item objid="escidoc:630782" 
+        
+        citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
+        
+        objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
+        citations=root.findall(objxpath)
+        
+        ret={}
+        for citation in citations:
+            objId = citation.get('objid')
+            
+            text = citation.find(citationxpath)
+            
+            ret[objId]=text.text
+
+        
+        
+        return ret
+        
+         
+        
+    def getEntryFromPubman(self,escidocid):
+        
+        h = httplib2.Http()
+        cn = self.connectorString+"cqlQuery=escidoc.objid=%s&"
+        cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
+      
+        resp, content = h.request(cn%escidocid)
+        ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
+
+        root = ET.fromstring(content)
+        
+        
+        citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
+        
+        citation=root.find(citationxpath)
+        
+        if citation is not None:
+
+            return citation.text
+    
+        return ""
+        
     def pubmanConnectorURL(self):
         return self.connectorString