Skip to content

Commit

Permalink
Merge pull request #7915 from rldhont/server-cache-manager-extension
Browse files Browse the repository at this point in the history
[Server][Cache] Finalizing the cache manager
  • Loading branch information
rldhont authored Oct 7, 2018
2 parents b247c7c + 3bb64a7 commit 2b71c9c
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 24 deletions.
28 changes: 26 additions & 2 deletions src/server/services/wcs/qgswcsdescribecoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,34 @@ namespace QgsWcs
void writeDescribeCoverage( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QDomDocument doc = createDescribeCoverageDocument( serverIface, project, version, request );
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *describeDocument = nullptr;

QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
describeDocument = &doc;
}
else //describe feature xml not in cache. Create a new one
{
doc = createDescribeCoverageDocument( serverIface, project, version, request );

if ( cacheManager )
{
cacheManager->setCachedDocument( &doc, project, request, accessControl );
}
describeDocument = &doc;
}

response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
response.write( doc.toByteArray() );
response.write( describeDocument->toByteArray() );
}


Expand Down
11 changes: 8 additions & 3 deletions src/server/services/wcs/qgswcsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ namespace QgsWcs
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand Down
28 changes: 26 additions & 2 deletions src/server/services/wfs/qgswfsdescribefeaturetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,34 @@ namespace QgsWfs
void writeDescribeFeatureType( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QDomDocument doc = createDescribeFeatureTypeDocument( serverIface, project, version, request );
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *describeDocument = nullptr;

QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
describeDocument = &doc;
}
else //describe feature xml not in cache. Create a new one
{
doc = createDescribeFeatureTypeDocument( serverIface, project, version, request );

if ( cacheManager )
{
cacheManager->setCachedDocument( &doc, project, request, accessControl );
}
describeDocument = &doc;
}

response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
response.write( doc.toByteArray() );
response.write( describeDocument->toByteArray() );
}


Expand Down
11 changes: 8 additions & 3 deletions src/server/services/wfs/qgswfsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ namespace QgsWfs
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand Down
11 changes: 8 additions & 3 deletions src/server/services/wfs/qgswfsgetcapabilities_1_0_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ namespace QgsWfs
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand Down
10 changes: 8 additions & 2 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ namespace QgsWms
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response, bool projectSettings )
{
QgsAccessControl *accessControl = serverIface->accessControls();
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif

QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;
Expand All @@ -110,7 +113,10 @@ namespace QgsWms
cache = accessControl->fillCacheKey( cacheKeyList );
QString cacheKey = cacheKeyList.join( '-' );

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand Down
29 changes: 27 additions & 2 deletions src/server/services/wms/qgswmsgetcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,35 @@ namespace QgsWms
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response )
{
QDomDocument doc = getContext( serverIface, project, version, request );
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif

QDomDocument doc;
const QDomDocument *contextDocument = nullptr;

QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
contextDocument = &doc;
}
else //context xml not in cache. Create a new one
{
doc = getContext( serverIface, project, version, request );

if ( cacheManager )
{
cacheManager->setCachedDocument( &doc, project, request, accessControl );
}
contextDocument = &doc;
}

response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
response.write( doc.toByteArray() );
response.write( contextDocument->toByteArray() );
}


Expand Down
50 changes: 49 additions & 1 deletion src/server/services/wms/qgswmsgetlegendgraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,64 @@ namespace QgsWms
Q_UNUSED( version );

QgsServerRequest::Parameters params = request.parameters();
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );

// Get cached image
QgsAccessControl *accessControl = nullptr;
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager )
{
ImageOutputFormat outputFormat = parseImageFormat( format );
QString saveFormat;
QString contentType;
switch ( outputFormat )
{
case PNG:
case PNG8:
case PNG16:
case PNG1:
contentType = "image/png";
saveFormat = "PNG";
break;
case JPEG:
contentType = "image/jpeg";
saveFormat = "JPEG";
break;
default:
throw QgsServiceException( "InvalidFormat",
QString( "Output format '%1' is not supported in the GetLegendGraphic request" ).arg( format ) );
break;
}

QImage image;
QByteArray content = cacheManager->getCachedImage( project, request, accessControl );
if ( !content.isEmpty() && image.loadFromData( content ) )
{
response.setHeader( QStringLiteral( "Content-Type" ), contentType );
image.save( response.io(), qPrintable( saveFormat ) );
return;
}
}

QgsRenderer renderer( serverIface, project, wmsParameters );

std::unique_ptr<QImage> result( renderer.getLegendGraphics() );

if ( result )
{
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
writeImage( response, *result, format, renderer.getImageQuality() );
if ( cacheManager )
{
QByteArray content = response.data();
if ( !content.isEmpty() )
cacheManager->setCachedImage( &content, project, request, accessControl );
}
}
else
{
Expand Down
11 changes: 8 additions & 3 deletions src/server/services/wmts/qgswmtsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ namespace QgsWmts
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
Expand Down
8 changes: 6 additions & 2 deletions src/server/services/wmts/qgswmtsgettile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ namespace QgsWmts
QUrlQuery query = translateWmtsParamToWmsQueryItem( QStringLiteral( "GetMap" ), params, project, serverIface );

// Get cached image
QgsAccessControl *accessControl = serverIface->accessControls();
QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsAccessControl *accessControl = nullptr;
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager )
{
QgsWmtsParameters::Format f = params.format();
Expand Down
Loading

0 comments on commit 2b71c9c

Please sign in to comment.