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

Add v1.10.1 to master #290

Merged
merged 4 commits into from
Mar 11, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- [#273](https://github.com/jirik/layman/issues/273) New endpoints [GET Layers](doc/rest.md#get-layers) and [GET Layers](doc/rest.md#get-maps) to query publications in all [workspaces](doc/models.md#workspace).
- [#273](https://github.com/jirik/layman/issues/273) All Layer(s) and Map(s) endpoints with `<workspace_name>` in their URL were renamed to 'Workspace Layer...' and 'Workspace Map' in the documentation.

## v1.10.1
2021-03-10
### Changes
- [#285](https://github.com/jirik/layman/issues/285) Fix upgrade 1.10.0 error (CSW get_template_path_and_values now works even if the layer is not in GeoServer and/or in DB).

## v1.10.0
2021-03-04
Expand Down
90 changes: 53 additions & 37 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
from layman.layer import db
from layman.layer.geoserver import wms
from layman.layer.geoserver import wfs
from layman.layer.geoserver.util import get_gs_proxy_base_url
from layman.layer import LAYER_TYPE
from layman import settings, patch_mode, LaymanError
from layman.util import url_for
from layman.util import url_for, get_publication_info
from requests.exceptions import HTTPError, ConnectionError
from urllib.parse import urljoin
from lxml import etree as ET

PATCH_MODE = patch_mode.NO_DELETE
Expand All @@ -27,8 +25,8 @@ def get_metadata_uuid(uuid):
return f"m-{uuid}" if uuid is not None else None


def get_layer_info(username, layername):
uuid = get_layer_uuid(username, layername)
def get_layer_info(workspace, layername):
uuid = get_layer_uuid(workspace, layername)
try:
csw = common_util.create_csw()
if uuid is None or csw is None:
Expand All @@ -44,31 +42,31 @@ def get_layer_info(username, layername):
'identifier': muuid,
'csw_url': settings.CSW_PROXY_URL,
'record_url': settings.CSW_RECORD_URL.format(identifier=muuid),
'comparison_url': url_for('rest_workspace_layer_metadata_comparison.get', username=username, layername=layername),
'comparison_url': url_for('rest_workspace_layer_metadata_comparison.get', username=workspace, layername=layername),
}
}
else:
return {}


def patch_layer(username, layername, metadata_properties_to_refresh, actor_name=None, create_if_not_exists=True, timeout=5):
def patch_layer(workspace, layername, metadata_properties_to_refresh, actor_name=None, create_if_not_exists=True, timeout=5):
# current_app.logger.info(f"patch_layer metadata_properties_to_refresh={metadata_properties_to_refresh}")
if len(metadata_properties_to_refresh) == 0:
return {}
uuid = get_layer_uuid(username, layername)
uuid = get_layer_uuid(workspace, layername)
csw = common_util.create_csw()
if uuid is None or csw is None:
return {}
muuid = get_metadata_uuid(uuid)
el = common_util.get_record_element_by_id(csw, muuid)
if el is None:
if create_if_not_exists:
return csw_insert(username, layername)
return csw_insert(workspace, layername)
else:
return None
# current_app.logger.info(f"Current element=\n{ET.tostring(el, encoding='unicode', pretty_print=True)}")

_, prop_values = get_template_path_and_values(username, layername, http_method='patch')
_, prop_values = get_template_path_and_values(workspace, layername, http_method='patch')
prop_values = {
k: v for k, v in prop_values.items()
if k in metadata_properties_to_refresh + ['md_date_stamp']
Expand All @@ -90,16 +88,16 @@ def patch_layer(username, layername, metadata_properties_to_refresh, actor_name=
return muuid


def get_publication_uuid(username, publication_type, publication_name):
def get_publication_uuid(workspace, publication_type, publication_name):
return None


def post_layer(username, layername):
def post_layer(workspace, layername):
pass


def delete_layer(username, layername):
uuid = get_layer_uuid(username, layername)
def delete_layer(workspace, layername):
uuid = get_layer_uuid(workspace, layername)
muuid = get_metadata_uuid(uuid)
if muuid is None:
return
Expand All @@ -110,8 +108,8 @@ def delete_layer(username, layername):
raise LaymanError(38)


def csw_insert(username, layername):
template_path, prop_values = get_template_path_and_values(username, layername, http_method='post')
def csw_insert(workspace, layername):
template_path, prop_values = get_template_path_and_values(workspace, layername, http_method='post')
record = common_util.fill_xml_template_as_pretty_str(template_path, prop_values, METADATA_PROPERTIES)
try:
muuid = common_util.csw_insert({
Expand All @@ -123,34 +121,52 @@ def csw_insert(username, layername):
return muuid


def get_template_path_and_values(username, layername, http_method=None):
def get_template_path_and_values(workspace, layername, http_method=None):
assert http_method in ['post', 'patch']
wmsi = wms.get_wms_proxy(username)
wms_layer = wmsi.contents[layername]
uuid_file_path = get_publication_uuid_file(LAYER_TYPE, username, layername)
wmsi = wms.get_wms_proxy(workspace)
wms_layer = wmsi.contents.get(layername) if wmsi else None
publ_info = get_publication_info(workspace, LAYER_TYPE, layername, context={
'keys': ['title'],
})
title = publ_info['title']

if wms_layer:
abstract = wms_layer.abstract
extent = wms_layer.boundingBoxWGS84
else:
abstract = None
extent = [-180, -90, 180, 90]

uuid_file_path = get_publication_uuid_file(LAYER_TYPE, workspace, layername)
publ_datetime = datetime.fromtimestamp(os.path.getmtime(uuid_file_path))
revision_date = datetime.now()
md_language = next(iter(common_language.get_languages_iso639_2(' '.join([
wms_layer.title or '',
wms_layer.abstract or ''
title or '',
abstract or ''
]))), None)
languages = db.get_text_languages(username, layername)
scale_denominator = db.guess_scale_denominator(username, layername)
try:
languages = db.get_text_languages(workspace, layername)
except LaymanError:
languages = []
try:
scale_denominator = db.guess_scale_denominator(workspace, layername)
except LaymanError:
scale_denominator = None

prop_values = _get_property_values(
username=username,
workspace=workspace,
layername=layername,
uuid=get_layer_uuid(username, layername),
title=wms_layer.title,
abstract=wms_layer.abstract or None,
uuid=get_layer_uuid(workspace, layername),
title=title,
abstract=abstract or None,
publication_date=publ_datetime.strftime('%Y-%m-%d'),
revision_date=revision_date.strftime('%Y-%m-%d'),
md_date_stamp=date.today().strftime('%Y-%m-%d'),
identifier=url_for('rest_workspace_layer.get', username=username, layername=layername),
identifier=url_for('rest_workspace_layer.get', username=workspace, layername=layername),
identifier_label=layername,
extent=wms_layer.boundingBoxWGS84,
wms_url=wms.get_wms_url(username, external_url=True),
wfs_url=wfs.get_wfs_url(username, external_url=True),
extent=extent,
wms_url=wms.get_wms_url(workspace, external_url=True),
wfs_url=wfs.get_wfs_url(workspace, external_url=True),
md_organisation_name=None,
organisation_name=None,
md_language=md_language,
Expand All @@ -165,7 +181,7 @@ def get_template_path_and_values(username, layername, http_method=None):


def _get_property_values(
username='browser',
workspace='browser',
layername='layer',
uuid='ca238200-8200-1a23-9399-42c9fca53542',
title='CORINE - Krajinný pokryv CLC 90',
Expand Down Expand Up @@ -203,12 +219,12 @@ def _get_property_values(
'label': identifier_label,
},
'abstract': abstract,
'graphic_url': url_for('rest_workspace_layer_thumbnail.get', username=username, layername=layername),
'graphic_url': url_for('rest_workspace_layer_thumbnail.get', username=workspace, layername=layername),
'extent': extent,

'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_workspace_layer.get', username=username, layername=layername),
'layer_endpoint': url_for('rest_workspace_layer.get', username=workspace, layername=layername),
'scale_denominator': scale_denominator,
'language': languages,
'md_organisation_name': md_organisation_name,
Expand Down Expand Up @@ -356,8 +372,8 @@ def _get_property_values(
}


def get_metadata_comparison(username, layername):
uuid = get_layer_uuid(username, layername)
def get_metadata_comparison(workspace, layername):
uuid = get_layer_uuid(workspace, layername)
csw = common_util.create_csw()
if uuid is None or csw is None:
return {}
Expand Down
1 change: 1 addition & 0 deletions src/layman/layer/rest_workspace_layers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def assert_wms_layer(workspace, layer, style, expected_thumbnail_path=None):
diffs = test_util.compare_images(thumbnail_path, expected_thumbnail_path)
assert diffs < 100

@pytest.mark.flaky(reruns=2, reruns_delay=2)
@pytest.mark.timeout(60)
@pytest.mark.usefixtures('ensure_layman')
@pytest.mark.parametrize('operations', [
Expand Down