From db12a49a556e2718feed5c06ad47c3da6e0847aa Mon Sep 17 00:00:00 2001 From: index-git <66255344+index-git@users.noreply.github.com> Date: Tue, 23 Feb 2021 18:24:44 +0100 Subject: [PATCH] rest_layer.get returns 'style' with 'url' and 'type' ('sld' or 'qml') --- CHANGELOG.md | 1 + doc/rest.md | 1 + src/layman/layer/geoserver/sld.py | 3 ++- src/layman/layer/qgis/qgis_test.py | 8 ++++++-- src/layman/layer/qgis/wms.py | 11 +++++++++-- src/layman/layer/rest_layers_test.py | 4 ++++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d349a66..ba91c527d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - [#154](https://github.com/jirik/layman/issues/154) Layers with [QGIS style](https://docs.qgis.org/3.16/en/docs/user_manual/style_library/style_manager.html#exporting-items) are published on [GeoServer dedicated WMS workspace](doc/data-storage.md#geoserver) through WMS cascade from QGIS server, where they are stored as QGS file. All layers are published directly from PostgreSQL database to GeoServer for [WFS workspace](doc/data-storage.md#geoserver). - [#154](https://github.com/jirik/layman/issues/154) During startup, [LAYMAN_OUTPUT_SRS_LIST](doc/env-settings.md#LAYMAN_OUTPUT_SRS_LIST) is ensure for all QGIS layers. - [#154](https://github.com/jirik/layman/issues/154) Treat attribute names in QML (also known as '[launder](https://gdal.org/drivers/vector/pg.html#layer-creation-options)'). +- [#154](https://github.com/jirik/layman/issues/154) Endpoint [GET Layer](doc/rest.md#get-layer) returns in 'style' also 'type', either 'sld' or 'qml'. ## v1.9.1 2021-01-18 diff --git a/doc/rest.md b/doc/rest.md index 69e9ab909..24ae640e6 100644 --- a/doc/rest.md +++ b/doc/rest.md @@ -190,6 +190,7 @@ JSON object with following structure: - *error*: If status is FAILURE, this may contain error object. - **style** - *url*: String. URL of layer default style. It points to [GET Layer Style](#get-layer-style). + - *type*: String. Type of used style. Either 'sld' or 'qml'. - *status*: Status information about publishing style. See [GET Layer](#get-layer) **wms** property for meaning. - *error*: If status is FAILURE, this may contain error object. - **~~style~~** diff --git a/src/layman/layer/geoserver/sld.py b/src/layman/layer/geoserver/sld.py index 997f93468..6d2057fb3 100644 --- a/src/layman/layer/geoserver/sld.py +++ b/src/layman/layer/geoserver/sld.py @@ -49,7 +49,8 @@ def get_layer_info(username, layername): url = url_for('rest_layer_style.get', username=username, layername=layername) info = { 'style': { - 'url': url + 'url': url, + 'type': 'sld', }, } else: diff --git a/src/layman/layer/qgis/qgis_test.py b/src/layman/layer/qgis/qgis_test.py index c46293ec6..1a10f2a80 100644 --- a/src/layman/layer/qgis/qgis_test.py +++ b/src/layman/layer/qgis/qgis_test.py @@ -1,7 +1,7 @@ import pytest import os -from layman import app, settings +from layman import app, settings, util as layman_util from layman.layer import qgis from layman.layer.qgis import wms from test import process_client @@ -24,7 +24,11 @@ def test_qgis_rest(): assert os.path.exists(workspace_directory) assert os.path.exists(layer_directory) with app.app_context(): - assert wms.get_layer_info(workspace, layer) == {'name': layer} + url = layman_util.url_for('rest_layer_style.get', username=workspace, layername=layer) + assert wms.get_layer_info(workspace, layer) == {'name': layer, + 'style': {'type': 'qml', + 'url': url}, + } assert workspace in qgis.get_workspaces() process_client.delete_layer(workspace, layer) diff --git a/src/layman/layer/qgis/wms.py b/src/layman/layer/qgis/wms.py index ad45bb70e..c482620d0 100644 --- a/src/layman/layer/qgis/wms.py +++ b/src/layman/layer/qgis/wms.py @@ -2,8 +2,8 @@ from owslib.wms import WebMapService from . import util -from layman import patch_mode, settings from .. import db, qgis, util as layer_util +from layman import patch_mode, settings, util as layman_util PATCH_MODE = patch_mode.DELETE_IF_DEPENDANT VERSION = "1.3.0" @@ -25,7 +25,14 @@ def get_layer_info(username, layername): input_file_dir = qgis.get_layer_dir(username, layername) result = {} if os.path.exists(input_file_dir): - result = {'name': layername} + url = layman_util.url_for('rest_layer_style.get', username=username, layername=layername) + result = { + 'name': layername, + 'style': { + 'url': url, + 'type': 'qml', + }, + } return result diff --git a/src/layman/layer/rest_layers_test.py b/src/layman/layer/rest_layers_test.py index 3b60351f9..d347998e1 100644 --- a/src/layman/layer/rest_layers_test.py +++ b/src/layman/layer/rest_layers_test.py @@ -79,6 +79,8 @@ def test_style_correctly_saved(source_style_file_path, with app.app_context(): info = layer_util.get_layer_info(workspace, layer) assert info['style_type'] == 'sld' + assert info['style']['type'] == 'sld', info.get('style') + assert info['style']['url'], info.get('style') assert_style_file(workspace, layer, None) @@ -118,6 +120,8 @@ def assert_wms_layer(workspace, layer, style, expected_thumbnail_path=None): assert (os.path.exists(expected_style_file + '.qml')) == (style == 'qml') assert (os.path.exists(expected_style_file + '.sld')) == (style == 'sld') assert (os.path.exists(expected_qgis_file)) == (style == 'qml') + assert info['style']['type'] == style if style else 'sld', info.get('style') + assert info['style']['url'], info.get('style') rv = requests.get(wms_stores_url, auth=settings.LAYMAN_GS_AUTH,