diff --git a/CHANGELOG.md b/CHANGELOG.md index 72360d003..7af4a6a73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Build Layman as a part of `make start-demo*` commands. - Fix demo run without Micka, fix #55 - Respect public URL scheme in REST API responses, fix #58 +- Show public WMS and WFS URLs in metadata comparison, fix #54 +- Change WFS endpoint from `/ows` to `/wfs`, because `/ows` capabilities pointed to `/wfs` ## v1.3.2 diff --git a/src/layman/layer/geoserver/util.py b/src/layman/layer/geoserver/util.py index 02893615d..ca744d436 100644 --- a/src/layman/layer/geoserver/util.py +++ b/src/layman/layer/geoserver/util.py @@ -50,12 +50,20 @@ def get_feature_type( r.raise_for_status() return r.json()['featureType'] + +def wms_direct(wms_url, xml=None, version=None): + from layman.layer.geoserver.wms import VERSION + version = version or VERSION + wms = WebMapService(wms_url, xml=xml.encode('utf-8') if xml is not None else xml, version=version) + return wms + + def wms_proxy(wms_url, xml=None, version=None): from layman.layer.geoserver.wms import VERSION version = version or VERSION wms_url_path = urlparse(wms_url).path # current_app.logger.info(f"xml=\n{xml}") - wms = WebMapService(wms_url, xml=xml.encode('utf-8') if xml is not None else xml, version=version) + wms = wms_direct(wms_url, xml=xml, version=version) for operation in wms.operations: # app.logger.info(operation.name) for method in operation.methods: @@ -68,13 +76,21 @@ def wms_proxy(wms_url, xml=None, version=None): method['url'] = method_url.geturl() return wms + +def wfs_direct(wfs_url, xml=None, version=None): + from layman.layer.geoserver.wfs import VERSION + version = version or VERSION + wfs = WebFeatureService(wfs_url, xml=xml.encode('utf-8') if xml is not None else xml, version=version) + return wfs + + def wfs_proxy(wfs_url, xml=None, version=None): from layman.layer.geoserver.wfs import VERSION version = version or VERSION wfs_url_path = urlparse(wfs_url).path # TODO: https://github.com/geopython/OWSLib/issues/673 try: - wfs = WebFeatureService(wfs_url, xml=xml.encode('utf-8') if xml is not None else xml, version=version) + wfs = wfs_direct(wfs_url, xml=xml, version=version) for operation in wfs.operations: # app.logger.info(operation.name) for method in operation.methods: diff --git a/src/layman/layer/geoserver/wfs.py b/src/layman/layer/geoserver/wfs.py index f3fe550b0..8d4d8b37c 100644 --- a/src/layman/layer/geoserver/wfs.py +++ b/src/layman/layer/geoserver/wfs.py @@ -73,10 +73,23 @@ def delete_layer(username, layername): return {} +def get_wfs_url(username): + return urljoin(settings.LAYMAN_GS_URL, username + '/wfs') + + +def get_wfs_direct(username): + ows_url = get_wfs_url(username) + from .util import wfs_direct + key = get_flask_proxy_key(username) + redis_obj = settings.LAYMAN_REDIS.hgetall(key) + string_value = redis_obj['value'] if redis_obj is not None else None + return wfs_direct(ows_url, xml=string_value) + + def get_wfs_proxy(username): key = get_flask_proxy_key(username) - ows_url = urljoin(settings.LAYMAN_GS_URL, username + '/ows') + ows_url = get_wfs_url(username) def create_string_value(): r = requests.get(ows_url, params={ 'SERVICE': 'WFS', @@ -117,7 +130,7 @@ def clear_cache(username): def _get_wfs_proxy_url(username): - return urljoin(get_gs_proxy_base_url(), username + '/ows') + return urljoin(get_gs_proxy_base_url(), username + '/wfs') def get_layer_info(username, layername): @@ -162,7 +175,7 @@ def get_publication_uuid(username, publication_type, publication_name): def get_metadata_comparison(username, layername): - wfs = get_wfs_proxy(username) + wfs = get_wfs_direct(username) if wfs is None: return {} cap_op = wfs.getOperationByName('GetCapabilities') diff --git a/src/layman/layer/geoserver/wms.py b/src/layman/layer/geoserver/wms.py index dfb0cee22..e6db81e2d 100644 --- a/src/layman/layer/geoserver/wms.py +++ b/src/layman/layer/geoserver/wms.py @@ -47,10 +47,23 @@ def delete_layer(username, layername): return {} +def get_wms_url(username): + return urljoin(settings.LAYMAN_GS_URL, username + '/ows') + + +def get_wms_direct(username): + ows_url = get_wms_url(username) + from .util import wms_direct + key = get_flask_proxy_key(username) + redis_obj = settings.LAYMAN_REDIS.hgetall(key) + string_value = redis_obj['value'] if redis_obj is not None else None + return wms_direct(ows_url, xml=string_value) + + def get_wms_proxy(username): key = get_flask_proxy_key(username) - ows_url = urljoin(settings.LAYMAN_GS_URL, username + '/ows') + ows_url = get_wms_url(username) def create_string_value(): r = requests.get(ows_url, params={ 'SERVICE': 'WMS', @@ -132,7 +145,7 @@ def get_publication_uuid(username, publication_type, publication_name): def get_metadata_comparison(username, layername): - wms = get_wms_proxy(username) + wms = get_wms_direct(username) if wms is None: return {} cap_op = wms.getOperationByName('GetCapabilities') diff --git a/src/layman/layer/micka/csw.py b/src/layman/layer/micka/csw.py index dec4754a9..dc76306f3 100644 --- a/src/layman/layer/micka/csw.py +++ b/src/layman/layer/micka/csw.py @@ -154,7 +154,8 @@ def get_template_path_and_values(username, layername, http_method=None): identifier=url_for('rest_layer.get', username=username, layername=layername), identifier_label=layername, extent=wms_layer.boundingBoxWGS84, - ows_url=urljoin(get_gs_proxy_base_url(), username + '/ows'), + wms_url=urljoin(get_gs_proxy_base_url(), username + '/ows'), + wfs_url=urljoin(get_gs_proxy_base_url(), username + '/wfs'), md_organisation_name=None, organisation_name=None, md_language=md_language, @@ -183,7 +184,8 @@ def _get_property_values( identifier='http://www.env.cz/data/corine/1990', identifier_label='MZP-CORINE', extent=None, # w, s, e, n - ows_url="http://www.env.cz/corine/data/download.zip", + wms_url="http://www.env.cz/corine/data/download.zip", + wfs_url="http://www.env.cz/corine/data/download.zip", epsg_codes=None, scale_denominator=None, languages=None, @@ -210,8 +212,8 @@ def _get_property_values( 'graphic_url': url_for('rest_layer_thumbnail.get', username=username, layername=layername), 'extent': extent, - 'wms_url': wms.add_capabilities_params_to_url(ows_url), - 'wfs_url': wfs.add_capabilities_params_to_url(ows_url), + 'wms_url': wms.add_capabilities_params_to_url(wms_url), + 'wfs_url': wfs.add_capabilities_params_to_url(wfs_url), 'layer_endpoint': url_for('rest_layer.get', username=username, layername=layername), 'scale_denominator': scale_denominator, 'language': languages, diff --git a/src/layman/layer/rest_test.py b/src/layman/layer/rest_test.py index f178efef0..2e36f71bf 100644 --- a/src/layman/layer/rest_test.py +++ b/src/layman/layer/rest_test.py @@ -48,12 +48,7 @@ 'wms_url', } -METADATA_PROPERTIES_NOT_EQUAL = { - 'wfs_url', - 'wms_url', -} - -METADATA_PROPERTIES_EQUAL = METADATA_PROPERTIES - METADATA_PROPERTIES_NOT_EQUAL +METADATA_PROPERTIES_EQUAL = METADATA_PROPERTIES min_geojson = """ { @@ -81,8 +76,8 @@ def check_metadata(client, username, layername, props_equal, expected_values): resp_json = rv.get_json() assert METADATA_PROPERTIES == set(resp_json['metadata_properties'].keys()) for k, v in resp_json['metadata_properties'].items(): - assert v['equal_or_null'] == (k in props_equal), f"Metadata property values have unexpected 'equal_or_null' value: {k}: {json.dumps(v, indent=2)}" - assert v['equal'] == (k in props_equal), f"Metadata property values have unexpected 'equal' value: {k}: {json.dumps(v, indent=2)}" + assert v['equal_or_null'] == (k in props_equal), f"Metadata property values have unexpected 'equal_or_null' value: {k}: {json.dumps(v, indent=2)}, sources: {json.dumps(resp_json['metadata_sources'], indent=2)}" + assert v['equal'] == (k in props_equal), f"Metadata property values have unexpected 'equal' value: {k}: {json.dumps(v, indent=2)}, sources: {json.dumps(resp_json['metadata_sources'], indent=2)}" # print(f"'{k}': {json.dumps(list(v['values'].values())[0], indent=2)},") if k in expected_values: vals = list(v['values'].values()) diff --git a/src/layman/layer/rest_test_filled_template.xml b/src/layman/layer/rest_test_filled_template.xml index 0b7a1e7b4..7cfbdecd7 100644 --- a/src/layman/layer/rest_test_filled_template.xml +++ b/src/layman/layer/rest_test_filled_template.xml @@ -269,7 +269,7 @@ - http://localhost:8600/geoserver/testuser1/ows?SERVICE=WFS&REQUEST=GetCapabilities&VERSION=2.0.0 + http://localhost:8600/geoserver/testuser1/wfs?SERVICE=WFS&REQUEST=GetCapabilities&VERSION=2.0.0 OGC:WFS-2.0.0-http-get-capabilities diff --git a/src/layman/map/micka/csw.py b/src/layman/map/micka/csw.py index 9c6ed7b00..f6508c925 100644 --- a/src/layman/map/micka/csw.py +++ b/src/layman/map/micka/csw.py @@ -136,7 +136,7 @@ def map_json_to_operates_on(map_json): unquote_urls(map_json) gs_url = get_gs_proxy_base_url() gs_url = gs_url if gs_url.endswith('/') else f"{gs_url}/" - gs_url_pattern = r'^' + re.escape(gs_url) + r'(' + USERNAME_ONLY_PATTERN + r')' + r'/ows.*$' + gs_url_pattern = r'^' + re.escape(gs_url) + r'(' + USERNAME_ONLY_PATTERN + r')' + r'/(?:ows|wms|wfs).*$' layman_layer_names = [] for map_layer in map_json['layers']: layer_url = map_layer.get('url', None) diff --git a/src/layman/map/rest_test.py b/src/layman/map/rest_test.py index bb95e2524..790be3a98 100644 --- a/src/layman/map/rest_test.py +++ b/src/layman/map/rest_test.py @@ -38,8 +38,6 @@ 'title', } -METADATA_PROPERTIES_NOT_EQUAL = set() - METADATA_PROPERTIES_EQUAL = METADATA_PROPERTIES METADATA_PROPERTIES_POST_EMPTY = {