annotate zopePubmanConnector.py @ 18:da890cb0fd04

shows also context if wanted in getEntryFromPubman
author dwinter
date Wed, 26 Jun 2013 16:02:02 +0200
parents 48c4a6f3b135
children 38ff05179d71
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
373e6610e290 initial
dwinter
parents:
diff changeset
1 # -*- coding: utf-8 -*-
373e6610e290 initial
dwinter
parents:
diff changeset
2
373e6610e290 initial
dwinter
parents:
diff changeset
3 #Verbindet Zope mit pubman.
373e6610e290 initial
dwinter
parents:
diff changeset
4
373e6610e290 initial
dwinter
parents:
diff changeset
5
373e6610e290 initial
dwinter
parents:
diff changeset
6 from OFS.SimpleItem import SimpleItem
373e6610e290 initial
dwinter
parents:
diff changeset
7 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
373e6610e290 initial
dwinter
parents:
diff changeset
8 import os.path
373e6610e290 initial
dwinter
parents:
diff changeset
9
373e6610e290 initial
dwinter
parents:
diff changeset
10 from Globals import package_home
373e6610e290 initial
dwinter
parents:
diff changeset
11 import httplib2
373e6610e290 initial
dwinter
parents:
diff changeset
12 import xml.etree.ElementTree as ET
1
c6478f155400 id eingebaut
dwinter
parents: 0
diff changeset
13 import logging
9
166482535b54 timing output for debugging.
casties
parents: 8
diff changeset
14 import time
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
15 import unicodedata
6
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
16
16
3e154b154b6f timeouts
dwinter
parents: 15
diff changeset
17 TIMEOUT=10
3e154b154b6f timeouts
dwinter
parents: 15
diff changeset
18
6
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
19 cacheFolder ="/var/tmp/.cacheWWW"
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
20
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
21 ns = {'escidocMetadataProfile':"http://escidoc.mpg.de/metadataprofile/schema/0.1/",
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
22 'escidocMetadataRecords':"http://www.escidoc.de/schemas/metadatarecords/0.4",
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
23 'dc':'http://purl.org/dc/elements/1.1/',
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
24 'escidocComponents':'http://www.escidoc.de/schemas/components/0.8',
18
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
25 'escidocItem':'http://www.escidoc.de/schemas/item/0.8',
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
26 'srel':'http://escidoc.de/core/01/structural-relations/',
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
27 }
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
28
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
29
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
30
0
373e6610e290 initial
dwinter
parents:
diff changeset
31 def zptFile(self, path, orphaned=False):
373e6610e290 initial
dwinter
parents:
diff changeset
32 """returns a page template file from the product"""
373e6610e290 initial
dwinter
parents:
diff changeset
33 if orphaned:
373e6610e290 initial
dwinter
parents:
diff changeset
34 # unusual case
373e6610e290 initial
dwinter
parents:
diff changeset
35 pt=PageTemplateFile(os.path.join(package_home(globals()), path))
373e6610e290 initial
dwinter
parents:
diff changeset
36 else:
373e6610e290 initial
dwinter
parents:
diff changeset
37
373e6610e290 initial
dwinter
parents:
diff changeset
38 pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self)
373e6610e290 initial
dwinter
parents:
diff changeset
39 return pt
373e6610e290 initial
dwinter
parents:
diff changeset
40
373e6610e290 initial
dwinter
parents:
diff changeset
41 class ZopePubmanConnector(SimpleItem):
373e6610e290 initial
dwinter
parents:
diff changeset
42
373e6610e290 initial
dwinter
parents:
diff changeset
43
373e6610e290 initial
dwinter
parents:
diff changeset
44 connectorString="http://pubman.mpiwg-berlin.mpg.de/search/SearchAndExport?"
373e6610e290 initial
dwinter
parents:
diff changeset
45
373e6610e290 initial
dwinter
parents:
diff changeset
46
373e6610e290 initial
dwinter
parents:
diff changeset
47 meta_type="ZopePubmanConnector"
373e6610e290 initial
dwinter
parents:
diff changeset
48
373e6610e290 initial
dwinter
parents:
diff changeset
49 manage_options= ({'label':'Main Config','action': 'changeMain'},) + SimpleItem.manage_options
373e6610e290 initial
dwinter
parents:
diff changeset
50
373e6610e290 initial
dwinter
parents:
diff changeset
51 def __init__(self,id,title,pubmanURL):
373e6610e290 initial
dwinter
parents:
diff changeset
52 self.id=id
373e6610e290 initial
dwinter
parents:
diff changeset
53 self.title=title
373e6610e290 initial
dwinter
parents:
diff changeset
54 self.pubmanURL=pubmanURL #URL einer pubman instance bzw. einer collection, falls nicht die default collection benutzt werden soll
373e6610e290 initial
dwinter
parents:
diff changeset
55
373e6610e290 initial
dwinter
parents:
diff changeset
56
373e6610e290 initial
dwinter
parents:
diff changeset
57
373e6610e290 initial
dwinter
parents:
diff changeset
58 def changeMain(self,pubmanURL=None,title=None,REQUEST=None,RESPONSE=None):
373e6610e290 initial
dwinter
parents:
diff changeset
59 """change main settings"""
373e6610e290 initial
dwinter
parents:
diff changeset
60 if pubmanURL:
373e6610e290 initial
dwinter
parents:
diff changeset
61 self.pubmanURL=pubmanURL
373e6610e290 initial
dwinter
parents:
diff changeset
62 self.title=title
373e6610e290 initial
dwinter
parents:
diff changeset
63
373e6610e290 initial
dwinter
parents:
diff changeset
64 if RESPONSE is not None:
373e6610e290 initial
dwinter
parents:
diff changeset
65 RESPONSE.redirect('manage_main')
373e6610e290 initial
dwinter
parents:
diff changeset
66
373e6610e290 initial
dwinter
parents:
diff changeset
67
373e6610e290 initial
dwinter
parents:
diff changeset
68 else:
373e6610e290 initial
dwinter
parents:
diff changeset
69 pt=zptFile(self, 'zpt/ChangeZopePubmanConnector.zpt')
373e6610e290 initial
dwinter
parents:
diff changeset
70 return pt()
373e6610e290 initial
dwinter
parents:
diff changeset
71
373e6610e290 initial
dwinter
parents:
diff changeset
72
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
73 def getPublications(self,personID,limit=None,publicationType=None):
0
373e6610e290 initial
dwinter
parents:
diff changeset
74 """get all publications der personID"""
16
3e154b154b6f timeouts
dwinter
parents: 15
diff changeset
75 h = httplib2.Http(cacheFolder,timeout=TIMEOUT)
1
c6478f155400 id eingebaut
dwinter
parents: 0
diff changeset
76
c6478f155400 id eingebaut
dwinter
parents: 0
diff changeset
77
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
78
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
79 if publicationType is None:
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
80 # cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22&"
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
81 cn = self.connectorString+"cqlQuery=escidoc.publication.creator.person.identifier=%22"+personID+"%22&"
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
82 else:
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
83 #cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22"
13
43849c9cc08b Incomplete - # 74: More Link auf den pers?nlichne Homepages
dwinter
parents: 12
diff changeset
84 cn = self.connectorString+"cqlQuery=%28escidoc.publication.creator.person.identifier=%22"+personID+"%22%29"
43849c9cc08b Incomplete - # 74: More Link auf den pers?nlichne Homepages
dwinter
parents: 12
diff changeset
85 cn +="%20and%28%20escidoc.publication.type=%22"+publicationType+"%22%29&"
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
86
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
87 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
88 if limit:
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
89 cn+="&maximumRecords=%s"%limit
1
c6478f155400 id eingebaut
dwinter
parents: 0
diff changeset
90
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
91 logging.debug(cn)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
92 resp, content = h.request(cn)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
93
3
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
94
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
95
0
373e6610e290 initial
dwinter
parents:
diff changeset
96 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
373e6610e290 initial
dwinter
parents:
diff changeset
97
373e6610e290 initial
dwinter
parents:
diff changeset
98 root = ET.fromstring(content)
373e6610e290 initial
dwinter
parents:
diff changeset
99
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
100 #<escidocItem:item objid="escidoc:630782"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
101
0
373e6610e290 initial
dwinter
parents:
diff changeset
102 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
373e6610e290 initial
dwinter
parents:
diff changeset
103
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
104 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
105
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
106
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
107
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
108 citations=root.findall(objxpath)
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
109 logging.debug(len(citations))
0
373e6610e290 initial
dwinter
parents:
diff changeset
110 ret=[]
373e6610e290 initial
dwinter
parents:
diff changeset
111 for citation in citations:
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
112 objId = citation.get('objid')
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
113
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
114 text = citation.find(citationxpath)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
115
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
116
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
117
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
118
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
119
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
120 idTermPath =""".//escidocMetadataRecords:md-records/escidocMetadataRecords:md-record/escidocMetadataProfile:publication/dc:identifier"""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
121 #idTermPath =".//{http://purl.org/dc/elements/1.1/}identifier"
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
122
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
123 idterms = citation.findall(idTermPath,ns)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
124
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
125 linksIdentifier=[]
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
126 linksLocator=[]
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
127
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
128
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
129 bookID = None
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
130
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
131
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
132 for idterm in idterms:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
133 if idterm.get("{http://www.w3.org/2001/XMLSchema-instance}type",'') in ['eterms:OTHER','eidt:OTHER']: ##suche nach bookID
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
134 logging.debug("zopePubmanConnector: %s"%idterm.text)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
135 checkID =idterm.text.lstrip().rstrip()
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
136 if checkID.startswith("MPIWG-Book:"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
137 bookID = checkID
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
138 break
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
139 elif idterm.get("{http://www.w3.org/2001/XMLSchema-instance}type",'') in ['eterms:URI','eidt:URI']:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
140 linksIdentifier.append(idterm.text.lstrip().rstrip())
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
141
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
142
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
143
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
144
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
145 componentsPath =""".//escidocComponents:components[1]"""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
146
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
147 components=citation.findall(componentsPath,ns);
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
148
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
149 for component in components:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
150 cnt = component.find(".//escidocComponents:content",ns)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
151 if cnt is not None:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
152 link=""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
153 title=""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
154 type=""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
155 for name,value in cnt.items():
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
156 if name.endswith("href"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
157 link=value
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
158 elif name.endswith("title"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
159 title=value
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
160 elif name.endswith("storage"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
161 type=value
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
162
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
163 linksLocator.append((title,link,type))
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
164
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
165
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
166
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
167
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
168 ret.append((objId,text.text,bookID,linksIdentifier,linksLocator))
0
373e6610e290 initial
dwinter
parents:
diff changeset
169
373e6610e290 initial
dwinter
parents:
diff changeset
170
373e6610e290 initial
dwinter
parents:
diff changeset
171
373e6610e290 initial
dwinter
parents:
diff changeset
172 return ret
373e6610e290 initial
dwinter
parents:
diff changeset
173
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
174
5
245294b18a1d search modified
dwinter
parents: 4
diff changeset
175 def search(self,values={},exact=False,limit=None,contexts=None):
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
176 """search pubman
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
177 @values map mit field->value
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
178 @return map mit escidocId -> XML-formatted snippeds
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
179 """
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
180
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
181 fieldToEscidoc={"title":"escidoc.any-title",
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
182 "author":"escidoc.publication.any.publication-creator-names",
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
183 "any":"escidoc.metadata"}
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
184
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
185
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
186 cn = self.connectorString+"cqlQuery=%s&"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
187 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
188
5
245294b18a1d search modified
dwinter
parents: 4
diff changeset
189 if limit:
245294b18a1d search modified
dwinter
parents: 4
diff changeset
190 cn+="&maximumRecords=%s"%limit
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
191
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
192 querys = []
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
193 for field in values.keys():
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
194
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
195 searchField = fieldToEscidoc.get(field,None)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
196 if searchField is None:
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
197 logging.debug("search, don't know field: %s"%field)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
198 continue
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
199
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
200 value = values[field]
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
201 try:
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
202 value=unicodedata.normalize('NFKD', value).encode('ASCII', 'ignore')
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
203 except:
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
204 value=unicodedata.normalize('NFKD', value.decode('utf-8')).encode('ASCII', 'ignore')
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
205 if value == '':
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
206 continue
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
207 logging.debug("%s=%s"%(field,value))
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
208 if not exact:
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
209 value=value+"*"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
210
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
211 querys.append("%s=%%22%s%%22"%(searchField,value))
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
212
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
213 query="%20AND%20".join(querys)
5
245294b18a1d search modified
dwinter
parents: 4
diff changeset
214
245294b18a1d search modified
dwinter
parents: 4
diff changeset
215 if contexts: # einscbraenken auf contexte
245294b18a1d search modified
dwinter
parents: 4
diff changeset
216
245294b18a1d search modified
dwinter
parents: 4
diff changeset
217 if isinstance(contexts, str):
245294b18a1d search modified
dwinter
parents: 4
diff changeset
218 contexts=[contexts]
245294b18a1d search modified
dwinter
parents: 4
diff changeset
219
245294b18a1d search modified
dwinter
parents: 4
diff changeset
220 ctxquerys=[]
245294b18a1d search modified
dwinter
parents: 4
diff changeset
221 for context in contexts:
245294b18a1d search modified
dwinter
parents: 4
diff changeset
222 ctxquerys.append("escidoc.context.objid=%%22%s%%22"%(context))
245294b18a1d search modified
dwinter
parents: 4
diff changeset
223
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
224 ctxquery="%20OR%20".join(ctxquerys)
5
245294b18a1d search modified
dwinter
parents: 4
diff changeset
225
245294b18a1d search modified
dwinter
parents: 4
diff changeset
226 if query!="":
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
227 query=query+"AND%%20(%s)"%ctxquery
5
245294b18a1d search modified
dwinter
parents: 4
diff changeset
228 else:
245294b18a1d search modified
dwinter
parents: 4
diff changeset
229 query="(%s)"%ctxquery
245294b18a1d search modified
dwinter
parents: 4
diff changeset
230
12
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
231 try:
16
3e154b154b6f timeouts
dwinter
parents: 15
diff changeset
232 h = httplib2.Http(cacheFolder,timeout=TIMEOUT)
12
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
233 logging.debug("search: "+cn%query)
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
234 resp, content = h.request(cn%query)
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
235 except:
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
236 logging.error("Unable to get data from PubMan!")
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
237 return {}
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
238
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
239 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
240
3
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
241 try:
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
242 root = ET.fromstring(content)
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
243 except:
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
244 logging.error("Couldn't parse content of:%s"%(cn%query))
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
245 return {}
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
246 #<escidocItem:item objid="escidoc:630782"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
247
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
248 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
249
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
250 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
251 citations=root.findall(objxpath)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
252
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
253 ret={}
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
254 for citation in citations:
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
255 objId = citation.get('objid')
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
256 text = citation.find(citationxpath)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
257 ret[objId]=text.text
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
258
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
259 return ret
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
260
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
261
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
262 def getEntriesFromPubman(self,escidocids):
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
263
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
264 doctypes={}
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
265 for escidocid in escidocids:
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
266
15
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
267 txt, type, bookID,linksIdentifier,linksLocator = self.getEntryFromPubman(escidocid.escidocid, True)
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
268
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
269 if not doctypes.has_key(type):
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
270 doctypes[type]=[]
15
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
271
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
272 entry={}
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
273 entry['citation']= txt
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
274 entry['escidocId']= escidocid.escidocid
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
275 entry['bookId']=bookID
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
276 entry['linksIdentifier']=linksIdentifier
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
277 entry['linksLocator']=linksIdentifier
ca3084877394 publicationslist
dwinter
parents: 14
diff changeset
278 doctypes[type].append(entry)
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
279
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
280
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
281 return doctypes
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
282
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
283
18
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
284 def getEntryFromPubman(self,escidocid,extendedData=None,withContext=False):
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
285 """get one entry"""
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
286
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
287
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
288
3
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
289 escidocid=escidocid.lstrip().strip()
17
48c4a6f3b135 minor bug, handliung withdrawn entrie
dwinter
parents: 16
diff changeset
290 h = httplib2.Http(cacheFolder,timeout=TIMEOUT)
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
291 cn = self.connectorString+"cqlQuery=escidoc.objid=%s&"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
292 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
293
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
294 resp, content = h.request(cn%escidocid)
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
295 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
3
602b6e46b176 error handling bei falscher suche
dwinter
parents: 2
diff changeset
296 logging.debug(cn%escidocid)
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
297
18
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
298 try:
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
299 root = ET.fromstring(content)
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
300 except:
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
301 logging.error("zopePubmanConnector: cannot parse")
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
302 logging.error(content)
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
303 return "",''
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
304
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
305 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
306
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
307 itempath = ".//escidocItem:item"
17
48c4a6f3b135 minor bug, handliung withdrawn entrie
dwinter
parents: 16
diff changeset
308
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
309
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
310 item = root.find(itempath,ns) #get item
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
311
17
48c4a6f3b135 minor bug, handliung withdrawn entrie
dwinter
parents: 16
diff changeset
312 if item is None:
48c4a6f3b135 minor bug, handliung withdrawn entrie
dwinter
parents: 16
diff changeset
313 logging.error("pubman connector: cannot find %s"%escidocid)
48c4a6f3b135 minor bug, handliung withdrawn entrie
dwinter
parents: 16
diff changeset
314 return escidocid,"","","",""
48c4a6f3b135 minor bug, handliung withdrawn entrie
dwinter
parents: 16
diff changeset
315
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
316 citation=item.find(citationxpath,ns)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
317
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
318
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
319 if citation is not None and extendedData is not None:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
320
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
321 linksIdentifier=[]
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
322 linksLocator=[]
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
323
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
324
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
325
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
326 #get identifier
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
327 idTermPath =""".//escidocMetadataRecords:md-records/escidocMetadataRecords:md-record/escidocMetadataProfile:publication/dc:identifier"""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
328 #idTermPath =".//{http://purl.org/dc/elements/1.1/}identifier"
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
329
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
330 idterms = item.findall(idTermPath,ns)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
331
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
332 bookID = None
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
333 logging.debug("zopePubmanConnector: %s"%idterms)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
334 for idterm in idterms:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
335
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
336 if idterm.get("{http://www.w3.org/2001/XMLSchema-instance}type",'') in ['eterms:OTHER','eidt:OTHER']: ##suche nach bookID
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
337 logging.debug("zopePubmanConnector: %s"%idterm.text)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
338 checkID =idterm.text.lstrip().rstrip()
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
339 if checkID.startswith("MPIWG-Book:"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
340 bookID = checkID
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
341 break
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
342 elif idterm.get("{http://www.w3.org/2001/XMLSchema-instance}type",'') in ['eterms:URI','eidt:URI']:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
343 linksIdentifier.append(idterm.text.lstrip().rstrip())
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
344
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
345
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
346 #get files and locators
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
347 componentsPath =""".//escidocComponents:components[1]"""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
348
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
349 components=item.findall(componentsPath,ns);
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
350
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
351 for component in components:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
352 cnt = component.find(".//escidocComponents:content",ns)
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
353 if cnt is not None:
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
354 link=""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
355 title=""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
356 type=""
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
357 for name,value in cnt.items():
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
358 if name.endswith("href"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
359 link=value
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
360 elif name.endswith("title"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
361 title=value
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
362 elif name.endswith("storage"):
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
363 type=value
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
364
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
365 linksLocator.append((title,link,type))
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
366
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
367
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
368
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
369
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
370
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
371
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
372
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
373
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
374
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
375 path = ".//escidocMetadataRecords:md-records/escidocMetadataRecords:md-record/escidocMetadataProfile:publication"
14
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
376 publicationTag= item.find(path,ns);
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
377
d92decb037d6 bugs in publ
dwinter
parents: 13
diff changeset
378 return citation.text,publicationTag.get('type'),bookID,linksIdentifier,linksLocator
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
379
18
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
380
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
381 if citation is not None and withContext:
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
382 ctxPath=".//escidocItem:properties/srel:context"
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
383 ctx = item.find(ctxPath,ns)
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
384
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
385 return citation.text,ctx.get('objid')
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
386
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
387 if citation is not None:
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
388
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
389 return citation.text
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
390
18
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
391
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
392
da890cb0fd04 shows also context if wanted in getEntryFromPubman
dwinter
parents: 17
diff changeset
393
11
69a2f0b8a932 sortieren von treffer listen nach typen
dwinter
parents: 10
diff changeset
394 return "",''
2
9dbb9354abbe getPublications erweitert nach Typ
dwinter
parents: 1
diff changeset
395
0
373e6610e290 initial
dwinter
parents:
diff changeset
396 def pubmanConnectorURL(self):
373e6610e290 initial
dwinter
parents:
diff changeset
397 return self.connectorString
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
398
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
399
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
400 def getPublicationsFromContext(self,context,limit=None,publicationType=None,search=None):
7
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
401 """gibt alle publicationen des context, jeweils als tupel ("escidoc:id",METADATEN)
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
402
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
403 METADATEN ist hierbei eine Map mit :
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
404 "citation" --> citation in der APA formatierung
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
405 "volume" --> volume
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
406 "link" --> dowloadlink
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
407 "abstracts" --> map mit deu/eng für den abstrakt
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
408 "authors" --> [(NACHNAME,VORNAME]),..]
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
409 "title"--> title
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
410 "year" --> issued
06befe15f66f dokumentation
dwinter
parents: 6
diff changeset
411 """
16
3e154b154b6f timeouts
dwinter
parents: 15
diff changeset
412 h = httplib2.Http(cacheFolder,timeout=TIMEOUT)
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
413
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
414 if publicationType is None:
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
415 cn = self.connectorString+"cqlQuery=(escidoc.context.objid=%22"+context+"%22"
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
416 #cn = self.connectorString+"cqlQuery=escidoc.objid=%22"+"escidoc:643455"+"%22&"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
417 else:
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
418 cn = self.connectorString+"cqlQuery=(escidoc.context.objid=%22"+context+"%22"
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
419 cn +="%20and%20escidoc.publication.type=%22"+publicationType+"%22"
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
420
10
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
421 if search is not None and search != "":
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
422 try:
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
423 search = unicodedata.normalize('NFKD', search).encode('ASCII', 'ignore')
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
424 except:
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
425 search = unicodedata.normalize('NFKD', search.decode('utf-8')).encode('ASCII', 'ignore')
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
426 cn+="%20and%20escidoc.metadata="+search+""
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
427
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
428
007ba22a5eb1 umlaut suche jetzt normalisiert
dwinter
parents: 9
diff changeset
429 cn +=")&exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
430 if limit:
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
431 cn+="&maximumRecords=%s"%limit
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
432
9
166482535b54 timing output for debugging.
casties
parents: 8
diff changeset
433 startTime = time.time()
12
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
434 try:
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
435 logging.debug("getPublicationsFromContext: getting %s"%cn)
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
436 resp, content = h.request(cn)
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
437 logging.debug("getPublicationsFromContext: got data in %ss"%(time.time()-startTime))
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
438
12
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
439 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
440
12
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
441 root = ET.fromstring(content)
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
442
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
443 except Exception, e:
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
444 logging.error("Unable to read and parse data! %s"%e)
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
445 return []
55294833888f fix error without network connection.
casties
parents: 11
diff changeset
446
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
447 #<escidocItem:item objid="escidoc:630782"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
448
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
449 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
450 abstractpath=".//{http://purl.org/dc/terms/}abstract"
6
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
451 issuedpath=".//{http://purl.org/dc/terms/}issued"
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
452
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
453 creatorpath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/publication}creator/{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}person"
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
454 familyNamepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}family-name"
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
455 givenNamepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}given-name"
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
456
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
457
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
458 titlepath=".//{http://purl.org/dc/elements/1.1/}title"
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
459
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
460 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
461 srcpath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/publication}source"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
462 volumepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}volume"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
463
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
464 #linkspath=""".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content[@storage="internal-managed"]"""
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
465 linkspath=""".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content[@storage="external-url"]"""
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
466 #linkspath=".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
467 citations=root.findall(objxpath)
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
468
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
469 ret=[]
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
470 for citation in citations:
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
471 objId = citation.get('objid')
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
472
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
473 text = citation.find(citationxpath)
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
474
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
475 #Get volume = preprintID
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
476 # <publication:source type="series">
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
477 # <dc:title>Max-Planck-Institut für Wissenschaftsgeschichte : Preprint</dc:title>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
478 # <escidoc:volume>437</escidoc:volume>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
479
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
480 src= citation.find(srcpath)
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
481 vol = src.find(volumepath)
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
482
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
483 #get link to fulltext
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
484 #<escidocComponents:component objid="escidoc:644183">
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
485 #<escidocComponents:properties>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
486 # <prop:creation-date>2013-04-29T09:00:01.100Z</prop:creation-date>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
487 # <prop:valid-status>valid</prop:valid-status>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
488 # <prop:visibility>public</prop:visibility>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
489 # <prop:content-category>pre-print</prop:content-category>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
490 # <prop:file-name>P437.PDF</prop:file-name>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
491 # <prop:mime-type>application/pdf</prop:mime-type>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
492 # <prop:checksum>d0ccdc62d6707d934e60e9839ffe30bf</prop:checksum>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
493 # <prop:checksum-algorithm>MD5</prop:checksum-algorithm>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
494 #</escidocComponents:properties>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
495 #<escidocComponents:content xlink:type="simple" xlink:title="P437.PDF" storage="internal-managed"
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
496 # xlink:href="http://pubman.mpiwg-berlin.mpg.de/pubman/item/escidoc:643686:3/component/escidoc:644183/P437.PDF"/>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
497 #
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
498
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
499 src= citation.find(linkspath)
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
500 if src is not None:
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
501
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
502 link=src.get("{http://www.w3.org/1999/xlink}href")
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
503 #logging.debug(src.attrib)
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
504
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
505 else:
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
506 link =""
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
507
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
508 #<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>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
509 #<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>
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
510
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
511 abstracts = citation.findall(abstractpath)
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
512
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
513 abstractTexts={}
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
514 for abstract in abstracts:
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
515
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
516 lang = abstract.get("{http://www.w3.org/XML/1998/namespace}lang")
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
517 abstractTexts[lang]=abstract.text
6
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
518
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
519 authorsTags = citation.findall(creatorpath)
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
520
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
521 authors=[]
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
522 for author in authorsTags:
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
523
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
524 gn= author.find(givenNamepath).text
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
525 fn= author.find(familyNamepath).text
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
526
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
527 authors.append((fn,gn))
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
528
8
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
529 titleTag = citation.find(titlepath)
6
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
530
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
531 if titleTag is not None:
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
532 title = titleTag.text
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
533 else:
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
534 title=""
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
535
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
536 issuedTag = citation.find(issuedpath)
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
537
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
538 if issuedTag is not None:
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
539 issued = issuedTag.text
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
540 else:
49abb91d6c6a getPreprints gibt nun hash mit metadate zurueck
dwinter
parents: 5
diff changeset
541 issued=""
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
542
8
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
543 item = {"id":objId,
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
544 "citation":text.text,
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
545 "volume":vol.text,
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
546 "link":link,
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
547 "abstracts":abstractTexts,
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
548 "authors":authors,
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
549 "title":title,
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
550 "year":issued}
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
551
ddd7e357e518 changed getPreprints to getPublicationsFromContext. returns simple list.
casties
parents: 7
diff changeset
552 ret.append(item)
9
166482535b54 timing output for debugging.
casties
parents: 8
diff changeset
553
166482535b54 timing output for debugging.
casties
parents: 8
diff changeset
554 logging.debug("getPublicationsFromContext: done in %ss"%(time.time()-startTime))
4
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
555 return ret
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
556
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
557
f845502cf73a preprint methoden hinzugefuegt
dwinter
parents: 3
diff changeset
558
0
373e6610e290 initial
dwinter
parents:
diff changeset
559
373e6610e290 initial
dwinter
parents:
diff changeset
560 def manage_addZopePubmanConnectorForm(self):
373e6610e290 initial
dwinter
parents:
diff changeset
561 """Form for external Links"""
373e6610e290 initial
dwinter
parents:
diff changeset
562 pt=zptFile(self, 'zpt/AddZopePubmanConnector.zpt')
373e6610e290 initial
dwinter
parents:
diff changeset
563 return pt()
373e6610e290 initial
dwinter
parents:
diff changeset
564
373e6610e290 initial
dwinter
parents:
diff changeset
565
373e6610e290 initial
dwinter
parents:
diff changeset
566 def manage_addZopePubmanConnector(self,id,title,pubmanURL,RESPONSE=None):
373e6610e290 initial
dwinter
parents:
diff changeset
567 """Add an external Link"""
373e6610e290 initial
dwinter
parents:
diff changeset
568
373e6610e290 initial
dwinter
parents:
diff changeset
569 newObj=ZopePubmanConnector(id,title,pubmanURL)
373e6610e290 initial
dwinter
parents:
diff changeset
570
373e6610e290 initial
dwinter
parents:
diff changeset
571 self._setObject(id,newObj)
373e6610e290 initial
dwinter
parents:
diff changeset
572
373e6610e290 initial
dwinter
parents:
diff changeset
573 if RESPONSE is not None:
373e6610e290 initial
dwinter
parents:
diff changeset
574 RESPONSE.redirect('manage_main')
17
48c4a6f3b135 minor bug, handliung withdrawn entrie
dwinter
parents: 16
diff changeset
575