Skip to content
Permalink
Browse files

Merge pull request #4637 from rldhont/server-wms-configparser-describ…

…elayer

[Server] WMS DescribeLayer refactoring
  • Loading branch information
rldhont committed May 29, 2017
2 parents d996cf2 + 8a0261c commit 8356c767b905bb6fb715c2196f9781384532f230
@@ -243,5 +243,5 @@ namespace QgsServerProjectUtils
* @param project the QGIS project
* @return the Layer ids list.
*/
QStringList wcsLayers( const QgsProject &project );
QStringList wcsLayerIds( const QgsProject &project );
};
@@ -263,7 +263,7 @@ QString QgsServerProjectUtils::wcsServiceUrl( const QgsProject &project )
return project.readEntry( QStringLiteral( "WCSUrl" ), QStringLiteral( "/" ), "" );
}

QStringList QgsServerProjectUtils::wcsLayers( const QgsProject &project )
QStringList QgsServerProjectUtils::wcsLayerIds( const QgsProject &project )
{
return project.readListEntry( QStringLiteral( "WCSLayers" ), QStringLiteral( "/" ) );
}
@@ -245,7 +245,7 @@ namespace QgsServerProjectUtils
* \param project the QGIS project
* \returns the Layer ids list.
*/
SERVER_EXPORT QStringList wcsLayers( const QgsProject &project );
SERVER_EXPORT QStringList wcsLayerIds( const QgsProject &project );
};

#endif
@@ -94,7 +94,7 @@ namespace QgsWcs
}
}

QStringList wcsLayersId = QgsServerProjectUtils::wcsLayers( *project );
QStringList wcsLayersId = QgsServerProjectUtils::wcsLayerIds( *project );
for ( int i = 0; i < wcsLayersId.size(); ++i )
{
QgsMapLayer *layer = project->mapLayer( wcsLayersId.at( i ) );
@@ -260,7 +260,7 @@ namespace QgsWcs
*/
QDomElement contentMetadataElement = doc.createElement( QStringLiteral( "ContentMetadata" )/*wcs:ContentMetadata*/ );

QStringList wcsLayersId = QgsServerProjectUtils::wcsLayers( *project );
QStringList wcsLayersId = QgsServerProjectUtils::wcsLayerIds( *project );
for ( int i = 0; i < wcsLayersId.size(); ++i )
{
QgsMapLayer *layer = project->mapLayer( wcsLayersId.at( i ) );
@@ -73,7 +73,7 @@ namespace QgsWcs
}

//get the raster layer
QStringList wcsLayersId = QgsServerProjectUtils::wcsLayers( *project );
QStringList wcsLayersId = QgsServerProjectUtils::wcsLayerIds( *project );

QgsRasterLayer *rLayer = nullptr;
for ( int i = 0; i < wcsLayersId.size(); ++i )
@@ -40,7 +40,6 @@ namespace QgsWms
Q_UNUSED( version );

QgsServerRequest::Parameters parameters = request.parameters();
QgsWmsConfigParser *configParser = getConfigParser( serverIface );

if ( !parameters.contains( QStringLiteral( "SLD_VERSION" ) ) )
{
@@ -64,6 +63,24 @@ namespace QgsWms
{
throw QgsServiceException( QStringLiteral( "InvalidParameterValue" ), QStringLiteral( "Layers is empty" ), 400 );
}
QDomDocument myDocument = QDomDocument();

QDomNode header = myDocument.createProcessingInstruction( QStringLiteral( "xml" ), QStringLiteral( "version=\"1.0\" encoding=\"UTF-8\"" ) );
myDocument.appendChild( header );

// Create the root element
QDomElement root = myDocument.createElementNS( QStringLiteral( "http://www.opengis.net/sld" ), QStringLiteral( "DescribeLayerResponse" ) );
root.setAttribute( QStringLiteral( "xsi:schemaLocation" ), QStringLiteral( "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/DescribeLayer.xsd" ) );
root.setAttribute( QStringLiteral( "xmlns:ows" ), QStringLiteral( "http://www.opengis.net/ows" ) );
root.setAttribute( QStringLiteral( "xmlns:se" ), QStringLiteral( "http://www.opengis.net/se" ) );
root.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
root.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
myDocument.appendChild( root );

// store the Version element
QDomElement versionNode = myDocument.createElement( QStringLiteral( "Version" ) );
versionNode.appendChild( myDocument.createTextNode( QStringLiteral( "1.1.0" ) ) );
root.appendChild( versionNode );

// get the wms service url defined in project or keep the one from the
// request url
@@ -85,7 +102,86 @@ namespace QgsWms
wcsHrefString = wmsHrefString;
}

return configParser->describeLayer( layersList, wfsHrefString, wcsHrefString );
// access control
QgsAccessControl *accessControl = serverIface->accessControls();
// Use layer ids
bool useLayerIds = QgsServerProjectUtils::wmsUseLayerIds( *project );
// WMS restricted layers
QStringList restrictedLayers = QgsServerProjectUtils::wmsRestrictedLayers( *project );
// WFS layers
QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *project );
// WCS layers
QStringList wcsLayerIds = QgsServerProjectUtils::wcsLayerIds( *project );

Q_FOREACH ( QgsMapLayer *layer, project->mapLayers() )
{
QString name = layer->name();
if ( useLayerIds )
name = layer->id();
else if ( !layer->shortName().isEmpty() )
name = layer->shortName();

if ( !layersList.contains( name ) )
{
continue;
}

//unpublished layer
if ( restrictedLayers.contains( layer->name() ) )
{
throw QgsSecurityException( QStringLiteral( "You are not allowed to access to this layer" ) );
}

if ( accessControl && !accessControl->layerReadPermission( layer ) )
{
throw QgsSecurityException( QStringLiteral( "You are not allowed to access to this layer" ) );
}

// Create the NamedLayer element
QDomElement layerNode = myDocument.createElement( QStringLiteral( "LayerDescription" ) );
root.appendChild( layerNode );

// store the owsType element
QDomElement typeNode = myDocument.createElement( QStringLiteral( "owsType" ) );
// store the se:OnlineResource element
QDomElement oResNode = myDocument.createElement( QStringLiteral( "se:OnlineResource" ) );
oResNode.setAttribute( QStringLiteral( "xlink:type" ), QStringLiteral( "simple" ) );
// store the TypeName element
QDomElement nameNode = myDocument.createElement( QStringLiteral( "TypeName" ) );
if ( layer->type() == QgsMapLayer::VectorLayer )
{
typeNode.appendChild( myDocument.createTextNode( QStringLiteral( "wfs" ) ) );

if ( wfsLayerIds.indexOf( layer->id() ) != -1 )
{
oResNode.setAttribute( QStringLiteral( "xlink:href" ), wfsHrefString );
}

// store the se:FeatureTypeName element
QDomElement typeNameNode = myDocument.createElement( QStringLiteral( "se:FeatureTypeName" ) );
typeNameNode.appendChild( myDocument.createTextNode( name ) );
nameNode.appendChild( typeNameNode );
}
else if ( layer->type() == QgsMapLayer::RasterLayer )
{
typeNode.appendChild( myDocument.createTextNode( QStringLiteral( "wcs" ) ) );

if ( wcsLayerIds.indexOf( layer->id() ) != -1 )
{
oResNode.setAttribute( QStringLiteral( "xlink:href" ), wcsHrefString );
}

// store the se:CoverageTypeName element
QDomElement typeNameNode = myDocument.createElement( QStringLiteral( "se:CoverageTypeName" ) );
typeNameNode.appendChild( myDocument.createTextNode( name ) );
nameNode.appendChild( typeNameNode );
}
layerNode.appendChild( typeNode );
layerNode.appendChild( oResNode );
layerNode.appendChild( nameNode );
}

return myDocument;
}

} // samespace QgsWms
@@ -125,6 +125,12 @@ def test_project_wms(self):
'FEATURE_COUNT=10&FILTER=testlayer%20%C3%A8%C3%A9' + urllib.parse.quote(':"NAME" = \'two\' OR "utf8nameè" = \'three èé↓\''),
'wms_getfeatureinfo_filter_or_utf8')

# Test DescribeLayer
self.wms_request_compare('DescribeLayer',
'&layers=testlayer%20%C3%A8%C3%A9&' +
'SLD_VERSION=1.1.0',
'describelayer')

def wms_inspire_request_compare(self, request):
"""WMS INSPIRE tests"""
project = self.testdata_path + "test_project_inspire.qgs"
@@ -0,0 +1,14 @@
*****
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<DescribeLayerResponse xmlns="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/DescribeLayer.xsd" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink">
<Version>1.1.0</Version>
<LayerDescription>
<owsType>wfs</owsType>
<se:OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?*****"/>
<TypeName>
<se:FeatureTypeName>testlayer èé</se:FeatureTypeName>
</TypeName>
</LayerDescription>
</DescribeLayerResponse>

0 comments on commit 8356c76

Please sign in to comment.
You can’t perform that action at this time.