changeset 38:6d0d7f1c11f2

/dris added to the api
author dwinter
date Tue, 04 Mar 2014 14:16:55 +0100
parents 6a0873a913c5
children a33fa2377075
files managePurls/manageIndexMetaPURLs.py restService/getPurls.py restService/restService.py restService/templates/serviceDescription.html
diffstat 4 files changed, 54 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/managePurls/manageIndexMetaPURLs.py	Mon Mar 03 18:07:08 2014 +0100
+++ b/managePurls/manageIndexMetaPURLs.py	Tue Mar 04 14:16:55 2014 +0100
@@ -273,9 +273,19 @@
             ret.append(purl.purl)
             
         return ret
+    
+    def getAllPurls(self,limit=None,offset=None,isDri=True):
         
+        results = self.purlDB.where('purls',what="purl,path",limit=limit,offset=offset,isdri=isDri)
+    
+        ret = []
+        for result in results:
+            ret.append({'path':result.path,'dri':result.purl})
+        return ret
+            
 if __name__ == '__main__':
     
     im = IndexMetaPURLManager()
-    print im.register("/tmp3/index.meta", True, "", "dwinter")
+    #print im.register("/tmp3/index.meta", True, "", "dwinter")
+    print im.getAllPurls()
     pass
--- a/restService/getPurls.py	Mon Mar 03 18:07:08 2014 +0100
+++ b/restService/getPurls.py	Tue Mar 04 14:16:55 2014 +0100
@@ -116,7 +116,34 @@
         lst = self.purlManager.getLastEntries(3)
         
         return json.dumps(lst)
-         
+    
+class dris:
+    def __init__(self):
+        self.purlManager =IndexMetaPURLManager()
+        
+    def GET(self):
+        
+        params = web.input();
+      
+        limit = params.get("limit",None)
+        offset = params.get("offset",None)
+        format =params.get("format","json")
+      
+        lst = self.purlManager.getAllPurls(limit=limit,offset=offset,isDri=True)
+        
+        if format=="json":
+            web.header('Content-Type', 'application/json')
+            return json.dumps(lst)
+        elif format =="csv":
+            web.header('Content-Type', 'text/plain')
+            str =""
+            for entry in lst:
+                str+="%s,%s\n"%(entry['path'],entry['dri'])
+                
+            return str
+        else:
+             raise web.badrequest("Allowed parameters for format are only  plain and json. The default is json. Parameter was %s.."%format)
+            
          
          
         
--- a/restService/restService.py	Mon Mar 03 18:07:08 2014 +0100
+++ b/restService/restService.py	Tue Mar 04 14:16:55 2014 +0100
@@ -18,6 +18,7 @@
 from searchService.searchSolr import searchSolr
 from images import image
 from images import imageURL
+from getPurls import dris
 
 import config
 
@@ -36,7 +37,8 @@
     '/imageURL/(.+)','imageURL',
     '/image/(.+)','image',
     '/random','randomSearch',
-    '/last','lastEntries'
+    '/last','lastEntries',
+    '/dris','dris'
 )
 
 
--- a/restService/templates/serviceDescription.html	Mon Mar 03 18:07:08 2014 +0100
+++ b/restService/templates/serviceDescription.html	Tue Mar 04 14:16:55 2014 +0100
@@ -64,5 +64,17 @@
 
 an additional parameter <b>format=short</b> suppresses the additional metadata in the output.
 
+<h4>/dris</h4>
+<p>get a list of all DRIs.</p>
+
+<p>
+Optional parameters are:
+<ol>
+<li>offset: start list at offset</li>
+<li>limit: limit number of entries return</li>
+<li>format, is ether json or csv</li>
+</ol>
+</p>
 
 
+