Skip to content

Commit

Permalink
Merge pull request #40185 from elpaso/server-landingpage-project-from…
Browse files Browse the repository at this point in the history
…-cache

Server landing page: use cached projects
  • Loading branch information
elpaso committed Nov 19, 2020
2 parents 83aa68f + 1cc55f9 commit c7bdc47
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 116 deletions.
2 changes: 1 addition & 1 deletion python/server/auto_generated/qgsconfigcache.sip.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Removes an entry from cache.
:param path: The path of the project :param path: The path of the project
%End %End


const QgsProject *project( const QString &path, QgsServerSettings *settings = 0 ); const QgsProject *project( const QString &path, const QgsServerSettings *settings = 0 );
%Docstring %Docstring
If the project is not cached yet, then the project is read from the If the project is not cached yet, then the project is read from the
path. If the project is not available, then ``None`` is returned. path. If the project is not available, then ``None`` is returned.
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsconfigcache.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ QgsConfigCache::QgsConfigCache()
} }




const QgsProject *QgsConfigCache::project( const QString &path, QgsServerSettings *settings ) const QgsProject *QgsConfigCache::project( const QString &path, const QgsServerSettings *settings )
{ {
if ( ! mProjectCache[ path ] ) if ( ! mProjectCache[ path ] )
{ {
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsconfigcache.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SERVER_EXPORT QgsConfigCache : public QObject
* \returns the project or NULLPTR if an error happened * \returns the project or NULLPTR if an error happened
* \since QGIS 3.0 * \since QGIS 3.0
*/ */
const QgsProject *project( const QString &path, QgsServerSettings *settings = nullptr ); const QgsProject *project( const QString &path, const QgsServerSettings *settings = nullptr );


private: private:
QgsConfigCache() SIP_FORCE; QgsConfigCache() SIP_FORCE;
Expand Down
13 changes: 12 additions & 1 deletion src/server/qgsserver.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
QString configFilePath = configPath( *sConfigFilePath, params.map() ); QString configFilePath = configPath( *sConfigFilePath, params.map() );


// load the project if needed and not empty // load the project if needed and not empty
project = mConfigCache->project( configFilePath, sServerInterface->serverSettings() ); if ( ! configFilePath.isEmpty() )
{
project = mConfigCache->project( configFilePath, sServerInterface->serverSettings() );
}
} }


// Set the current project instance // Set the current project instance
Expand All @@ -380,6 +383,14 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
{ {
sServerInterface->setConfigFilePath( project->fileName() ); sServerInterface->setConfigFilePath( project->fileName() );
} }
else
{
sServerInterface->setConfigFilePath( QString() );
}

// Note that at this point we still might not have set a valid project.
// There are APIs that work without a project (e.g. the landing page catalog API that
// lists the available projects metadata).


// Dispatcher: if SERVICE is set, we assume a OWS service, if not, let's try an API // Dispatcher: if SERVICE is set, we assume a OWS service, if not, let's try an API
// TODO: QGIS 4 fix the OWS services and treat them as APIs // TODO: QGIS 4 fix the OWS services and treat them as APIs
Expand Down
3 changes: 1 addition & 2 deletions src/server/services/landingpage/qgslandingpagehandlers.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "qgslandingpageutils.h" #include "qgslandingpageutils.h"
#include "qgsserverinterface.h" #include "qgsserverinterface.h"
#include "qgsserverresponse.h" #include "qgsserverresponse.h"
#include "qgsproject.h"
#include "qgsserverprojectutils.h" #include "qgsserverprojectutils.h"
#include "qgsvectorlayer.h" #include "qgsvectorlayer.h"
#include "qgslayertreenode.h" #include "qgslayertreenode.h"
Expand Down Expand Up @@ -91,7 +90,7 @@ void QgsLandingPageMapHandler::handleRequest( const QgsServerApiContext &context
{ {
throw QgsServerApiNotFoundError( QStringLiteral( "Requested project hash not found!" ) ); throw QgsServerApiNotFoundError( QStringLiteral( "Requested project hash not found!" ) );
} }
data[ "project" ] = QgsLandingPageUtils::projectInfo( projectPath ); data[ "project" ] = QgsLandingPageUtils::projectInfo( projectPath, mSettings );
write( data, context, {{ "pageTitle", linkTitle() }, { "navigation", json::array() }} ); write( data, context, {{ "pageTitle", linkTitle() }, { "navigation", json::array() }} );
} }


228 changes: 120 additions & 108 deletions src/server/services/landingpage/qgslandingpageutils.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/server/services/landingpage/qgslandingpageutils.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ struct QgsLandingPageUtils
static QMap<QString, QString> projects( const QgsServerSettings &settings ); static QMap<QString, QString> projects( const QgsServerSettings &settings );


/** /**
* Returns project information for a given \a projectPath * Returns project information for a given \a projectPath and optional \a serverSettings
*/ */
static json projectInfo( const QString &projectPath ); static json projectInfo( const QString &projectPath, const QgsServerSettings *serverSettings = nullptr );


/** /**
* Returns the layer tree information for the given \a project * Returns the layer tree information for the given \a project
Expand Down

0 comments on commit c7bdc47

Please sign in to comment.