Skip to content

Commit 916ab4e

Browse files
committed
uuid layer metadata comparison endpoint
1 parent e5f9ca4 commit 916ab4e

11 files changed

Lines changed: 56 additions & 45 deletions

File tree

doc/client-proxy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ Currently, value of X-Forwarded headers affects following URLs:
8282
* [WFS endpoints](endpoints.md#web-feature-service)
8383
* all operations URLs
8484

85-
Values of X-Forwarded headers does not affect responses of [GET Workspace Layer Metadata Comparison](rest.md#get-workspace-layer-metadata-comparison) and [GET Workspace Map Metadata Comparison](rest.md#get-workspace-map-metadata-comparison) intentionally, in order to keep URLs in canonical form.
85+
Values of X-Forwarded headers does not affect responses of [GET Layer Metadata Comparison](rest.md#get-layer-metadata-comparison) and [GET Workspace Map Metadata Comparison](rest.md#get-workspace-map-metadata-comparison) intentionally, in order to keep URLs in canonical form.

doc/rest.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
|Layer Thumbnail|`/rest/layers/<uuid>/thumbnail`|[GET](#get-layer-thumbnail)| x | x | x |
1010
|Layer Style|`/rest/layers/<uuid>/style`|[GET](#get-layer-style)| x | x | x |
1111
|Layer Chunk|`/rest/layers/<uuid>/chunk`|[GET](#get-layer-chunk)| [POST](#post-layer-chunk) | x | x |
12+
<<<<<<< HEAD
1213
|Workspace Layer Metadata Comparison|`/rest/workspaces/<workspace_name>/layers/<layername>/metadata-comparison`|[GET](#get-workspace-layer-metadata-comparison) | x | x | x |
14+
=======
15+
|Layer Metadata Comparison|`/rest/layers/<uuid>/metadata-comparison`|[GET](#get-layer-metadata-comparison) | x | x | x |
16+
>>>>>>> 580dffe1 (uuid layer metadata comparison endpoint)
1317
|Maps|`/rest/maps`|[GET](#get-maps)| [POST](#post-maps) | x | [DELETE](#delete-maps) |
1418
|[Map](models.md#map)|`/rest/maps/<uuid>`|[GET](#get-map)| x | [PATCH](#patch-map) | [DELETE](#delete-map) |
1519
|Map Thumbnail|`/rest/maps/<uuid>/thumbnail`|[GET](#get-map-thumbnail)| x | x | x |
@@ -330,7 +334,7 @@ JSON object with following structure:
330334
- *identifier*: String. Identifier of metadata record in CSW instance.
331335
- *record_url*: String. URL of metadata record accessible by web browser, probably with some editing capabilities.
332336
- *csw_url*: String. URL of CSW endpoint. It points to CSW endpoint of Micka.
333-
- *comparison_url*: String. URL of [GET Workspace Layer Metadata Comparison](#get-workspace-layer-metadata-comparison).
337+
- *comparison_url*: String. URL of [GET Layer Metadata Comparison](#get-layer-metadata-comparison).
334338
- *status*: Status information about metadata import and availability. See [GET Layer](#get-layer) **wms** property for meaning.
335339
- *error*: If status is FAILURE, this may contain error object.
336340
- **access_rights**:
@@ -505,7 +509,7 @@ Content-Type: `application/json`
505509
HTTP status code 200 if chunk was successfully saved.
506510

507511

508-
### GET Workspace Layer Metadata Comparison
512+
### GET Layer Metadata Comparison
509513
Get comparison of metadata properties among Layman, CSW, WMS and WFS.
510514

511515
#### Request

src/layman/layer/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def get_layer_patch_keys():
3939

4040
from ..common import InternalSourceTypeDef
4141
from .rest_layer_chunk import bp as layer_chunk_bp
42+
from .rest_layer_metadata_comparison import bp as layer_metadata_comparison_bp
4243
from .rest_layer_thumbnail import bp as layer_thumbnail_bp
4344
from .rest_layer_style import bp as layer_style_bp
44-
from .rest_workspace_layer_metadata_comparison import bp as workspace_layer_metadata_comparison_bp
4545
from .rest_layers import bp as layers_bp
4646
from .rest_layer import bp as layer_bp
4747

@@ -52,11 +52,11 @@ def get_layer_patch_keys():
5252
'name': PUBLICATION_TYPE_NAME,
5353
'rest_path_name': LAYER_REST_PATH_NAME,
5454
'workspace_blueprints': [ # blueprints to register
55-
workspace_layer_metadata_comparison_bp,
5655
],
5756
'blueprints': [ # blueprints to register
5857
layers_bp,
5958
layer_bp,
59+
layer_metadata_comparison_bp,
6060
layer_thumbnail_bp,
6161
layer_style_bp,
6262
layer_chunk_bp,

src/layman/layer/micka/csw.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def get_layer_info(workspace, layername, *, x_forwarded_items=None):
4646
'identifier': muuid,
4747
'csw_url': settings.CSW_PROXY_URL,
4848
'record_url': common_util.get_metadata_url(layer.uuid, url_type=common_util.RecordUrlType.BASIC),
49-
'comparison_url': url_for('rest_workspace_layer_metadata_comparison.get', workspace=workspace, layername=layername,
50-
x_forwarded_items=x_forwarded_items),
49+
'comparison_url': url_for('rest_layer_metadata_comparison.get', uuid=layer.uuid, x_forwarded_items=x_forwarded_items),
5150
}
5251
}
5352
return {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from flask import Blueprint, current_app as app, g, jsonify
2+
3+
from layman.authn import authenticate
4+
from layman.authz import authorize_uuid_publication_decorator
5+
from layman.util import check_uuid_decorator
6+
from . import util, LAYER_REST_PATH_NAME, LAYER_TYPE
7+
from .layer_class import Layer
8+
9+
bp = Blueprint('rest_layer_metadata_comparison', __name__)
10+
11+
12+
@bp.before_request
13+
@check_uuid_decorator
14+
@authenticate
15+
@authorize_uuid_publication_decorator(expected_publication_type=LAYER_TYPE)
16+
def before_request():
17+
pass
18+
19+
20+
@bp.route(f"/{LAYER_REST_PATH_NAME}/<uuid>/metadata-comparison", methods=['GET'])
21+
def get(uuid):
22+
app.logger.info(f"GET Layer Metadata Comparison, actor={g.user}")
23+
24+
layer = Layer(uuid=uuid)
25+
md_props = util.get_metadata_comparison(layer)
26+
27+
return jsonify(md_props), 200

src/layman/layer/rest_workspace_layer_metadata_comparison.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/layman/layer/rest_workspace_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def test_post_layers_simple():
180180
md_record_url = f"http://micka:80/record/basic/m-{layeruuid}"
181181
assert layer_info['metadata']['record_url'].replace("http://localhost:3080", "http://micka:80") == md_record_url
182182
with app.app_context():
183-
assert layer_info['metadata']['comparison_url'] == test_util.url_for_external('rest_workspace_layer_metadata_comparison.get',
184-
workspace=workspace, layername=layername)
183+
assert layer_info['metadata']['comparison_url'] == test_util.url_for_external('rest_layer_metadata_comparison.get',
184+
uuid=layeruuid)
185185
assert 'id' not in layer_info.keys()
186186
assert 'type' not in layer_info.keys()
187187

src/layman/rest_responses_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ class TestResponsesClass:
122122
'geodata_type': 'vector',
123123
'file': {'paths': [f'layers/{layer_uuid}/input_file/{layer_uuid}.geojson'],
124124
},
125-
'metadata': {'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{workspace}/layers/{publication}/'
126-
f'metadata-comparison',
125+
'metadata': {'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/layers/{layer_uuid}/metadata-comparison',
127126
'csw_url': f'{settings.CSW_PROXY_URL}',
128127
'identifier': f"m-{layer_uuid}",
129128
'record_url': None},

test_tools/process_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
'rest_layers.delete',
8181
layer_keys_to_check,
8282
'sample/layman.layer/small_layer.geojson',
83-
'rest_workspace_layer_metadata_comparison.get',
83+
'rest_layer_metadata_comparison.get',
8484
'rest_layer_chunk.post',
8585
),
8686
None: PublicationTypeDef('publicationname',
@@ -492,7 +492,13 @@ def get_workspace_publication_metadata_comparison(publication_type, workspace, n
492492

493493
publication_type_def = PUBLICATION_TYPES_DEF[publication_type]
494494
with app.app_context():
495-
r_url = url_for(publication_type_def.get_workspace_metadata_comparison_url, **{publication_type_def.url_param_name: name}, workspace=workspace)
495+
if publication_type == LAYER_TYPE:
496+
uuid = layman_util.get_publication_uuid(workspace, publication_type, name)
497+
r_url = url_for(publication_type_def.get_workspace_metadata_comparison_url, uuid=uuid)
498+
else:
499+
r_url = url_for(publication_type_def.get_workspace_metadata_comparison_url,
500+
**{publication_type_def.url_param_name: name},
501+
workspace=workspace)
496502
response = requests.get(r_url, headers=headers, timeout=HTTP_TIMEOUT)
497503
raise_layman_error(response)
498504
return response.json()

tests/asserts/final/publication/internal.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def _correct_values_in_detail_common(
158158
publ_type_dir = util.get_directory_name_from_publ_type(publ_type)
159159

160160
thumbnail_url = f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/{publ_type_dir}/{uuid}/thumbnail'
161+
comparison_url = f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{workspace}/{publ_type_dir}/{name}/metadata-comparison'
162+
if publ_type == process_client.LAYER_TYPE:
163+
comparison_url = f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/{publ_type_dir}/{uuid}/metadata-comparison'
161164

162165
expected_detail = {
163166
'name': name,
@@ -166,9 +169,7 @@ def _correct_values_in_detail_common(
166169
'type': publ_type,
167170
'thumbnail': {'url': thumbnail_url,
168171
'path': f'{publ_type_dir}/{uuid}/thumbnail/{uuid}.png'},
169-
'metadata': {'comparison_url':
170-
f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/'
171-
f'{workspace}/{publ_type_dir}/{name}/metadata-comparison',
172+
'metadata': {'comparison_url': comparison_url,
172173
'csw_url': 'http://localhost:3080/csw'},
173174
'_thumbnail': {'path': f'/layman_data_test/{publ_type_dir}/{uuid}/thumbnail/{uuid}.png'},
174175
'access_rights': {'read': ['EVERYONE'], 'write': ['EVERYONE']},

0 commit comments

Comments
 (0)