Skip to content

Commit

Permalink
♻️ Refactor REST API response for: /interface/ows (#601)
Browse files Browse the repository at this point in the history
* Refactoring response of /interface/ows API.

* ⬆️ Client:
    g3w-client : g3w-suite/g3w-client@991bdde

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: Raruto <[email protected]>
Co-authored-by: volterra79 <[email protected]>
  • Loading branch information
4 people authored Nov 17, 2023
1 parent 47de721 commit 6577b9d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion g3w-admin/client/static/client/css/app.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion g3w-admin/client/static/client/js/app.min.js

Large diffs are not rendered by default.

63 changes: 53 additions & 10 deletions g3w-admin/core/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,61 @@ def post(self, request, **kwargs):
# -----------------------------------
self.results.results.update({'title': ows.identification.title, 'abstract': ows.identification.abstract})

# Map formats
# -----------------------------------
self.results.results.update({'map_formats': ows.getOperationByName('GetMap').formatOptions})
# Add methods
methods = {}

# Info formats
# -----------------------------------
try:
self.results.results.update({'info_formats': ows.getOperationByName('GetFeatureInfo').formatOptions})
except Exception as e:
for method in ('GetMap', 'GetFeatureInfo', 'GetCapabilities'):


if method == 'GetMap':

if method not in methods:
methods[method] = {}

# GetMap
# -----------------------------------
methods[method].update({'formats': ows.getOperationByName('GetMap').formatOptions})

# Add methods
try:
methods[method].update(
{"urls": ows.getOperationByName("GetMap").methods}
)
except Exception as e:

# Case where OWS service doesn't support GetMap
logger.debug(f'The service {url} doesn\'t support GetMap, err: {str(e)}')


if method == 'GetFeatureInfo':

# GetFeatureInfo
# -----------------------------------
try:
if method not in methods:
methods[method] = {}
methods[method].update({'formats': ows.getOperationByName('GetFeatureInfo').formatOptions})
methods[method].update({"methods": ows.getOperationByName("GetFeatureInfo").methods})
except Exception as e:

# Case where OWS service doesn't support GetFeatureInfo
logger.debug(f'The service {url} doesn\'t support GetFeatureInfo, err: {str(e)}')

if method == 'GetCapabilities':

# GetCapabilities
# -----------------------------------
try:
if method not in methods:
methods[method] = {}
methods[method].update({'formats': ows.getOperationByName('GetCapabilities').formatOptions})
methods[method].update({"methods": ows.getOperationByName("GetCapabilities").methods})
except Exception as e:

# Case where OWS service doesn't support GetCapabilities
logger.debug(f'The service {url} doesn\'t support GetCapabilities, err: {str(e)}')

# Case where OWS service doesn't support GetFeatureInfo
logger.debug(f'The service {url} doesn\'t support GetFeatureInfo, err: {str(e)}')
self.results.results.update({'methods': methods})

# Layers
# -----------------------------------
Expand Down
6 changes: 4 additions & 2 deletions g3w-admin/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,10 @@ def testCoreInterfaceOwsView(self):

self.assertTrue(jres['result'])
self.assertEqual('Geoscopio_wms catasto'.lower(), jres['title'].lower())
self.assertTrue('image/png' in jres['map_formats'])
self.assertTrue('text/html' in jres['info_formats'])
self.assertTrue('GetMap' in jres['methods'] and 'GetFeatureInfo' in jres['methods'] and 'GetCapabilities' in jres['methods'])
self.assertTrue('image/png' in jres['methods']['GetMap']['formats'])
self.assertEqual(jres["methods"]["GetMap"]["urls"],[{'type': 'Get', 'url': 'https://www502.regione.toscana.it/ows_catasto/com.rt.wms.RTmap/ows?map=owscatasto&'}, {'type': 'Post', 'url': 'https://www502.regione.toscana.it/ows_catasto/com.rt.wms.RTmap/ows?map=owscatasto&'}])
self.assertTrue('text/html' in jres['methods']['GetFeatureInfo']['formats'])
self.assertEqual(len(jres['layers']), 21)

self.assertEqual(jres['layers'][1]['title'].lower(), 'Acque - AdT Catasto Terreni'.lower())
Expand Down

0 comments on commit 6577b9d

Please sign in to comment.