Skip to content

Commit

Permalink
[Server][WFS] Update Transaction 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Oct 12, 2017
1 parent 24a6854 commit 1558b03
Show file tree
Hide file tree
Showing 7 changed files with 1,462 additions and 77 deletions.
1 change: 1 addition & 0 deletions src/server/services/wfs/CMakeLists.txt
Expand Up @@ -10,6 +10,7 @@ SET (wfs_SRCS
qgswfsdescribefeaturetype.cpp
qgswfsgetfeature.cpp
qgswfstransaction.cpp
qgswfstransaction_1_0_0.cpp
qgswfsparameters.cpp
)

Expand Down
11 changes: 10 additions & 1 deletion src/server/services/wfs/qgswfs.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgswfsgetfeature.h"
#include "qgswfsdescribefeaturetype.h"
#include "qgswfstransaction.h"
#include "qgswfstransaction_1_0_0.h"

#define QSTR_COMPARE( str, lit )\
(str.compare( QStringLiteral( lit ), Qt::CaseInsensitive ) == 0)
Expand Down Expand Up @@ -92,7 +93,15 @@ namespace QgsWfs
}
else if ( QSTR_COMPARE( req, "Transaction" ) )
{
writeTransaction( mServerIface, project, versionString, request, response );
// Supports WFS 1.0.0
if ( QSTR_COMPARE( versionString, "1.0.0" ) )
{
v1_0_0::writeTransaction( mServerIface, project, versionString, request, response );
}
else
{
writeTransaction( mServerIface, project, versionString, request, response );
}
}
else
{
Expand Down
163 changes: 88 additions & 75 deletions src/server/services/wfs/qgswfstransaction.cpp
Expand Up @@ -36,7 +36,7 @@ namespace QgsWfs
{
namespace
{
void addTransactionResult( QDomDocument &responseDoc, QDomElement &responseElem, const QString &status,
void addTransactionResult( QDomDocument &responseDoc, QDomElement &resultsElem,
const QString &locator, const QString &message );
}

Expand Down Expand Up @@ -84,110 +84,125 @@ namespace QgsWfs
// It's time to make the transaction
// Create the response document
QDomDocument resp;
//wfs:WFS_TransactionRespone element
QDomElement respElem = resp.createElement( QStringLiteral( "WFS_TransactionResponse" )/*wfs:WFS_TransactionResponse*/ );
//wfs:TransactionRespone element
QDomElement respElem = resp.createElement( QStringLiteral( "TransactionResponse" )/*wfs:TransactionResponse*/ );
respElem.setAttribute( QStringLiteral( "xmlns" ), WFS_NAMESPACE );
respElem.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
respElem.setAttribute( QStringLiteral( "xsi:schemaLocation" ), WFS_NAMESPACE + " http://schemas.opengis.net/wfs/1.0.0/wfs.xsd" );
respElem.setAttribute( QStringLiteral( "xsi:schemaLocation" ), WFS_NAMESPACE + " http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" );
respElem.setAttribute( QStringLiteral( "xmlns:ogc" ), OGC_NAMESPACE );
respElem.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0.0" ) );
respElem.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1.0" ) );
resp.appendChild( respElem );

int totalInserted = 0;
int totalUpdated = 0;
int totalDeleted = 0;
int errorCount = 0;
QStringList errorLocators;
QStringList errorMessages;

QList<transactionUpdate>::iterator tuIt = aRequest.updates.begin();
for ( ; tuIt != aRequest.updates.end(); ++tuIt )
{
transactionUpdate &action = *tuIt;
if ( action.error )
{
errorCount += 1;
if ( action.handle.isEmpty() )
{
errorLocators << QStringLiteral( "Update:%1" ).arg( action.typeName );
}
else
{
errorLocators << action.handle;
}
errorMessages << action.errorMsg;
}
}

QList<transactionDelete>::iterator tdIt = aRequest.deletes.begin();
for ( ; tdIt != aRequest.deletes.end(); ++tdIt )
{
transactionDelete &action = *tdIt;
if ( action.error )
{
errorCount += 1;
if ( action.handle.isEmpty() )
{
errorLocators << QStringLiteral( "Delete:%1" ).arg( action.typeName );
}
else
{
errorLocators << action.handle;
}
errorMessages << action.errorMsg;
}
}
//wfs:TransactionResults element
QDomElement trsElem = doc.createElement( QStringLiteral( "TransactionResults" ) );

//wfs:InsertResults element
QDomElement irsElem = doc.createElement( QStringLiteral( "InsertResults" ) );
QList<transactionInsert>::iterator tiIt = aRequest.inserts.begin();
for ( ; tiIt != aRequest.inserts.end(); ++tiIt )
{
transactionInsert &action = *tiIt;
if ( action.error )
{
errorCount += 1;
if ( action.handle.isEmpty() )
{
errorLocators << QStringLiteral( "Insert:%1" ).arg( action.typeName );
}
else
QString locator = action.handle;
if ( locator.isEmpty() )
{
errorLocators << action.handle;
locator = QStringLiteral( "Insert:%1" ).arg( action.typeName );
}
errorMessages << action.errorMsg;
addTransactionResult( resp, trsElem, locator, action.errorMsg );
}
else
{
QStringList::const_iterator fidIt = action.insertFeatureIds.constBegin();
for ( ; fidIt != action.insertFeatureIds.constEnd(); ++fidIt )
{
QString fidStr = *fidIt;
QDomElement irElem = doc.createElement( QStringLiteral( "InsertResult" ) );
QDomElement irElem = doc.createElement( QStringLiteral( "Feature" ) );
if ( !action.handle.isEmpty() )
{
irElem.setAttribute( QStringLiteral( "handle" ), action.handle );
}
QDomElement fiElem = doc.createElement( QStringLiteral( "ogc:FeatureId" ) );
fiElem.setAttribute( QStringLiteral( "fid" ), fidStr );
irElem.appendChild( fiElem );
respElem.appendChild( irElem );
irsElem.appendChild( irElem );
}
}
totalInserted += action.insertFeatureIds.count();
}

// addTransactionResult
if ( errorCount == 0 )
{
addTransactionResult( resp, respElem, QStringLiteral( "SUCCESS" ), QString(), QString() );
}
else
QList<transactionUpdate>::iterator tuIt = aRequest.updates.begin();
for ( ; tuIt != aRequest.updates.end(); ++tuIt )
{
QString locator = errorLocators.join( QStringLiteral( "; " ) );
QString message = errorMessages.join( QStringLiteral( "; " ) );
if ( errorCount != actionCount )
transactionUpdate &action = *tuIt;
if ( action.error )
{
addTransactionResult( resp, respElem, QStringLiteral( "PARTIAL" ), locator, message );
errorCount += 1;
QString locator = action.handle;
if ( locator.isEmpty() )
{
locator = QStringLiteral( "Update:%1" ).arg( action.typeName );
}
addTransactionResult( resp, trsElem, locator, action.errorMsg );
}
else
totalUpdated += action.totalUpdated;
}

QList<transactionDelete>::iterator tdIt = aRequest.deletes.begin();
for ( ; tdIt != aRequest.deletes.end(); ++tdIt )
{
transactionDelete &action = *tdIt;
if ( action.error )
{
addTransactionResult( resp, respElem, QStringLiteral( "ERROR" ), locator, message );
errorCount += 1;
QString locator = action.handle;
if ( locator.isEmpty() )
{
locator = QStringLiteral( "Delete:%1" ).arg( action.typeName );
}
addTransactionResult( resp, trsElem, locator, action.errorMsg );
}
totalDeleted += action.totalDeleted;
}

//wfs:TransactionSummary element
QDomElement summaryElem = doc.createElement( QStringLiteral( "TransactionSummary" ) );
if ( aRequest.inserts.size() > 0 )
{
QDomElement totalInsertedElem = doc.createElement( QStringLiteral( "TotalInserted" ) );
totalInsertedElem.appendChild( doc.createTextNode( QString::number( totalInserted ) ) );
summaryElem.appendChild( totalInsertedElem );
}
if ( aRequest.updates.size() > 0 )
{
QDomElement totalUpdatedElem = doc.createElement( QStringLiteral( "TotalUpdated" ) );
totalUpdatedElem.appendChild( doc.createTextNode( QString::number( totalUpdated ) ) );
summaryElem.appendChild( totalUpdatedElem );
}
if ( aRequest.deletes.size() > 0 )
{
QDomElement totalDeletedElem = doc.createElement( QStringLiteral( "TotalDeleted" ) );
totalDeletedElem.appendChild( doc.createTextNode( QString::number( totalDeleted ) ) );
summaryElem.appendChild( totalDeletedElem );
}
respElem.appendChild( summaryElem );

// add TransactionResults
if ( errorCount > 0 && trsElem.hasChildNodes() )
{
respElem.appendChild( trsElem );
}

// add InsertResults
if ( aRequest.inserts.size() > 0 && irsElem.hasChildNodes() )
{
respElem.appendChild( irsElem );
}
return resp;
}
Expand Down Expand Up @@ -356,6 +371,7 @@ namespace QgsWfs
// get iterator
QgsFeatureIterator fit = vlayer->getFeatures( featureRequest );
QgsFeature feature;
int totalUpdated = 0;
// get action properties
QMap<QString, QString> propertyMap = action.propertyMap;
QDomElement geometryElem = action.geometryElement;
Expand Down Expand Up @@ -433,6 +449,7 @@ namespace QgsWfs
break;
}
}
totalUpdated += 1;
}
if ( action.error )
{
Expand Down Expand Up @@ -467,6 +484,7 @@ namespace QgsWfs
continue;
}
// all the changes are OK!
action.totalUpdated = totalUpdated;
action.error = false;

}
Expand Down Expand Up @@ -564,6 +582,7 @@ namespace QgsWfs
continue;
}
// all the changes are OK!
action.totalDeleted = fids.count();
action.error = false;
}

Expand Down Expand Up @@ -1159,21 +1178,15 @@ namespace QgsWfs
namespace
{

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

if ( !locator.isEmpty() )
{
QDomElement locElem = responseDoc.createElement( QStringLiteral( "Locator" ) );
locElem.appendChild( responseDoc.createTextNode( locator ) );
trElem.appendChild( locElem );
trElem.setAttribute( QStringLiteral( "locator" ), locator );
}

if ( !message.isEmpty() )
Expand Down
4 changes: 4 additions & 0 deletions src/server/services/wfs/qgswfstransaction.h
Expand Up @@ -52,6 +52,8 @@ namespace QgsWfs

QgsFeatureRequest featureRequest;

int totalUpdated = 0;

bool error;

QString errorMsg;
Expand All @@ -65,6 +67,8 @@ namespace QgsWfs

QgsFeatureRequest featureRequest;

int totalDeleted = 0;

bool error;

QString errorMsg;
Expand Down

0 comments on commit 1558b03

Please sign in to comment.