Skip to content
Permalink
Browse files

Fix check of allowed wfst capabilities in project. Funded by Sourcepo…

…le QGIS Enterprise
  • Loading branch information
mhugent authored and rldhont committed Sep 2, 2014
1 parent 17669b5 commit 2313be90417301460574536c5e5dd1294ffa439a
@@ -69,9 +69,9 @@ void QgsWFSProjectParser::featureTypeList( QDomElement& parentElement, QDomDocum
}

QStringList wfsLayersId = mProjectParser.wfsLayers();
QStringList wfstUpdateLayersId = wfstUpdateLayers();
QStringList wfstInsertLayersId = wfstInsertLayers();
QStringList wfstDeleteLayersId = wfstDeleteLayers();
QSet<QString> wfstUpdateLayersId = wfstUpdateLayers();
QSet<QString> wfstInsertLayersId = wfstInsertLayers();
QSet<QString> wfstDeleteLayersId = wfstDeleteLayers();

QMap<QString, QgsMapLayer *> layerMap;

@@ -199,10 +199,10 @@ void QgsWFSProjectParser::featureTypeList( QDomElement& parentElement, QDomDocum
return;
}

QStringList QgsWFSProjectParser::wfstUpdateLayers() const
QSet<QString> QgsWFSProjectParser::wfstUpdateLayers() const
{
QStringList publiedIds = mProjectParser.wfsLayers();
QStringList wfsList;
QSet<QString> wfsList;
if ( !mProjectParser.xmlDocument() )
{
return wfsList;
@@ -228,15 +228,17 @@ QStringList QgsWFSProjectParser::wfstUpdateLayers() const
{
QString id = valueList.at( i ).toElement().text();
if ( publiedIds.contains( id ) )
wfsList << id;
{
wfsList.insert( id );
}
}
return wfsList;
}

QStringList QgsWFSProjectParser::wfstInsertLayers() const
QSet<QString> QgsWFSProjectParser::wfstInsertLayers() const
{
QStringList updateIds = wfstUpdateLayers();
QStringList wfsList;
QSet<QString> updateIds = wfstUpdateLayers();
QSet<QString> wfsList;
if ( !mProjectParser.xmlDocument() )
{
return wfsList;
@@ -262,15 +264,17 @@ QStringList QgsWFSProjectParser::wfstInsertLayers() const
{
QString id = valueList.at( i ).toElement().text();
if ( updateIds.contains( id ) )
wfsList << id;
{
wfsList.insert( id );
}
}
return wfsList;
}

QStringList QgsWFSProjectParser::wfstDeleteLayers() const
QSet<QString> QgsWFSProjectParser::wfstDeleteLayers() const
{
QStringList insertIds = wfstInsertLayers();
QStringList wfsList;
QSet<QString> insertIds = wfstInsertLayers();
QSet<QString> wfsList;
if ( !mProjectParser.xmlDocument() )
{
return wfsList;
@@ -296,7 +300,9 @@ QStringList QgsWFSProjectParser::wfstDeleteLayers() const
{
QString id = valueList.at( i ).toElement().text();
if ( insertIds.contains( id ) )
wfsList << id;
{
wfsList.insert( id );
}
}
return wfsList;
}
@@ -38,12 +38,12 @@ class QgsWFSProjectParser

QList<QgsMapLayer*> mapLayerFromTypeName( const QString& aTypeName, bool useCache = true ) const;

QSet<QString> wfstUpdateLayers() const;
QSet<QString> wfstInsertLayers() const;
QSet<QString> wfstDeleteLayers() const;

private:
QgsServerProjectParser mProjectParser;

QStringList wfstUpdateLayers() const;
QStringList wfstInsertLayers() const;
QStringList wfstDeleteLayers() const;
};

#endif // QGSWFSPROJECTPARSER_H
@@ -23,6 +23,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgsmaptopixel.h"
#include "qgsmessagelog.h"
#include "qgspallabeling.h"
#include "qgsproject.h"
#include "qgsrasterlayer.h"
@@ -1382,6 +1383,15 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
QDomNodeList upNodeList = typeNameElem.elementsByTagNameNS( WFS_NAMESPACE, "Update" );
for ( int j = 0; j < upNodeList.count(); ++j )
{
if ( !mConfigParser->wfstUpdateLayers().contains( layer->id() ) )
{
//no wfs permissions to do updates
QString errorMsg = "No permissions to do WFS updates on layer '" + layer->name() + "'";
QgsMessageLog::logMessage( errorMsg, "Server", QgsMessageLog::CRITICAL );
addTransactionResult( resp, respElem, "FAILED", "Update", errorMsg );
return resp;
}

actionElem = upNodeList.at( j ).toElement();

// Get the Feature Ids for this filter on the layer
@@ -1451,22 +1461,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
// Commit the changes of the update elements
if ( !layer->commitChanges() )
{
QgsDebugMsg( QString( "update errors:\n %1" ).arg( layer->commitErrors().join( "\n " ) ) );
QDomElement trElem = doc.createElement( "TransactionResult" );
QDomElement stElem = doc.createElement( "Status" );
QDomElement successElem = doc.createElement( "PARTIAL" );
stElem.appendChild( successElem );
trElem.appendChild( stElem );
respElem.appendChild( trElem );

QDomElement locElem = doc.createElement( "Locator" );
locElem.appendChild( doc.createTextNode( "Update" ) );
trElem.appendChild( locElem );

QDomElement mesElem = doc.createElement( "Message" );
mesElem.appendChild( doc.createTextNode( layer->commitErrors().join( "\n " ) ) );
trElem.appendChild( mesElem );

addTransactionResult( resp, respElem, "PARTIAL", "Update", layer->commitErrors().join( "\n " ) );
return resp;
}
// Start the delete transaction
@@ -1477,6 +1472,15 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
QDomNodeList delNodeList = typeNameElem.elementsByTagNameNS( WFS_NAMESPACE, "Delete" );
for ( int j = 0; j < delNodeList.count(); ++j )
{
if ( !mConfigParser->wfstDeleteLayers().contains( layer->id() ) )
{
//no wfs permissions to do updates
QString errorMsg = "No permissions to do WFS deletes on layer '" + layer->name() + "'";
QgsMessageLog::logMessage( errorMsg, "Server", QgsMessageLog::CRITICAL );
addTransactionResult( resp, respElem, "FAILED", "Delete", errorMsg );
return resp;
}

actionElem = delNodeList.at( j ).toElement();
QDomElement filterElem = actionElem.firstChild().toElement();
// Get Feature Ids for the Filter element
@@ -1488,22 +1492,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
// Commit the changes of the delete elements
if ( !layer->commitChanges() )
{
QgsDebugMsg( QString( "delete errors:\n %1" ).arg( layer->commitErrors().join( "\n " ) ) );
QDomElement trElem = doc.createElement( "TransactionResult" );
QDomElement stElem = doc.createElement( "Status" );
QDomElement successElem = doc.createElement( "PARTIAL" );
stElem.appendChild( successElem );
trElem.appendChild( stElem );
respElem.appendChild( trElem );

QDomElement locElem = doc.createElement( "Locator" );
locElem.appendChild( doc.createTextNode( "Delete" ) );
trElem.appendChild( locElem );

QDomElement mesElem = doc.createElement( "Message" );
mesElem.appendChild( doc.createTextNode( layer->commitErrors().join( "\n " ) ) );
trElem.appendChild( mesElem );

addTransactionResult( resp, respElem, "PARTIAL", "Delete", layer->commitErrors().join( "\n " ) );
return resp;
}

@@ -1521,6 +1510,15 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
QDomNodeList inNodeList = typeNameElem.elementsByTagNameNS( WFS_NAMESPACE, "Insert" );
for ( int j = 0; j < inNodeList.count(); ++j )
{
if ( !mConfigParser->wfstInsertLayers().contains( layer->id() ) )
{
//no wfs permissions to do updates
QString errorMsg = "No permissions to do WFS inserts on layer '" + layer->name() + "'";
QgsMessageLog::logMessage( errorMsg, "Server", QgsMessageLog::CRITICAL );
addTransactionResult( resp, respElem, "FAILED", "Insert", errorMsg );
return resp;
}

actionElem = inNodeList.at( j ).toElement();
// Loop through the feature element
QDomNodeList featNodes = actionElem.childNodes();
@@ -1573,33 +1571,11 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
// add the features
if ( !provider->addFeatures( inFeatList ) )
{
QDomElement trElem = doc.createElement( "TransactionResult" );
QDomElement stElem = doc.createElement( "Status" );
QDomElement successElem = doc.createElement( "PARTIAL" );
stElem.appendChild( successElem );
trElem.appendChild( stElem );
respElem.appendChild( trElem );

QDomElement locElem = doc.createElement( "Locator" );
locElem.appendChild( doc.createTextNode( "Insert" ) );
trElem.appendChild( locElem );

QDomElement mesElem = doc.createElement( "Message" );
QStringList mesErrors;
mesErrors << QString( "ERROR: %1 feature(s) not added." ).arg( inFeatList.size() );
addTransactionResult( resp, respElem, "Partial", "Insert", layer->commitErrors().join( "\n " ) );
if ( provider->hasErrors() )
{
mesErrors << "\n Provider errors:" << provider->errors();
provider->clearErrors();
}
else
{
mesErrors << "\n Provider didn't report any errors:";
}
QgsDebugMsg( QString( "add errors:\n %1" ).arg( mesErrors.join( "\n " ) ) );
mesElem.appendChild( doc.createTextNode( mesErrors.join( "\n " ) ) );
trElem.appendChild( mesElem );

return resp;
}
// Get the Feature Ids of the inserted feature
@@ -1918,3 +1894,21 @@ QString QgsWFSServer::serviceUrl() const
}
return mapUrl.toString();
}

void QgsWFSServer::addTransactionResult( QDomDocument& responseDoc, QDomElement& responseElem, const QString& status, const QString& locator, const QString& message )
{
QDomElement trElem = responseDoc.createElement( "TransactionResult" );
QDomElement stElem = responseDoc.createElement( "Status" );
QDomElement successElem = responseDoc.createElement( status );
stElem.appendChild( successElem );
trElem.appendChild( stElem );
responseElem.appendChild( trElem );

QDomElement locElem = responseDoc.createElement( "Locator" );
locElem.appendChild( responseDoc.createTextNode( locator ) );
trElem.appendChild( locElem );

QDomElement mesElem = responseDoc.createElement( "Message" );
mesElem.appendChild( responseDoc.createTextNode( message ) );
trElem.appendChild( mesElem );
}
@@ -118,6 +118,8 @@ class QgsWFSServer: public QgsOWSServer

//methods to write GML3
QDomElement createFeatureGML3( QgsFeature* feat, QDomDocument& doc, int prec, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/;

void addTransactionResult( QDomDocument& responseDoc, QDomElement& responseElem, const QString& status, const QString& locator, const QString& message );
};

#endif

0 comments on commit 2313be9

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