cedadev / pyramid-phoenix

Phoenix is a Pyramid web-application to make it easy to interact with WPS services
http://pyramid-phoenix.readthedocs.io/en/latest/
Apache License 2.0
0 stars 0 forks source link

Implement predictable URLs in phoenix #15

Closed agstephens closed 3 years ago

agstephens commented 4 years ago

We want to be able to use the name of the WPS in URLs so that linking to fixed end-points in phoenix is easy. E.g.:

/processes/list?wps=midas%20extract   OR
/processes/list?wps=goldfinch  

/processes/execute?wps=midas%20extract&process=GetWeatherStations  OR
/processes/execute?wps=goldfinch&process=GetWeatherStations

At the moment, the WPS is represented in URLs by an identifier random string.

Here are some ideas about extending phoenix to allow predictable URLs:

diff --git a/phoenix/catalog.py b/phoenix/catalog.py
index 9aed8a6..cf3492b 100644
--- a/phoenix/catalog.py
+++ b/phoenix/catalog.py
@@ -53,6 +53,9 @@ class Catalog(object):
     def get_record_by_id(self, identifier):
         raise NotImplementedError

+    def get_record_by_attribute(self, attr, value):
+        raise NotImplementedError
+
     def delete_record(self, identifier):
         raise NotImplementedError

@@ -89,6 +93,20 @@ class MongodbCatalog(Catalog):
     def get_record_by_id(self, identifier):
         return doc2record(self.collection.find_one({'identifier': identifier}))

+    def get_record_by_attribute(self, attr, value):
+#        for svc in self.collection.find():
+#            doc = doc2record(svc)
+
+#            if doc.get(attr) == value:
+#                return doc
+        record = doc2record(self.collection.find_one({attr: value}))
+        if record:
+            return record
+
+        msg = f"could not find record with attribute/value: {attr}={value}"
+        LOGGER.warning(msg)
+        raise Exception(msg)
+
     def delete_record(self, identifier):
         self.collection.delete_one({'identifier': identifier})

diff --git a/phoenix/processes/views/list.py b/phoenix/processes/views/list.py
index 9663bde..01611e2 100644
--- a/phoenix/processes/views/list.py
+++ b/phoenix/processes/views/list.py
@@ -17,7 +17,13 @@ def get_process_media(process):
 class ProcessList(MyView):
     def __init__(self, request):
         self.service_id = request.params.get('wps')
-        service = request.catalog.get_record_by_id(self.service_id)
+
+        try:
+            service = request.catalog.get_record_by_id(self.service_id)
+        except Exception:
+            service = request.catalog.get_record_by_attribute('name', self.service_id)
+            self.service_id = service.identifier
+
         self.wps = WebProcessingService(
             url=service.url,
             verify=False)
agstephens commented 4 years ago

@antony-wilson and @jhaigh0 : here is the issue relating to MongoDB

agstephens commented 3 years ago

@antony-wilson and @jhaigh0: I'm going to take a look at this.

agstephens commented 3 years ago

Fixed in https://github.com/cedadev/pyramid-phoenix/commit/c26c43c8ec7dca0af5040aac67784459ba81a1d5