0
|
1 # -*- coding: utf-8 -*-
|
|
2
|
|
3 #Verbindet Zope mit pubman.
|
|
4
|
|
5
|
|
6 from OFS.SimpleItem import SimpleItem
|
|
7 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
|
|
8 import os.path
|
|
9
|
|
10 from Globals import package_home
|
|
11 import httplib2
|
|
12 import urlparse
|
|
13 import urllib
|
|
14 import re
|
|
15 import xml.etree.ElementTree as ET
|
|
16 import json
|
1
|
17 import logging
|
0
|
18
|
|
19 def zptFile(self, path, orphaned=False):
|
|
20 """returns a page template file from the product"""
|
|
21 if orphaned:
|
|
22 # unusual case
|
|
23 pt=PageTemplateFile(os.path.join(package_home(globals()), path))
|
|
24 else:
|
|
25
|
|
26 pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self)
|
|
27 return pt
|
|
28
|
|
29 class ZopePubmanConnector(SimpleItem):
|
|
30
|
|
31
|
|
32 connectorString="http://pubman.mpiwg-berlin.mpg.de/search/SearchAndExport?"
|
|
33
|
|
34
|
|
35 meta_type="ZopePubmanConnector"
|
|
36
|
|
37 manage_options= ({'label':'Main Config','action': 'changeMain'},) + SimpleItem.manage_options
|
|
38
|
|
39 def __init__(self,id,title,pubmanURL):
|
|
40 self.id=id
|
|
41 self.title=title
|
|
42 self.pubmanURL=pubmanURL #URL einer pubman instance bzw. einer collection, falls nicht die default collection benutzt werden soll
|
|
43
|
|
44
|
|
45
|
|
46 def changeMain(self,pubmanURL=None,title=None,REQUEST=None,RESPONSE=None):
|
|
47 """change main settings"""
|
|
48 if pubmanURL:
|
|
49 self.pubmanURL=pubmanURL
|
|
50 self.title=title
|
|
51
|
|
52 if RESPONSE is not None:
|
|
53 RESPONSE.redirect('manage_main')
|
|
54
|
|
55
|
|
56 else:
|
|
57 pt=zptFile(self, 'zpt/ChangeZopePubmanConnector.zpt')
|
|
58 return pt()
|
|
59
|
|
60
|
2
|
61 def getPublications(self,personID,limit=None,publicationType=None):
|
0
|
62 """get all publications der personID"""
|
|
63 h = httplib2.Http()
|
1
|
64
|
|
65
|
2
|
66
|
|
67 if publicationType is None:
|
|
68 cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22&"
|
|
69 else:
|
|
70 cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22"
|
|
71 cn +="%20and%20escidoc.publication.type=%22"+publicationType+"%22&"
|
|
72
|
|
73 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
|
|
74 if limit:
|
|
75 cn+="&maximumRecords=%s"%limit
|
1
|
76
|
2
|
77 logging.debug(cn)
|
|
78 resp, content = h.request(cn)
|
|
79
|
3
|
80
|
2
|
81
|
0
|
82 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
|
|
83
|
|
84 root = ET.fromstring(content)
|
|
85
|
2
|
86 #<escidocItem:item objid="escidoc:630782"
|
|
87
|
0
|
88 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
|
|
89
|
2
|
90 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
|
|
91 citations=root.findall(objxpath)
|
0
|
92
|
|
93 ret=[]
|
|
94 for citation in citations:
|
2
|
95 objId = citation.get('objid')
|
|
96
|
|
97 text = citation.find(citationxpath)
|
|
98
|
|
99 ret.append((objId,text.text))
|
0
|
100
|
|
101
|
|
102
|
|
103 return ret
|
|
104
|
2
|
105
|
5
|
106 def search(self,values={},exact=False,limit=None,contexts=None):
|
2
|
107
|
|
108 """search pubman
|
|
109 @values map mit field->value
|
|
110 @return map mit escidocId -> XML-formatted snippeds
|
|
111 """
|
|
112
|
|
113 fieldToEscidoc={"title":"escidoc.any-title",
|
|
114 "author":"escidoc.publication.any.publication-creator-names",
|
|
115 "any":"escidoc.any-metadata"}
|
|
116
|
|
117
|
|
118 cn = self.connectorString+"cqlQuery=%s&"
|
|
119 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
|
|
120
|
5
|
121 if limit:
|
|
122 cn+="&maximumRecords=%s"%limit
|
|
123
|
|
124
|
2
|
125
|
|
126
|
|
127 querys = []
|
|
128 for field in values.keys():
|
|
129
|
|
130 searchField = fieldToEscidoc.get(field,None)
|
|
131 if searchField is None:
|
|
132 logging.debug("search, don't know field: %s"%field)
|
|
133 continue
|
|
134
|
|
135
|
|
136 value = values[field]
|
|
137
|
|
138 if value == '':
|
|
139 continue
|
|
140 logging.debug("%s=%s"%(field,value))
|
|
141 if not exact:
|
|
142 value=value+"*"
|
|
143
|
|
144
|
|
145 querys.append("%s=%%22%s%%22"%(searchField,value))
|
|
146
|
|
147
|
5
|
148 query="+AND+".join(querys)
|
|
149
|
|
150
|
|
151 if contexts: # einscbraenken auf contexte
|
|
152
|
|
153 if isinstance(contexts, str):
|
|
154 contexts=[contexts]
|
|
155
|
|
156 ctxquerys=[]
|
|
157 for context in contexts:
|
|
158 ctxquerys.append("escidoc.context.objid=%%22%s%%22"%(context))
|
|
159
|
|
160 ctxquery="+OR+".join(ctxquerys)
|
|
161
|
|
162 if query!="":
|
|
163 query=query+"AND (%s)"%ctxquery
|
|
164 else:
|
|
165 query="(%s)"%ctxquery
|
|
166
|
2
|
167 h = httplib2.Http()
|
|
168
|
|
169 logging.debug(cn%query)
|
|
170 resp, content = h.request(cn%query)
|
|
171
|
|
172 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
|
|
173
|
3
|
174 try:
|
|
175 root = ET.fromstring(content)
|
|
176 except:
|
|
177 logging.error("Couldn't parse content of:%s"%(cn%query))
|
|
178 return {}
|
2
|
179 #<escidocItem:item objid="escidoc:630782"
|
|
180
|
|
181 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
|
|
182
|
|
183 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
|
|
184 citations=root.findall(objxpath)
|
|
185
|
|
186 ret={}
|
|
187 for citation in citations:
|
|
188 objId = citation.get('objid')
|
|
189
|
|
190 text = citation.find(citationxpath)
|
|
191
|
|
192 ret[objId]=text.text
|
|
193
|
|
194
|
|
195
|
|
196 return ret
|
|
197
|
|
198
|
|
199
|
|
200 def getEntryFromPubman(self,escidocid):
|
4
|
201 """get one entry"""
|
|
202
|
3
|
203 escidocid=escidocid.lstrip().strip()
|
2
|
204 h = httplib2.Http()
|
|
205 cn = self.connectorString+"cqlQuery=escidoc.objid=%s&"
|
|
206 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
|
|
207
|
|
208 resp, content = h.request(cn%escidocid)
|
|
209 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
|
3
|
210 logging.debug(cn%escidocid)
|
4
|
211
|
2
|
212 root = ET.fromstring(content)
|
|
213
|
|
214
|
|
215 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
|
|
216
|
|
217 citation=root.find(citationxpath)
|
|
218
|
|
219 if citation is not None:
|
|
220
|
|
221 return citation.text
|
|
222
|
|
223 return ""
|
|
224
|
0
|
225 def pubmanConnectorURL(self):
|
|
226 return self.connectorString
|
4
|
227
|
|
228
|
|
229
|
|
230 def getPreprintsFromContext(self,context,limit=None,publicationType=None):
|
|
231 """get all publications des context"""
|
|
232 h = httplib2.Http()
|
|
233
|
|
234
|
|
235
|
|
236 if publicationType is None:
|
|
237 cn = self.connectorString+"cqlQuery=escidoc.context.objid=%22"+context+"%22&"
|
|
238 #cn = self.connectorString+"cqlQuery=escidoc.objid=%22"+"escidoc:643455"+"%22&"
|
|
239 else:
|
|
240 cn = self.connectorString+"cqlQuery=escidoc.context.objid=%22"+context+"%22"
|
|
241 cn +="%20and%20escidoc.publication.type=%22"+publicationType+"%22&"
|
|
242
|
|
243 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
|
|
244 if limit:
|
|
245 cn+="&maximumRecords=%s"%limit
|
|
246
|
|
247 logging.debug(cn)
|
|
248 resp, content = h.request(cn)
|
|
249
|
|
250
|
|
251 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
|
|
252
|
|
253 root = ET.fromstring(content)
|
|
254
|
|
255 #<escidocItem:item objid="escidoc:630782"
|
|
256
|
|
257 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
|
|
258 abstractpath=".//{http://purl.org/dc/terms/}abstract"
|
|
259
|
|
260
|
|
261 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
|
|
262 srcpath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/publication}source"
|
|
263 volumepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}volume"
|
|
264
|
|
265 #linkspath=""".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content[@storage="internal-managed"]"""
|
|
266 linkspath=""".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content[@storage="external-url"]"""
|
|
267 #linkspath=".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content"
|
|
268 citations=root.findall(objxpath)
|
|
269
|
|
270 ret=[]
|
|
271 for citation in citations:
|
|
272 objId = citation.get('objid')
|
|
273
|
|
274 text = citation.find(citationxpath)
|
|
275
|
|
276 #Get volume = preprintID
|
|
277 # <publication:source type="series">
|
|
278 # <dc:title>Max-Planck-Institut für Wissenschaftsgeschichte : Preprint</dc:title>
|
|
279 # <escidoc:volume>437</escidoc:volume>
|
|
280
|
|
281
|
|
282
|
|
283 src= citation.find(srcpath)
|
|
284 vol = src.find(volumepath)
|
|
285
|
|
286
|
|
287 #get link to fulltext
|
|
288 #<escidocComponents:component objid="escidoc:644183">
|
|
289 #<escidocComponents:properties>
|
|
290 # <prop:creation-date>2013-04-29T09:00:01.100Z</prop:creation-date>
|
|
291 # <prop:valid-status>valid</prop:valid-status>
|
|
292 # <prop:visibility>public</prop:visibility>
|
|
293 # <prop:content-category>pre-print</prop:content-category>
|
|
294 # <prop:file-name>P437.PDF</prop:file-name>
|
|
295 # <prop:mime-type>application/pdf</prop:mime-type>
|
|
296 # <prop:checksum>d0ccdc62d6707d934e60e9839ffe30bf</prop:checksum>
|
|
297 # <prop:checksum-algorithm>MD5</prop:checksum-algorithm>
|
|
298 #</escidocComponents:properties>
|
|
299 #<escidocComponents:content xlink:type="simple" xlink:title="P437.PDF" storage="internal-managed"
|
|
300 # xlink:href="http://pubman.mpiwg-berlin.mpg.de/pubman/item/escidoc:643686:3/component/escidoc:644183/P437.PDF"/>
|
|
301 #
|
|
302
|
|
303 src= citation.find(linkspath)
|
|
304 if src is not None:
|
|
305
|
|
306 link=src.get("{http://www.w3.org/1999/xlink}href")
|
|
307 #logging.debug(src.attrib)
|
|
308
|
|
309 else:
|
|
310 link =""
|
|
311
|
|
312
|
|
313 #<dcterms:abstract xml:lang="deu">Dieser Preprint versammelt eine Auswahl von Beiträgen zum Symposium zu Ehren von Hans-Jörg Rheinbergers 65. Geburtstag. Es fand am 24.1.2011 im Max-Planck-Institute für Wissenschaftsgeschichte statt und brachte Freunde, Studenten und Kollegen von Hans-Jörg Rheinberger zusammen.</dcterms:abstract>
|
|
314 #<dcterms:abstract xml:lang="eng">In this preprint, a selection of contributions to the symposium in honor of Hans-Jörg Rheinberger’s 65th birthday is published. It took place on January 24, 2011 at the Max-Planck-Institute for the History of Science and assembled friends, students and colleagues of Hans-Jörg Rheinberger.</dcterms:abstract>
|
|
315
|
|
316
|
|
317
|
|
318 abstracts = citation.findall(abstractpath)
|
|
319
|
|
320 abstractTexts={}
|
|
321 for abstract in abstracts:
|
|
322
|
|
323 lang = abstract.get("{http://www.w3.org/XML/1998/namespace}lang")
|
|
324 abstractTexts[lang]=abstract.text
|
|
325
|
|
326
|
|
327 #if abstractDE is not None:
|
|
328 # abstactDEtext = abstractDE.text
|
|
329 #else:
|
|
330 # abstactDEtext = ""
|
|
331
|
|
332 # abstractEN = citation.find(abstractENpath)
|
|
333 # if abstractEN is not None:
|
|
334 # abstactENtext = abstractEN.text
|
|
335 # else:
|
|
336 # abstactENtext = ""
|
|
337 #
|
|
338
|
|
339 ret.append((objId,text.text,vol.text,link,abstractTexts))
|
|
340
|
|
341
|
|
342 def cmpret(x,y): #sort by preprint number
|
|
343 try:
|
|
344 return -cmp(int(x[2]),int(y[2]))
|
|
345 except:
|
|
346 return 0
|
|
347 #return cmp(x[2],y[2])
|
|
348
|
|
349 ret.sort(cmpret)
|
|
350 return ret
|
|
351
|
|
352
|
|
353
|
0
|
354
|
|
355 def manage_addZopePubmanConnectorForm(self):
|
|
356 """Form for external Links"""
|
|
357 pt=zptFile(self, 'zpt/AddZopePubmanConnector.zpt')
|
|
358 return pt()
|
|
359
|
|
360
|
|
361 def manage_addZopePubmanConnector(self,id,title,pubmanURL,RESPONSE=None):
|
|
362 """Add an external Link"""
|
|
363
|
|
364 newObj=ZopePubmanConnector(id,title,pubmanURL)
|
|
365
|
|
366 self._setObject(id,newObj)
|
|
367
|
|
368
|
|
369 if RESPONSE is not None:
|
|
370 RESPONSE.redirect('manage_main')
|
|
371 |