# HG changeset patch # User dwinter # Date 1353508748 -3600 # Node ID cce127a28fc95b1e3a9720c86b83e63167aab30b # Parent 1eb5e3f6444b51b9b31c8c7e8ffe466bf5689b09 added getpurls diff -r 1eb5e3f6444b -r cce127a28fc9 managePurls/manageIndexMetaPURLs.py --- a/managePurls/manageIndexMetaPURLs.py Mon Nov 19 12:14:25 2012 +0100 +++ b/managePurls/manageIndexMetaPURLs.py Wed Nov 21 15:39:08 2012 +0100 @@ -38,7 +38,8 @@ def __init__(self): - self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="p*lWa55eR", host="tuxserve03") + #self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="p*lWa55eR", host="tuxserve03") + self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="3333") @@ -191,11 +192,15 @@ return update - def register(self,path,isIndexMeta,imagePath="",server_url="",user="",update=False): + def register(self,path=None,isIndexMeta=False,imagePath="",server_url="",user="",update=False): #teste ob es zu dem Pfad schon eine Purl gibt - purl = self.getPurl(path) + + if path: # wenn ein pfad definiert ist teste ob es schon eine purl dazu gibt. + purl = self.getPurl(path) + else: + purl =None if purl!=None: if update: diff -r 1eb5e3f6444b -r cce127a28fc9 restService/config.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/restService/config.py Wed Nov 21 15:39:08 2012 +0100 @@ -0,0 +1,3 @@ +#TEMPLATE_PATH="/usr/local/metadataServices/purlService/restService/templates/" +TEMPLATE_PATH="/Users/dwinter/Documents/Projekte/MetaDataManagement/purlService/restService/templates/" +TEXTER_URL="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter?fn=%s" \ No newline at end of file diff -r 1eb5e3f6444b -r cce127a28fc9 restService/getPurls.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/restService/getPurls.py Wed Nov 21 15:39:08 2012 +0100 @@ -0,0 +1,63 @@ +''' +Register purls at the server +Created on 22.11.2012 + +@author: dwinter +''' + +import web +import base64 +import re +import config +from managePurls.manageIndexMetaPURLs import IndexMetaPURLManager + +class getPurls: + + def __init__(self): + self.render = web.template.render(config.TEMPLATE_PATH) + self.purlManager = IndexMetaPURLManager() + + def GET(self): + + auth = web.ctx.env.get('HTTP_AUTHORIZATION') + + authreq = False + if auth is None: + authreq = True + else: + print auth + auth = re.sub('^Basic ','',auth) + username,password = base64.decodestring(auth).split(':') + + + if authreq: + web.header('WWW-Authenticate','Basic realm="Auth example"') + web.ctx.status = '401 Unauthorized' + return + + return self.render.registerPurls(username) + + def POST(self): + inp = web.input() + + username=inp.get("userName",None) + amount=inp.get("amount",None) + + if (username==None) or (amount==None): + raise web.badrequest("Username and amount have to be send!") + + try: + amount=int(amount) + except: + raise web.badrequest("Amount is not an integer!") + + if amount>10: + raise web.badrequest("Amount is to large (maximum 10)") + + purls=[] + for i in range(amount): + purls.append(self.purlManager.register(user=username)) + + + return self.render.registeredPurlsResponse(purls) + diff -r 1eb5e3f6444b -r cce127a28fc9 restService/restService.py --- a/restService/restService.py Mon Nov 19 12:14:25 2012 +0100 +++ b/restService/restService.py Wed Nov 21 15:39:08 2012 +0100 @@ -3,12 +3,17 @@ @author: dwinter ''' + + import web import managePurls.manageIndexMetaPURLs as manageIndexMetaPURLs from redirector import redirector import logging from searcher import searcher from searchService.searchLines import searchLines +from getPurls import getPurls +import config + urls = ( '/purl/(.+)','purl', @@ -17,20 +22,22 @@ '/indexMeta/(.+)','indexMeta', '/','serviceDescription', '/searchLines','searchLines', - '/searchLines/annotator/search','searchLines' + '/searchLines/annotator/search','searchLines', + '/getPurls','getPurls' ) + app = web.application(urls, globals()) -TEXTER_URL="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter?fn=%s" + class serviceDescription: def __init__(self): - self.render = web.template.render('/usr/local/metadataServices/purlService/restService/templates/') + self.render = web.template.render(config.TEMPLATE_PATH) def GET(self): return self.render.serviceDescription() @@ -55,7 +62,7 @@ return web.notfound("PURL currently not VALID try later!") - raise web.redirect(TEXTER_URL%path) + raise web.redirect(config.TEXTER_URL%path) diff -r 1eb5e3f6444b -r cce127a28fc9 restService/templates/registerPurls.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/restService/templates/registerPurls.html Wed Nov 21 15:39:08 2012 +0100 @@ -0,0 +1,8 @@ +$def with (username) +

Create Purls

+ +
+
Username (if existing your mpiwg username):
+
How many PURLS do you need (maximum 10):
+
+
\ No newline at end of file diff -r 1eb5e3f6444b -r cce127a28fc9 restService/templates/registeredPurlsResponse.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/restService/templates/registeredPurlsResponse.html Wed Nov 21 15:39:08 2012 +0100 @@ -0,0 +1,6 @@ +$def with (purls) + +

New Purls:

+ +$for i in range(len(purls)): +
$purls[i][1]
\ No newline at end of file diff -r 1eb5e3f6444b -r cce127a28fc9 restService/templates/serviceDescription.html --- a/restService/templates/serviceDescription.html Mon Nov 19 12:14:25 2012 +0100 +++ b/restService/templates/serviceDescription.html Wed Nov 21 15:39:08 2012 +0100 @@ -35,4 +35,13 @@

/indexMeta/PURL

Redirects to the index.meta file of the source, if existing. -

\ No newline at end of file +

+ + +

/getPurls

+get new purls + +GET: returns an simple web page to enter username and amount of purls needed + +POST: expects the parameter "username" and "amount"", return list of purls +