Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor REST API response for: /interface/ows #601

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading