From 1595a9f01357d92aae24845ef925fe27f9385591 Mon Sep 17 00:00:00 2001 From: index-git Date: Wed, 27 Sep 2023 14:37:07 +0200 Subject: [PATCH] Accept map json in version 3.x.x --- CHANGELOG.md | 1 + src/layman/map/util.py | 8 ++++---- .../{map_schema_3_0_0.json => map_schema_4_0_0.json} | 4 ++-- .../publications/wrong_input/wrong_input_test.py | 8 ++++---- timgen/src/map.js | 8 +++++--- 5 files changed, 16 insertions(+), 13 deletions(-) rename tests/dynamic_data/publications/wrong_input/{map_schema_3_0_0.json => map_schema_4_0_0.json} (93%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d67099f..421109950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - requests to [WMS](doc/endpoints.md#web-map-service) and [WFS](doc/endpoints.md#web-feature-service) endpoints - [#868](https://github.com/LayerManager/layman/issues/868) Responses to [GET Workspace Layer Metadata Comparison](doc/rest.md#get-workspace-layer-metadata-comparison) and [GET Workspace Map Metadata Comparison](doc/rest.md#get-workspace-map-metadata-comparison) do not respect [HTTP X-Forwarded headers](doc/client-proxy.md#x-forwarded-http-headers) of the request intentionally, in order to keep URLs in canonical form. - [#868](https://github.com/LayerManager/layman/issues/868) Relations between map and [internal layers](doc/models.md#internal-map-layer) are updated in `map_layer` table when calling [POST Workspace Maps](doc/rest.md#post-workspace-maps), [PATCH Workspace Map](doc/rest.md#patch-workspace-map), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), and [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps). +- [#901](https://github.com/LayerManager/layman/issues/868) Endpoints [POST](doc/rest.md#post-workspace-maps) and [PATCH](doc/rest.md#patch-workspace-map) accepts map compositions in version `3.x.x`. - [#927](https://github.com/LayerManager/layman/issues/927) Send styles to GeoServer with [`raw`](https://docs.geoserver.org/2.21.x/en/user/rest/api/styles.html#raw) param set to `True`. - [#880](https://github.com/LayerManager/layman/issues/880) Use Docker Compose v2 (`docker compose`) in Makefile without `compatibility` flag and remove `Makefile_docker-compose_v1` file. Docker containers are named according to Docker Compose v2 and may have different name after upgrade. - [#765](https://github.com/LayerManager/layman/issues/765) Stop saving OAuth2 claims in filesystem, use prime DB schema only. diff --git a/src/layman/map/util.py b/src/layman/map/util.py index b88523805..1b3fe5abf 100644 --- a/src/layman/map/util.py +++ b/src/layman/map/util.py @@ -27,7 +27,7 @@ MAPNAME_MAX_LENGTH = PUBLICATION_MAX_LENGTH SCHEMA_URL_PATTERN = r'^https://raw.githubusercontent.com/hslayers/map-compositions/(([0-9]{1,}.[0-9]{1,}.[0-9]{1,})|([a-zA-Z]*?))/schema.json$' _SCHEMA_CACHE_PATH = 'tmp' -_ACCEPTED_SCHEMA_MAJOR_VERSION = '2' +_ACCEPTED_SCHEMA_MAJOR_VERSION_LIST = ['2', '3'] FLASK_PROVIDERS_KEY = f'{__name__}:PROVIDERS' FLASK_SOURCES_KEY = f'{__name__}:SOURCES' @@ -172,11 +172,11 @@ def get_composition_schema(url): 'regular_expression': SCHEMA_URL_PATTERN, }) version = url.split('/')[-2] - if version.split('.')[0] != _ACCEPTED_SCHEMA_MAJOR_VERSION: + if version.split('.')[0] not in _ACCEPTED_SCHEMA_MAJOR_VERSION_LIST: raise LaymanError(2, { 'parameter': 'file', 'reason': 'Invalid schema version', - 'expected': _ACCEPTED_SCHEMA_MAJOR_VERSION + '.x.x', + 'expected': ' or '.join([v + '.x.x' for v in _ACCEPTED_SCHEMA_MAJOR_VERSION_LIST]), }) schema_file_name = os.path.join(*url.split('/')[-1:]) @@ -214,7 +214,7 @@ def check_file(file): raise LaymanError(2, { 'parameter': 'file', 'reason': 'Missing key `describedBy`', - 'expected': 'JSON file according schema `https://github.com/hslayers/map-compositions`, version ' + _ACCEPTED_SCHEMA_MAJOR_VERSION, + 'expected': 'JSON file according schema `https://github.com/hslayers/map-compositions`, version ' + ' or '.join(_ACCEPTED_SCHEMA_MAJOR_VERSION_LIST), }) from exc schema_json = get_composition_schema(schema_url) diff --git a/tests/dynamic_data/publications/wrong_input/map_schema_3_0_0.json b/tests/dynamic_data/publications/wrong_input/map_schema_4_0_0.json similarity index 93% rename from tests/dynamic_data/publications/wrong_input/map_schema_3_0_0.json rename to tests/dynamic_data/publications/wrong_input/map_schema_4_0_0.json index bddf16772..4b4aa73e9 100644 --- a/tests/dynamic_data/publications/wrong_input/map_schema_3_0_0.json +++ b/tests/dynamic_data/publications/wrong_input/map_schema_4_0_0.json @@ -1,6 +1,6 @@ { - "describedBy": "https://raw.githubusercontent.com/hslayers/map-compositions/3.0.0/schema.json", - "schema_version": "3.0.0", + "describedBy": "https://raw.githubusercontent.com/hslayers/map-compositions/4.0.0/schema.json", + "schema_version": "4.0.0", "abstract": "Na tematick\u00e9 map\u011b p\u0159i p\u0159ibl\u00ed\u017een\u00ed jsou postupn\u011b zobrazovan\u00e9 administrativn\u00ed celky Libereck\u00e9ho kraje : okresy, OP\u00da, ORP a obce.", "title": "Administrativn\u00ed \u010dlen\u011bn\u00ed Libereck\u00e9ho kraje", "extent": [ diff --git a/tests/dynamic_data/publications/wrong_input/wrong_input_test.py b/tests/dynamic_data/publications/wrong_input/wrong_input_test.py index ea195a148..e75e4e193 100644 --- a/tests/dynamic_data/publications/wrong_input/wrong_input_test.py +++ b/tests/dynamic_data/publications/wrong_input/wrong_input_test.py @@ -476,7 +476,7 @@ class Key(Enum): 'http_code': 400, 'sync': True, 'code': 2, - 'data': {'expected': 'JSON file according schema `https://github.com/hslayers/map-compositions`, version 2', + 'data': {'expected': 'JSON file according schema `https://github.com/hslayers/map-compositions`, version 2 or 3', 'parameter': 'file', 'reason': 'Missing key `describedBy`'}, }, @@ -484,11 +484,11 @@ class Key(Enum): Key.RUN_ONLY_CASES: frozenset([RestMethod.POST, WithChunksDomain.FALSE, CompressDomain.FALSE]), Key.SPECIFIC_CASES: {}, }, - 'map_schema_3_0_0': { + 'map_schema_4_0_0': { Key.PUBLICATION_TYPE: process_client.MAP_TYPE, Key.REST_ARGS: { 'file_paths': [ - f'{DIRECTORY}/map_schema_3_0_0.json', + f'{DIRECTORY}/map_schema_4_0_0.json', ], }, Key.EXCEPTION: LaymanError, @@ -497,7 +497,7 @@ class Key(Enum): 'http_code': 400, 'sync': True, 'code': 2, - 'data': {'expected': '2.x.x', + 'data': {'expected': '2.x.x or 3.x.x', 'parameter': 'file', 'reason': 'Invalid schema version'}, }, diff --git a/timgen/src/map.js b/timgen/src/map.js index cee65425d..e8694e0bf 100644 --- a/timgen/src/map.js +++ b/timgen/src/map.js @@ -175,8 +175,10 @@ const json_to_wms_layer = (layer_json, gs_public_url, gs_url, headers) => { const json_to_layer = (layer_json, gs_public_url, gs_url, headers) => { - switch (layer_json.className) { - case "HSLayers.Layer.WMS": + const class_name_split = layer_json.className.split('.') + const class_name_last = class_name_split[class_name_split.length-1] + switch (class_name_last) { + case "WMS": return json_to_wms_layer(layer_json, gs_public_url, gs_url, headers); break; // case 'OpenLayers.Layer.Vector': @@ -296,4 +298,4 @@ export const map_to_canvas = (map) => { export const log = (msg) => { console.log(msg); window['layman_logs'].push(msg); -} \ No newline at end of file +}