Skip to content

Commit

Permalink
rest_layer.get returns 'style' with 'url' and 'type' ('sld' or 'qml')
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Feb 23, 2021
1 parent 8bb1c2a commit 48cf0e2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions doc/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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~~**
Expand Down
3 changes: 2 additions & 1 deletion src/layman/layer/geoserver/sld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions src/layman/layer/qgis/qgis_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions src/layman/layer/qgis/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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


Expand Down
4 changes: 4 additions & 0 deletions src/layman/layer/rest_layers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 48cf0e2

Please sign in to comment.