Skip to content

Commit

Permalink
Show public WMS and WFS URLs in metadata comparison
Browse files Browse the repository at this point in the history
Fix #45

Change WFS endpoint from /ows to /wfs, because /ows capabilities pointed to /wfs
  • Loading branch information
jirik committed Apr 14, 2020
1 parent 8ab290c commit b984604
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions src/layman/layer/geoserver/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
19 changes: 16 additions & 3 deletions src/layman/layer/geoserver/wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down
17 changes: 15 additions & 2 deletions src/layman/layer/geoserver/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')
Expand Down
10 changes: 6 additions & 4 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions src/layman/layer/rest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
{
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/rest_test_filled_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://localhost:8600/geoserver/testuser1/ows?SERVICE=WFS&amp;REQUEST=GetCapabilities&amp;VERSION=2.0.0</gmd:URL>
<gmd:URL>http://localhost:8600/geoserver/testuser1/wfs?SERVICE=WFS&amp;REQUEST=GetCapabilities&amp;VERSION=2.0.0</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gmx:Anchor xlink:href="https://services.cuzk.cz/registry/codelist/OnlineResourceProtocolValue/OGC:WFS-2.0.0-http-get-capabilities">OGC:WFS-2.0.0-http-get-capabilities</gmx:Anchor>
Expand Down
2 changes: 1 addition & 1 deletion src/layman/map/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/layman/map/rest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
'title',
}

METADATA_PROPERTIES_NOT_EQUAL = set()

METADATA_PROPERTIES_EQUAL = METADATA_PROPERTIES

METADATA_PROPERTIES_POST_EMPTY = {
Expand Down

0 comments on commit b984604

Please sign in to comment.