Skip to content
Permalink
Browse files

Server: throw exception if one or more layers are not available. Proj…

…ects with missing layers are not cached, the layer may become available in future if e.g. the db connection has been temporarly interupted
  • Loading branch information
mhugent committed Jan 14, 2019
1 parent 3bc06e2 commit 4ea42fafbad6bd07c3154ad80647977ae7d0f3a0
@@ -40,6 +40,7 @@ SET(QGIS_SERVER_SRCS
qgsserviceregistry.cpp
qgsfeaturefilterprovidergroup.cpp
qgsfeaturefilter.cpp
qgsstorebadlayerinfo.cpp
)

SET (QGIS_SERVER_HDRS
@@ -17,6 +17,8 @@

#include "qgsconfigcache.h"
#include "qgsmessagelog.h"
#include "qgsserverexception.h"
#include "qgsstorebadlayerinfo.h"

#include <QFile>

@@ -40,8 +42,14 @@ const QgsProject *QgsConfigCache::project( const QString &path )
if ( ! mProjectCache[ path ] )
{
std::unique_ptr<QgsProject> prj( new QgsProject() );
QgsStoreBadLayerInfo *badLayerHandler = new QgsStoreBadLayerInfo();
prj->setBadLayerHandler( badLayerHandler );
if ( prj->read( path ) )
{
if ( badLayerHandler->badLayers().size() > 0 )
{
throw QgsServerException( QStringLiteral( "Layer(s) not valid" ) );
}
mProjectCache.insert( path, prj.release() );
mFileSystemWatcher.addPath( path );
}
@@ -0,0 +1,27 @@
#include "qgsstorebadlayerinfo.h"
#include <QDomElement>

QgsStoreBadLayerInfo::QgsStoreBadLayerInfo(): QgsProjectBadLayerHandler()
{
}

QgsStoreBadLayerInfo::~QgsStoreBadLayerInfo()
{
}

void QgsStoreBadLayerInfo::handleBadLayers( const QList<QDomNode> &layers )
{
mBadLayerIds.clear();
QList<QDomNode>::const_iterator it = layers.constBegin();
for ( ; it != layers.constEnd(); ++it )
{
if ( !it->isNull() )
{
QDomElement idElem = it->firstChildElement( "id" );
if ( !idElem.isNull() )
{
mBadLayerIds.append( idElem.text() );
}
}
}
}
@@ -0,0 +1,32 @@
#ifndef QGSSTOREBADLAYERINFO_H
#define QGSSTOREBADLAYERINFO_H

#include "qgsprojectbadlayerhandler.h"
#include <QStringList>

/**
* \ingroup server
* Stores layer ids of bad layers
*/
class QgsStoreBadLayerInfo: public QgsProjectBadLayerHandler
{
public:
QgsStoreBadLayerInfo();
~QgsStoreBadLayerInfo();
/**
* @brief handleBadLayers
* @param layers layer nodes
*/
void handleBadLayers( const QList<QDomNode> &layers );

/**
* @brief badLayers
* @return ids of bad layers
*/
QStringList badLayers() const { return mBadLayerIds; }

private:
QStringList mBadLayerIds;
};

#endif // QGSSTOREBADLAYERINFO_H

0 comments on commit 4ea42fa

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