Skip to content

Commit

Permalink
Merge pull request #4313 from pblottiere/cleansingleton
Browse files Browse the repository at this point in the history
[Server] WMS getmap refactoring
  • Loading branch information
rldhont authored Jun 1, 2017
2 parents e9a7dff + e663d19 commit df9ee6f
Show file tree
Hide file tree
Showing 60 changed files with 17,275 additions and 1,112 deletions.
1 change: 1 addition & 0 deletions python/core/qgsproject.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions python/server/qgsserverprojectparser.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
14 changes: 14 additions & 0 deletions src/server/qgsconfigcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions src/server/qgsconfigcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

class QgsServerProjectParser;
class QgsAccessControl;
class QgsProject;

class SERVER_EXPORT QgsConfigCache : public QObject
{
Expand All @@ -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();

Expand All @@ -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
Expand Down
26 changes: 25 additions & 1 deletion src/server/qgsfilterrestorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
{
Expand Down
7 changes: 7 additions & 0 deletions src/server/qgsfilterrestorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 5 additions & 14 deletions src/server/qgsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ QgsServer::QgsServer( )
abort();
}
init();
mConfigCache = QgsConfigCache::instance();
}

QString &QgsServer::serverName()
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Loading

0 comments on commit df9ee6f

Please sign in to comment.