Skip to content

Commit c05d779

Browse files
authoredMay 26, 2017
Merge pull request #4630 from rldhont/server-wms-configparser-getcontext
[Server] WMS GetContext refactoring
2 parents 8c873b1 + ce3cbeb commit c05d779

File tree

9 files changed

+488
-17
lines changed

9 files changed

+488
-17
lines changed
 

‎python/server/qgsserverprojectutils.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace QgsServerProjectUtils
127127
* \param project the QGIS project
128128
* \returns if Inspire is activated.
129129
*/
130-
bool wmsInspireActivated( const QgsProject &project );
130+
bool wmsInspireActivate( const QgsProject &project );
131131

132132
/** Returns the Inspire language.
133133
* \param project the QGIS project

‎src/server/qgsserverprojectutils.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,20 @@ QString QgsServerProjectUtils::owsServiceAbstract( const QgsProject &project )
3434

3535
QStringList QgsServerProjectUtils::owsServiceKeywords( const QgsProject &project )
3636
{
37-
return project.readListEntry( QStringLiteral( "WMSKeywordList" ), QStringLiteral( "/" ) );
37+
QStringList keywordList;
38+
QStringList list = project.readListEntry( QStringLiteral( "WMSKeywordList" ), QStringLiteral( "/" ), QStringList() );
39+
if ( !list.isEmpty() )
40+
{
41+
for ( int i = 0; i < list.size(); ++i )
42+
{
43+
QString keyword = list.at( i );
44+
if ( !keyword.isEmpty() )
45+
{
46+
keywordList.append( keyword );
47+
}
48+
}
49+
}
50+
return keywordList;
3851
}
3952

4053
QString QgsServerProjectUtils::owsServiceOnlineResource( const QgsProject &project )
@@ -104,7 +117,7 @@ bool QgsServerProjectUtils::wmsInfoFormatSia2045( const QgsProject &project )
104117
return false;
105118
}
106119

107-
bool QgsServerProjectUtils::wmsInspireActivated( const QgsProject &project )
120+
bool QgsServerProjectUtils::wmsInspireActivate( const QgsProject &project )
108121
{
109122
return project.readBoolEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/activated" ) );
110123
}
@@ -141,7 +154,19 @@ QStringList QgsServerProjectUtils::wmsRestrictedComposers( const QgsProject &pro
141154

142155
QStringList QgsServerProjectUtils::wmsOutputCrsList( const QgsProject &project )
143156
{
144-
QStringList crsList = project.readListEntry( QStringLiteral( "WMSCrsList" ), QStringLiteral( "/" ), QStringList() );
157+
QStringList crsList;
158+
QStringList wmsCrsList = project.readListEntry( QStringLiteral( "WMSCrsList" ), QStringLiteral( "/" ), QStringList() );
159+
if ( !wmsCrsList.isEmpty() )
160+
{
161+
for ( int i = 0; i < wmsCrsList.size(); ++i )
162+
{
163+
QString crs = wmsCrsList.at( i );
164+
if ( !crs.isEmpty() )
165+
{
166+
crsList.append( crs );
167+
}
168+
}
169+
}
145170
if ( crsList.isEmpty() )
146171
{
147172
QStringList valueList = project.readListEntry( QStringLiteral( "WMSEpsgList" ), QStringLiteral( "/" ), QStringList() );

‎src/server/qgsserverprojectutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace QgsServerProjectUtils
129129
* \param project the QGIS project
130130
* \returns if Inspire is activated.
131131
*/
132-
SERVER_EXPORT bool wmsInspireActivated( const QgsProject &project );
132+
SERVER_EXPORT bool wmsInspireActivate( const QgsProject &project );
133133

134134
/** Returns the Inspire language.
135135
* \param project the QGIS project

‎src/server/services/wms/qgswmsgetcapabilities.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#include "qgslayertreelayer.h"
3535
#include "qgslayertreemodel.h"
3636
#include "qgslayertree.h"
37+
#include "qgsmaplayerstylemanager.h"
3738

3839
#include "qgscsexception.h"
3940
#include "qgsexpressionnodeimpl.h"
40-
#include "qgsmaplayerstylemanager.h"
4141

4242

4343
namespace QgsWms
@@ -180,7 +180,7 @@ namespace QgsWms
180180
schemaLocation += QLatin1String( " http://www.opengis.net/sld" );
181181
schemaLocation += QLatin1String( " http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd" );
182182
schemaLocation += QLatin1String( " http://www.qgis.org/wms" );
183-
if ( QgsServerProjectUtils::wmsInspireActivated( *project ) )
183+
if ( QgsServerProjectUtils::wmsInspireActivate( *project ) )
184184
{
185185
wmsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:inspire_common" ), QStringLiteral( "http://inspire.ec.europa.eu/schemas/common/1.0" ) );
186186
wmsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:inspire_vs" ), QStringLiteral( "http://inspire.ec.europa.eu/schemas/inspire_vs/1.0" ) );
@@ -533,7 +533,7 @@ namespace QgsWms
533533
elem.setAttribute( QStringLiteral( "RemoteWCS" ), QStringLiteral( "0" ) );
534534
capabilityElem.appendChild( elem );
535535

536-
if ( QgsServerProjectUtils::wmsInspireActivated( *project ) )
536+
if ( QgsServerProjectUtils::wmsInspireActivate( *project ) )
537537
{
538538
capabilityElem.appendChild( getInspireCapabilitiesElement( doc, project ) );
539539
}
@@ -546,7 +546,7 @@ namespace QgsWms
546546
{
547547
QDomElement inspireCapabilitiesElem;
548548

549-
if ( !QgsServerProjectUtils::wmsInspireActivated( *project ) )
549+
if ( !QgsServerProjectUtils::wmsInspireActivate( *project ) )
550550
return inspireCapabilitiesElem;
551551

552552
inspireCapabilitiesElem = doc.createElement( QStringLiteral( "inspire_vs:ExtendedCapabilities" ) );
@@ -993,7 +993,7 @@ namespace QgsWms
993993
// add details about supported styles of the layer
994994
appendLayerStyles( doc, layerElem, l, project, version, request );
995995

996-
//min/max scale denominatormScaleBasedVisibility
996+
//min/max scale denominatorScaleBasedVisibility
997997
if ( l->hasScaleBasedVisibility() )
998998
{
999999
if ( version == QLatin1String( "1.1.1" ) )

‎src/server/services/wms/qgswmsgetcontext.cpp

Lines changed: 393 additions & 3 deletions
Large diffs are not rendered by default.

‎tests/src/python/test_qgsserver_accesscontrol.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,34 @@ def test_wms_getprojectsettings(self):
264264
str(response).find("<LayerDrawingOrder>Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
265265
"LayerDrawingOrder in GetProjectSettings\n%s" % response)
266266

267+
def test_wms_getprojectsettings(self):
268+
query_string = "&".join(["%s=%s" % i for i in list({
269+
"MAP": urllib.parse.quote(self.projectPath),
270+
"SERVICE": "WMS",
271+
"VERSION": "1.1.1",
272+
"REQUEST": "GetContext"
273+
}.items())])
274+
275+
response, headers = self._get_fullaccess(query_string)
276+
self.assertTrue(
277+
str(response).find("name=\"Hello\"") != -1,
278+
"No Hello layer in GetContext\n%s" % response)
279+
self.assertTrue(
280+
str(response).find("name=\"Country\"") != -1,
281+
"No Country layer in GetProjectSettings\n%s" % response)
282+
self.assertTrue(
283+
str(response).find("name=\"Country\"")
284+
< str(response).find("name=\"Hello\""),
285+
"Hello layer not after Country layer\n%s" % response)
286+
287+
response, headers = self._get_restricted(query_string)
288+
self.assertTrue(
289+
str(response).find("name=\"Hello\"") != -1,
290+
"No Hello layer in GetContext\n%s" % response)
291+
self.assertFalse(
292+
str(response).find("name=\"Country\"") != -1,
293+
"No Country layer in GetProjectSettings\n%s" % response)
294+
267295
def test_wms_describelayer_hello(self):
268296
query_string = "&".join(["%s=%s" % i for i in list({
269297
"MAP": urllib.parse.quote(self.projectPath),

‎tests/src/python/test_qgsserver_wms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def wms_request_compare(self, request, extra=None, reference_file=None):
6565

6666
def test_project_wms(self):
6767
"""Test some WMS request"""
68-
for request in ('GetCapabilities', 'GetProjectSettings'):
68+
for request in ('GetCapabilities', 'GetProjectSettings', 'GetContext'):
6969
self.wms_request_compare(request)
7070

7171
# Test getfeatureinfo response
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
*****
2+
Content-Type: text/xml; charset=utf-8
3+
4+
<?xml version="1.0" encoding="utf-8"?>
5+
<OWSContext xmlns:ogc="http://www.opengis.net/ogc" version="0.3.1" xmlns:context="http://www.opengis.net/context" xmlns="http://www.opengis.net/ows-context" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ows-context="http://www.opengis.net/ows-context" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" id="ows-context-test_project" xmlns:ows="http://www.opengis.net/ows" xmlns:ns9="http://www.w3.org/2005/Atom" xmlns:ins="http://www.inspire.org">
6+
<General>
7+
<Window width="800" height="600"/>
8+
<ows:Title>QGIS TestProject</ows:Title>
9+
<ows:Abstract>Some UTF8 text èòù</ows:Abstract>
10+
<ows:BoundingBox crs="EPSG:4326">
11+
<ows:LowerCorner>44.9012 8.20315</ows:LowerCorner>
12+
<ows:UpperCorner>44.9016 8.20416</ows:UpperCorner>
13+
</ows:BoundingBox>
14+
</General>
15+
<ResourceList>
16+
<Layer opacity="1" queryable="true" hidden="false" id="testlayer_èé" name="testlayer èé">
17+
<ows:Title>A test vector layer</ows:Title>
18+
<ows:OutputFormat>image/png</ows:OutputFormat>
19+
<Server version="1.3.0" default="true" service="urn:ogc:serviceType:WMS">
20+
<OnlineResource xlink:href="https://www.qgis.org/?*****&amp;"/>
21+
</Server>
22+
<ows:Abstract>A test vector layer with unicode òà</ows:Abstract>
23+
<StyleList>
24+
<Style current="true">
25+
<Name>default</Name>
26+
<Title>default</Title>
27+
</Style>
28+
</StyleList>
29+
</Layer>
30+
</ResourceList>
31+
</OWSContext>

‎tests/testdata/qgis_server/wcs_getcapabilities.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ Content-Type: text/xml; charset=utf-8
66
<name>WCS</name>
77
<label>QGIS Server test</label>
88
<description><![CDATA[Simple test app.]]></description>
9-
<keywords>
10-
<keyword></keyword>
11-
</keywords>
129
<responsibleParty>
1310
<individualName>Stéphane Brunner</individualName>
1411
<organisationName>QGIS</organisationName>

0 commit comments

Comments
 (0)
Please sign in to comment.