Skip to content
Permalink
Browse files

Merge pull request #4313 from pblottiere/cleansingleton

[Server] WMS getmap refactoring
  • Loading branch information
rldhont committed Jun 1, 2017
2 parents e9a7dff + e663d19 commit df9ee6f705dcf18944d4de2366842821d1ee5123
Showing with 17,275 additions and 1,112 deletions.
  1. +1 −0 python/core/qgsproject.sip
  2. +8 −5 python/server/qgsserverprojectparser.sip
  3. +5 −0 src/core/qgsproject.cpp
  4. +6 −0 src/core/qgsproject.h
  5. +14 −0 src/server/qgsconfigcache.cpp
  6. +10 −0 src/server/qgsconfigcache.h
  7. +25 −1 src/server/qgsfilterrestorer.cpp
  8. +7 −0 src/server/qgsfilterrestorer.h
  9. +5 −14 src/server/qgsserver.cpp
  10. +2 −2 src/server/qgsserver.h
  11. +86 −214 src/server/qgsserverprojectparser.cpp
  12. +11 −13 src/server/qgsserverprojectparser.h
  13. +1 −1 src/server/qgsserverprojectutils.cpp
  14. +2 −18 src/server/qgswmsprojectparser.cpp
  15. +10 −1 src/server/services/wms/CMakeLists.txt
  16. +115 −0 src/server/services/wms/qgslayerrestorer.cpp
  17. +48 −0 src/server/services/wms/qgslayerrestorer.h
  18. +660 −0 src/server/services/wms/qgswmsparameters.cpp
  19. +301 −0 src/server/services/wms/qgswmsparameters.h
  20. +582 −35 src/server/services/wms/qgswmsrenderer.cpp
  21. +61 −2 src/server/services/wms/qgswmsrenderer.h
  22. +6 −2 tests/src/python/test_qgsserver.py
  23. +11 −12 tests/src/python/test_qgsserver_accesscontrol.py
  24. +40 −3 tests/src/python/test_qgsserver_projectutils.py
  25. +458 −0 tests/src/python/test_qgsserver_wms.py
  26. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Annotations/WMS_GetMap_Annotations.png
  27. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Annotations/WMS_GetMap_Annotations_mask.png
  28. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic2/WMS_GetMap_Basic2.png
  29. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic2/WMS_GetMap_Basic2_mask.png
  30. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic3/WMS_GetMap_Basic3.png
  31. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic3/WMS_GetMap_Basic3_mask.png
  32. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic4/WMS_GetMap_Basic4.png
  33. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Basic4/WMS_GetMap_Basic4_mask.png
  34. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Diagrams/WMS_GetMap_Diagrams.png
  35. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Diagrams/WMS_GetMap_Diagrams_mask.png
  36. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter2/WMS_GetMap_Filter2.png
  37. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter2/WMS_GetMap_Filter2_mask.png
  38. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter3/WMS_GetMap_Filter3.png
  39. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Filter3/WMS_GetMap_Filter3_mask.png
  40. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Highlight/WMS_GetMap_Highlight.png
  41. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Highlight/WMS_GetMap_Highlight_mask.png
  42. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Opacities/WMS_GetMap_Opacities.png
  43. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_Opacities2/WMS_GetMap_Opacities2.png
  44. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_SLD/WMS_GetMap_SLD.png
  45. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_SLDRestored/WMS_GetMap_SLDRestored.png
  46. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_SLDRestored/WMS_GetMap_SLDRestored_mask.png
  47. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_StyleCustom/WMS_GetMap_StyleCustom_mask.png
  48. BIN tests/testdata/control_images/qgis_server/WMS_GetMap_StyleDefault/WMS_GetMap_StyleDefault_mask.png
  49. BIN ...ata/control_images/qgis_server_accesscontrol/Restricted_WMS_GetMap/Restricted_WMS_GetMap_mask.png
  50. BIN ...esscontrol/Restricted_WMS_GetMap_projectsubstring/Restricted_WMS_GetMap_projectsubstring_mask.png
  51. BIN tests/testdata/control_images/qgis_server_accesscontrol/WMS_GetMap/WMS_GetMap_mask.png
  52. BIN ...images/qgis_server_accesscontrol/WMS_GetMap_projectsubstring/WMS_GetMap_projectsubstring_mask.png
  53. BIN tests/testdata/qgis_server_accesscontrol/_helloworld.db
  54. BIN tests/testdata/qgis_server_accesscontrol/helloworld.db
  55. +1,430 −714 tests/testdata/qgis_server_accesscontrol/project.qgs
  56. +3,850 −0 tests/testdata/qgis_server_accesscontrol/project_state.qgs
  57. +4,199 −0 tests/testdata/qgis_server_accesscontrol/project_use_layerids.qgs
  58. +3,935 −0 tests/testdata/qgis_server_accesscontrol/project_with_annotations.qgs
  59. +1,117 −75 tests/testdata/qgis_server_project/project.qgs
  60. +269 −0 tests/testdata/qgis_server_project/project2.qgs
@@ -460,6 +460,7 @@ Convenience function to query topological editing status
:rtype: QgsAnnotationManager
%End


void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
%Docstring
Set a list of layers which should not be taken into account on map identification
@@ -84,11 +84,18 @@ class QgsServerProjectParser

/** Returns the text of the <layername> element for a layer element
@return name or a null string in case of error*/
QString layerName( const QDomElement &layerElem ) const;
// QString layerName( const QDomElement &layerElem ) const;

QStringList wfsLayers() const;
QStringList wcsLayers() const;

/** Gets a list containing names of layers. If a layer has a short name,
* then it's used instead of it's name.
* \returns A list of layers' names or short name if defined
* \since QGIS 3.0
*/
QStringList layersNames() const;

//! Add layers for vector joins
void addJoinLayersForElement( const QDomElement &layerElem ) const;

@@ -101,10 +108,6 @@ class QgsServerProjectParser
@return id or a null string in case of error*/
QString layerId( const QDomElement &layerElem ) const;

/** Returns the text of the <id> element for a layer element
@return id or a null string in case of error*/
QString layerShortName( const QDomElement &layerElem ) const;

QgsRectangle projectExtent() const;

int numberOfLayers() const;
@@ -1980,6 +1980,11 @@ QgsAnnotationManager *QgsProject::annotationManager()
return mAnnotationManager.get();
}

const QgsAnnotationManager *QgsProject::annotationManager() const
{
return mAnnotationManager.get();
}

void QgsProject::setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers )
{
QStringList currentLayers = nonIdentifiableLayers();
@@ -419,6 +419,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
QgsAnnotationManager *annotationManager();

/**
* Returns a const pointer to the project's annotation manager.
* \since QGIS 3.0
*/
const QgsAnnotationManager *annotationManager() const SIP_SKIP;

/**
* Set a list of layers which should not be taken into account on map identification
*/
@@ -40,6 +40,20 @@ QgsConfigCache::QgsConfigCache()
QObject::connect( &mFileSystemWatcher, &QFileSystemWatcher::fileChanged, this, &QgsConfigCache::removeChangedEntry );
}

const QgsProject *QgsConfigCache::project( const QString &path )
{
if ( ! mProjectCache[ path ] )
{
std::unique_ptr<QgsProject> prj( new QgsProject() );
if ( prj->read( path ) )
{
mProjectCache.insert( path, prj.release() );
}
}

return mProjectCache[ path ];
}

QgsServerProjectParser *QgsConfigCache::serverConfiguration( const QString &filePath )
{
QgsMessageLog::logMessage(
@@ -31,6 +31,7 @@

class QgsServerProjectParser;
class QgsAccessControl;
class QgsProject;

class SERVER_EXPORT QgsConfigCache : public QObject
{
@@ -47,6 +48,14 @@ class SERVER_EXPORT QgsConfigCache : public QObject

void removeEntry( const QString &path );

/** If the project is not cached yet, then the project is read thank to the
* path. If the project is not available, then a nullptr is returned.
* \param path the filename of the QGIS project
* \returns the project or nullptr if an error happened
* \since QGIS 3.0
*/
const QgsProject *project( const QString &path );

private:
QgsConfigCache();

@@ -58,6 +67,7 @@ class SERVER_EXPORT QgsConfigCache : public QObject

QCache<QString, QDomDocument> mXmlDocumentCache;
QCache<QString, QgsWmsConfigParser> mWMSConfigCache;
QCache<QString, QgsProject> mProjectCache;

private slots:
//! Removes changed entry from this cache
@@ -40,8 +40,32 @@ void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccess
}
if ( !layer->subsetString().isEmpty() )
{
sql.prepend( " AND " );
sql.prepend( ") AND (" );
sql.append( ")" );
sql.prepend( layer->subsetString() );
sql.prepend( "(" );
}
if ( !layer->setSubsetString( sql ) )
{
QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
}
}
}
}

void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccessControl *accessControl, QgsMapLayer *mapLayer )
{
if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
{
QString sql = accessControl->extraSubsetString( layer );
if ( !sql.isEmpty() )
{
if ( !layer->subsetString().isEmpty() )
{
sql.prepend( ") AND (" );
sql.append( ")" );
sql.prepend( layer->subsetString() );
sql.prepend( "(" );
}
if ( !layer->setSubsetString( sql ) )
{
@@ -53,6 +53,13 @@ class SERVER_EXPORT QgsOWSServerFilterRestorer
static void applyAccessControlLayerFilters( const QgsAccessControl *accessControl, QgsMapLayer *mapLayer,
QHash<QgsMapLayer *, QString> &originalLayerFilters );

/** Applies filters from access control on layer.
* \param accessControl The access control instance
* \param mapLayer The layer on which the filter has to be applied
* \since QGIS 3.0
*/
static void applyAccessControlLayerFilters( const QgsAccessControl *accessControl, QgsMapLayer *mapLayer );

private:
const QgsAccessControl *mAccessControl = nullptr;
QHash<QgsMapLayer *, QString> mOriginalLayerFilters;
@@ -76,6 +76,7 @@ QgsServer::QgsServer( )
abort();
}
init();
mConfigCache = QgsConfigCache::instance();
}

QString &QgsServer::serverName()
@@ -353,20 +354,10 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
QString configFilePath = configPath( *sConfigFilePath, parameterMap );

// load the project if needed and not empty
auto projectIt = mProjectRegistry.find( configFilePath );
if ( projectIt == mProjectRegistry.constEnd() )
const QgsProject *project = mConfigCache->project( configFilePath );
if ( ! project )
{
// load the project
QgsProject *project = new QgsProject();
project->setFileName( configFilePath );
if ( project->read() )
{
projectIt = mProjectRegistry.insert( configFilePath, project );
}
else
{
throw QgsServerException( QStringLiteral( "Project file error" ) );
}
throw QgsServerException( QStringLiteral( "Project file error" ) );
}

sServerInterface->setConfigFilePath( configFilePath );
@@ -397,7 +388,7 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
QgsService *service = sServiceRegistry.getService( serviceString, versionString );
if ( service )
{
service->executeRequest( request, responseDecorator, projectIt.value() );
service->executeRequest( request, responseDecorator, project );
}
else
{
@@ -124,8 +124,8 @@ class SERVER_EXPORT QgsServer

static QgsServerSettings sSettings;

// map of QgsProject
QMap<QString, const QgsProject *> mProjectRegistry;
//! cache
QgsConfigCache *mConfigCache;
};
#endif // QGSSERVER_H

0 comments on commit df9ee6f

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