Skip to content

Commit 33b4582

Browse files
committedMay 20, 2017
[Server] WMS GetCapabilities refactoring - Part 2
Part 2 (the last) for removing QgsWMSProjectParser from GetCapabilities
1 parent 258c872 commit 33b4582

File tree

7 files changed

+1131
-6
lines changed

7 files changed

+1131
-6
lines changed
 

‎src/server/qgsserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "qgsrequesthandler.h"
3232
#include "qgsapplication.h"
3333
#include "qgsconfigcache.h"
34+
#include "qgsconfigparserutils.h"
3435
#include "qgscapabilitiescache.h"
3536
#include "qgsmapsettings.h"
3637
#include "qgsmessagelog.h"

‎src/server/qgsserverprojectutils.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,70 @@ QStringList QgsServerProjectUtils::wmsRestrictedComposers( const QgsProject &pro
139139
return project.readListEntry( QStringLiteral( "WMSRestrictedComposers" ), QStringLiteral( "/" ), QStringList() );
140140
}
141141

142+
QStringList QgsServerProjectUtils::wmsOutputCrsList( const QgsProject &project )
143+
{
144+
QStringList crsList = project.readListEntry( QStringLiteral( "WMSCrsList" ), QStringLiteral( "/" ), QStringList() );
145+
if ( crsList.isEmpty() )
146+
{
147+
QStringList valueList = project.readListEntry( QStringLiteral( "WMSEpsgList" ), QStringLiteral( "/" ), QStringList() );
148+
bool conversionOk;
149+
for ( int i = 0; i < valueList.size(); ++i )
150+
{
151+
int epsgNr = valueList.at( i ).toInt( &conversionOk );
152+
if ( conversionOk )
153+
{
154+
crsList.append( QStringLiteral( "EPSG:%1" ).arg( epsgNr ) );
155+
}
156+
}
157+
}
158+
if ( crsList.isEmpty() )
159+
{
160+
//no CRS restriction defined in the project. Provide project CRS, wgs84 and pseudo mercator
161+
QString projectCrsId = project.crs().authid();
162+
crsList.append( projectCrsId );
163+
if ( projectCrsId.compare( QLatin1String( "EPSG:4326" ), Qt::CaseInsensitive ) != 0 )
164+
{
165+
crsList.append( QStringLiteral( "EPSG:%1" ).arg( 4326 ) );
166+
}
167+
if ( projectCrsId.compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) != 0 )
168+
{
169+
crsList.append( QStringLiteral( "EPSG:%1" ).arg( 3857 ) );
170+
}
171+
}
172+
return crsList;
173+
}
174+
142175
QString QgsServerProjectUtils::wmsServiceUrl( const QgsProject &project )
143176
{
144177
return project.readEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), "" );
145178
}
146179

180+
QString QgsServerProjectUtils::wmsRootName( const QgsProject &project )
181+
{
182+
return project.readEntry( QStringLiteral( "WMSRootName" ), QStringLiteral( "/" ), "" );
183+
}
184+
185+
QStringList QgsServerProjectUtils::wmsRestrictedLayers( const QgsProject &project )
186+
{
187+
return project.readListEntry( QStringLiteral( "WMSRestrictedLayers" ), QStringLiteral( "/" ), QStringList() );
188+
}
189+
190+
QgsRectangle QgsServerProjectUtils::wmsExtent( const QgsProject &project )
191+
{
192+
bool ok = false;
193+
QStringList values = project.readListEntry( QStringLiteral( "WMSExtent" ), QStringLiteral( "/" ), QStringList(), &ok );
194+
if ( !ok || values.size() != 4 )
195+
{
196+
return QgsRectangle();
197+
}
198+
//order of value elements must be xmin, ymin, xmax, ymax
199+
double xmin = values[ 0 ].toDouble();
200+
double ymin = values[ 1 ].toDouble();
201+
double xmax = values[ 2 ].toDouble();
202+
double ymax = values[ 3 ].toDouble();
203+
return QgsRectangle( xmin, ymin, xmax, ymax );
204+
}
205+
147206
QString QgsServerProjectUtils::wfsServiceUrl( const QgsProject &project )
148207
{
149208
return project.readEntry( QStringLiteral( "WFSUrl" ), QStringLiteral( "/" ), "" );

‎src/server/qgsserverprojectutils.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@ namespace QgsServerProjectUtils
173173
*/
174174
SERVER_EXPORT QString wmsServiceUrl( const QgsProject &project );
175175

176+
/** Returns the WMS root layer name defined in a QGIS project.
177+
* \param project the QGIS project
178+
* \returns root layer name if defined in project, an empty string otherwise.
179+
*/
180+
SERVER_EXPORT QString wmsRootName( const QgsProject &project );
181+
182+
/** Returns the restricted layer name list.
183+
* \param project the QGIS project
184+
* \returns the restricted layer name list if defined in project.
185+
*/
186+
SERVER_EXPORT QStringList wmsRestrictedLayers( const QgsProject &project );
187+
188+
/** Returns the WMS output CRS list.
189+
* \param project the QGIS project
190+
* \returns the WMS output CRS list.
191+
*/
192+
SERVER_EXPORT QStringList wmsOutputCrsList( const QgsProject &project );
193+
194+
/** Returns the WMS Extent restriction.
195+
* \param project the QGIS project
196+
* \returns the WMS Extent restriction.
197+
*/
198+
SERVER_EXPORT QgsRectangle wmsExtent( const QgsProject &project );
199+
176200
/** Returns the WFS service url defined in a QGIS project.
177201
* \param project the QGIS project
178202
* \returns url if defined in project, an empty string otherwise.

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

Lines changed: 1001 additions & 6 deletions
Large diffs are not rendered by default.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@
2121
#ifndef QGSWMSGETCAPABILITIES_H
2222
#define QGSWMSGETCAPABILITIES_H
2323

24+
#include "qgslayertreenode.h"
25+
#include "qgslayertreegroup.h"
26+
#include "qgslayertreelayer.h"
27+
#include "qgslayertreemodel.h"
28+
#include "qgslayertree.h"
29+
2430
namespace QgsWms
2531
{
2632

33+
/**
34+
* Create element for get capabilities document
35+
*/
36+
QDomElement getLayersAndStylesCapabilitiesElement( QDomDocument &doc, QgsServerInterface *serverIface,
37+
const QgsProject *project, const QString &version,
38+
const QgsServerRequest &request, bool projectSettings );
39+
2740
/**
2841
* Create WFSLayers element for get capabilities document
2942
*/

‎src/server/services/wms/qgswmsutils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class QgsRectangle;
3737
//! WMS implementation
3838
namespace QgsWms
3939
{
40+
// style name to use for the unnamed style of layers (must not be empty name in WMS)
41+
// this implies that a layer style called "default" will not be usable in WMS server
42+
const QString EMPTY_STYLE_NAME = QStringLiteral( "default" );
4043

4144
//! Supported image output format
4245
enum ImageOutputFormat

‎tests/src/python/test_qgsserver_accesscontrol.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,36 @@ def test_wms_getcapabilities(self):
234234
str(response).find("<Name>Country</Name>") != -1,
235235
"Country layer in GetCapabilities\n%s" % response)
236236

237+
def test_wms_getprojectsettings(self):
238+
query_string = "&".join(["%s=%s" % i for i in list({
239+
"MAP": urllib.parse.quote(self.projectPath),
240+
"SERVICE": "WMS",
241+
"VERSION": "1.1.1",
242+
"REQUEST": "GetProjectSettings"
243+
}.items())])
244+
245+
response, headers = self._get_fullaccess(query_string)
246+
self.assertTrue(
247+
str(response).find("<TreeName>Hello</TreeName>") != -1,
248+
"No Hello layer in GetProjectSettings\n%s" % response)
249+
self.assertTrue(
250+
str(response).find("<TreeName>Country</TreeName>") != -1,
251+
"No Country layer in GetProjectSettings\n%s" % response)
252+
self.assertTrue(
253+
str(response).find("<LayerDrawingOrder>Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
254+
"LayerDrawingOrder in GetProjectSettings\n%s" % response)
255+
256+
response, headers = self._get_restricted(query_string)
257+
self.assertTrue(
258+
str(response).find("<TreeName>Hello</TreeName>") != -1,
259+
"No Hello layer in GetProjectSettings\n%s" % response)
260+
self.assertFalse(
261+
str(response).find("<TreeName>Country</TreeName>") != -1,
262+
"Country layer in GetProjectSettings\n%s" % response)
263+
self.assertTrue(
264+
str(response).find("<LayerDrawingOrder>Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point</LayerDrawingOrder>") != -1,
265+
"LayerDrawingOrder in GetProjectSettings\n%s" % response)
266+
237267
def test_wms_describelayer_hello(self):
238268
query_string = "&".join(["%s=%s" % i for i in list({
239269
"MAP": urllib.parse.quote(self.projectPath),

0 commit comments

Comments
 (0)
Please sign in to comment.