41#include <QRegularExpression>
42#include <QRegularExpressionMatch>
45using namespace Qt::StringLiterals;
51 void addTransactionResult( QDomDocument &responseDoc, QDomElement &resultsElem,
const QString &locator,
const QString &message );
60 response.
setHeader(
"Content-Type",
"text/xml; charset=utf-8" );
61 response.
write( doc.toByteArray() );
74 if ( doc.setContent( request.
data(),
true, &errorMsg ) )
76 QDomElement docElem = doc.documentElement();
85 if ( actionCount == 0 )
96 QDomElement respElem = resp.createElement( u
"TransactionResponse"_s );
98 respElem.setAttribute( u
"xmlns:xsi"_s, u
"http://www.w3.org/2001/XMLSchema-instance"_s );
99 respElem.setAttribute( u
"xsi:schemaLocation"_s,
WFS_NAMESPACE +
" http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" );
101 respElem.setAttribute( u
"version"_s, u
"1.1.0"_s );
102 resp.appendChild( respElem );
104 int totalInserted = 0;
105 int totalUpdated = 0;
106 int totalDeleted = 0;
110 QDomElement trsElem = doc.createElement( u
"TransactionResults"_s );
113 QDomElement irsElem = doc.createElement( u
"InsertResults"_s );
114 QList<transactionInsert>::iterator tiIt = aRequest.
inserts.begin();
115 for ( ; tiIt != aRequest.
inserts.end(); ++tiIt )
121 QString locator = action.
handle;
122 if ( locator.isEmpty() )
124 locator = u
"Insert:%1"_s.arg( action.
typeName );
126 addTransactionResult( resp, trsElem, locator, action.
errorMsg );
133 QString fidStr = *fidIt;
134 QDomElement irElem = doc.createElement( u
"Feature"_s );
135 if ( !action.
handle.isEmpty() )
137 irElem.setAttribute( u
"handle"_s, action.
handle );
139 QDomElement fiElem = doc.createElement( u
"ogc:FeatureId"_s );
140 fiElem.setAttribute( u
"fid"_s, fidStr );
141 irElem.appendChild( fiElem );
142 irsElem.appendChild( irElem );
148 QList<transactionUpdate>::iterator tuIt = aRequest.
updates.begin();
149 for ( ; tuIt != aRequest.
updates.end(); ++tuIt )
155 QString locator = action.
handle;
156 if ( locator.isEmpty() )
158 locator = u
"Update:%1"_s.arg( action.
typeName );
160 addTransactionResult( resp, trsElem, locator, action.
errorMsg );
165 QList<transactionDelete>::iterator tdIt = aRequest.
deletes.begin();
166 for ( ; tdIt != aRequest.
deletes.end(); ++tdIt )
172 QString locator = action.
handle;
173 if ( locator.isEmpty() )
175 locator = u
"Delete:%1"_s.arg( action.
typeName );
177 addTransactionResult( resp, trsElem, locator, action.
errorMsg );
183 QDomElement summaryElem = doc.createElement( u
"TransactionSummary"_s );
184 if ( aRequest.
inserts.size() > 0 )
186 QDomElement totalInsertedElem = doc.createElement( u
"totalInserted"_s );
187 totalInsertedElem.appendChild( doc.createTextNode( QString::number( totalInserted ) ) );
188 summaryElem.appendChild( totalInsertedElem );
190 if ( aRequest.
updates.size() > 0 )
192 QDomElement totalUpdatedElem = doc.createElement( u
"totalUpdated"_s );
193 totalUpdatedElem.appendChild( doc.createTextNode( QString::number( totalUpdated ) ) );
194 summaryElem.appendChild( totalUpdatedElem );
196 if ( aRequest.
deletes.size() > 0 )
198 QDomElement totalDeletedElem = doc.createElement( u
"totalDeleted"_s );
199 totalDeletedElem.appendChild( doc.createTextNode( QString::number( totalDeleted ) ) );
200 summaryElem.appendChild( totalDeletedElem );
202 respElem.appendChild( summaryElem );
205 if ( errorCount > 0 && trsElem.hasChildNodes() )
207 respElem.appendChild( trsElem );
211 if ( aRequest.
inserts.size() > 0 && irsElem.hasChildNodes() )
213 respElem.appendChild( irsElem );
220#ifndef HAVE_SERVER_PYTHON_PLUGINS
221 ( void ) serverIface;
224 QStringList typeNameList;
226 QList<transactionInsert>::iterator tiIt = aRequest.
inserts.begin();
227 for ( ; tiIt != aRequest.
inserts.end(); ++tiIt )
229 QString name = ( *tiIt ).typeName;
230 if ( !typeNameList.contains( name ) )
231 typeNameList << name;
233 QList<transactionUpdate>::iterator tuIt = aRequest.
updates.begin();
234 for ( ; tuIt != aRequest.
updates.end(); ++tuIt )
236 QString name = ( *tuIt ).typeName;
237 if ( !typeNameList.contains( name ) )
238 typeNameList << name;
240 QList<transactionDelete>::iterator tdIt = aRequest.
deletes.begin();
241 for ( ; tdIt != aRequest.
deletes.end(); ++tdIt )
243 QString name = ( *tdIt ).typeName;
244 if ( !typeNameList.contains( name ) )
245 typeNameList << name;
248#ifdef HAVE_SERVER_PYTHON_PLUGINS
255 auto filterRestorer = std::make_unique<QgsOWSServerFilterRestorer>();
262 QMap<QString, QgsVectorLayer *> mapLayerMap;
263 for (
int i = 0; i < wfsLayerIds.size(); ++i )
277 if ( !typeNameList.contains( name ) )
306 if ( !wfstUpdateLayerIds.contains( vlayer->
id() ) && !wfstDeleteLayerIds.contains( vlayer->
id() ) && !wfstInsertLayerIds.contains( vlayer->
id() ) )
310#ifdef HAVE_SERVER_PYTHON_PLUGINS
322 mapLayerMap[name] = vlayer;
326 tuIt = aRequest.
updates.begin();
327 for ( ; tuIt != aRequest.
updates.end(); ++tuIt )
332 if ( !mapLayerMap.contains( typeName ) )
335 action.
errorMsg = u
"TypeName '%1' unknown"_s.arg( typeName );
343 if ( !wfstUpdateLayerIds.contains( vlayer->
id() ) )
346 action.
errorMsg = u
"No permissions to do WFS updates on layer '%1'"_s.arg( typeName );
349#ifdef HAVE_SERVER_PYTHON_PLUGINS
353 action.
errorMsg = u
"No permissions to do WFS updates on layer '%1'"_s.arg( typeName );
365 action.
errorMsg = u
"No capabilities to do WFS updates on layer '%1'"_s.arg( typeName );
386#ifdef HAVE_SERVER_PYTHON_PLUGINS
397 int totalUpdated = 0;
399 QMap<QString, QString> propertyMap = action.
propertyMap;
403 const QMap<QString, int> fieldMap = provider->
fieldNameMap();
404 QMap<QString, int>::const_iterator fieldMapIt;
406 bool conversionSuccess;
410#ifdef HAVE_SERVER_PYTHON_PLUGINS
411 if ( accessControl && !accessControl->
allowToEdit( vlayer, feature ) )
414 action.
errorMsg = u
"Feature modify permission denied on layer '%1'"_s.arg( typeName );
419 QMap<QString, QString>::const_iterator it = propertyMap.constBegin();
420 for ( ; it != propertyMap.constEnd(); ++it )
422 fieldName = it.key();
423 fieldMapIt = fieldMap.find( fieldName );
424 if ( fieldMapIt == fieldMap.constEnd() )
428 QgsField field = fields.
at( fieldMapIt.value() );
429 QVariant value = it.value();
435 action.
errorMsg = u
"NOT NULL constraint error on layer '%1', field '%2'"_s.arg( typeName, field.
name() );
442 if ( field.
type() == QMetaType::Type::Int )
444 value = it.value().toInt( &conversionSuccess );
445 if ( !conversionSuccess )
448 action.
errorMsg = u
"Property conversion error on layer '%1'"_s.arg( typeName );
453 else if ( field.
type() == QMetaType::Type::Double )
455 value = it.value().toDouble( &conversionSuccess );
456 if ( !conversionSuccess )
459 action.
errorMsg = u
"Property conversion error on layer '%1'"_s.arg( typeName );
464 else if ( field.
type() == QMetaType::Type::LongLong )
466 value = it.value().toLongLong( &conversionSuccess );
467 if ( !conversionSuccess )
470 action.
errorMsg = u
"Property conversion error on layer '%1'"_s.arg( typeName );
483 if ( !geometryElem.isNull() )
489 action.
errorMsg = u
"Geometry from GML error on layer '%1'"_s.arg( typeName );
496 action.
errorMsg = u
"Error in change geometry on layer '%1'"_s.arg( typeName );
507#ifdef HAVE_SERVER_PYTHON_PLUGINS
514 if ( accessControl && !accessControl->
allowToEdit( vlayer, feature ) )
517 action.
errorMsg = u
"Feature modify permission denied on layer '%1'"_s.arg( typeName );
533 action.
errorMsg = u
"Error committing updates: %1"_s.arg( vlayer->
commitErrors().join(
"; "_L1 ) );
539 action.
error =
false;
543 tdIt = aRequest.
deletes.begin();
544 for ( ; tdIt != aRequest.
deletes.end(); ++tdIt )
549 if ( !mapLayerMap.contains( typeName ) )
552 action.
errorMsg = u
"TypeName '%1' unknown"_s.arg( typeName );
560 if ( !wfstDeleteLayerIds.contains( vlayer->
id() ) )
563 action.
errorMsg = u
"No permissions to do WFS deletes on layer '%1'"_s.arg( typeName );
566#ifdef HAVE_SERVER_PYTHON_PLUGINS
570 action.
errorMsg = u
"No permissions to do WFS deletes on layer '%1'"_s.arg( typeName );
582 action.
errorMsg = u
"No capabilities to do WFS deletes on layer '%1'"_s.arg( typeName );
600 action.
errorMsg = u
"No feature ids to do WFS deletes on layer '%1'"_s.arg( typeName );
607#ifdef HAVE_SERVER_PYTHON_PLUGINS
621#ifdef HAVE_SERVER_PYTHON_PLUGINS
622 if ( accessControl && !accessControl->
allowToEdit( vlayer, feature ) )
625 action.
errorMsg = u
"Feature modify permission denied"_s;
630 fids << feature.
id();
640 action.
errorMsg = u
"Delete features failed on layer '%1'"_s.arg( typeName );
649 action.
errorMsg = u
"Error committing deletes: %1"_s.arg( vlayer->
commitErrors().join(
"; "_L1 ) );
655 action.
error =
false;
659 tiIt = aRequest.
inserts.begin();
660 for ( ; tiIt != aRequest.
inserts.end(); ++tiIt )
665 if ( !mapLayerMap.contains( typeName ) )
668 action.
errorMsg = u
"TypeName '%1' unknown"_s.arg( typeName );
676 if ( !wfstInsertLayerIds.contains( vlayer->
id() ) )
679 action.
errorMsg = u
"No permissions to do WFS inserts on layer '%1'"_s.arg( typeName );
682#ifdef HAVE_SERVER_PYTHON_PLUGINS
686 action.
errorMsg = u
"No permissions to do WFS inserts on layer '%1'"_s.arg( typeName );
698 action.
errorMsg = u
"No capabilities to do WFS inserts on layer '%1'"_s.arg( typeName );
718 if ( featureList.empty() )
721 action.
errorMsg = u
"No features to insert in layer '%1'"_s.arg( typeName );
725#ifdef HAVE_SERVER_PYTHON_PLUGINS
729 QgsFeatureList::iterator featureIt = featureList.begin();
730 while ( featureIt != featureList.end() )
732 if ( !accessControl->
allowToEdit( vlayer, *featureIt ) )
735 action.
errorMsg = u
"Feature modify permission denied on layer '%1'"_s.arg( typeName );
752 action.
errorMsg = u
"Insert features failed on layer '%1'"_s.arg( typeName );
765 action.
errorMsg = u
"Error committing inserts: %1"_s.arg( vlayer->
commitErrors().join(
"; "_L1 ) );
770 action.
error =
false;
774 for (
const QgsFeature &feat : std::as_const( featureList ) )
781 filterRestorer.reset();
793 const QMap<QString, int> fieldMap = provider->
fieldNameMap();
794 QMap<QString, int>::const_iterator fieldMapIt;
796 for (
int i = 0; i < featureNodeList.count(); i++ )
800 QDomElement featureElem = featureNodeList.at( i ).toElement();
801 QDomNode currentAttributeChild = featureElem.firstChild();
802 bool conversionSuccess =
true;
804 for ( ; !currentAttributeChild.isNull(); currentAttributeChild = currentAttributeChild.nextSibling() )
806 QDomElement currentAttributeElement = currentAttributeChild.toElement();
807 QString attrName = currentAttributeElement.localName();
809 if ( attrName !=
"boundedBy"_L1 )
811 if ( attrName !=
"geometry"_L1 )
813 fieldMapIt = fieldMap.find( attrName );
814 if ( fieldMapIt == fieldMap.constEnd() )
820 QgsField field = fields.
at( fieldMapIt.value() );
821 QString attrValue = currentAttributeElement.text();
822 int attrType = field.
type();
824 QgsMessageLog::logMessage( u
"attr: name=%1 idx=%2 value=%3"_s.arg( attrName ).arg( fieldMapIt.value() ).arg( attrValue ) );
826 if ( attrType == QMetaType::Type::Int )
827 feat.
setAttribute( fieldMapIt.value(), attrValue.toInt( &conversionSuccess ) );
828 else if ( attrType == QMetaType::Type::Double )
829 feat.
setAttribute( fieldMapIt.value(), attrValue.toDouble( &conversionSuccess ) );
833 if ( !conversionSuccess )
858 if ( !parameters.contains( u
"OPERATION"_s ) )
862 if ( parameters.value( u
"OPERATION"_s ).toUpper() !=
"DELETE"_L1 )
868 if ( ( parameters.contains( u
"FEATUREID"_s ) && ( parameters.contains( u
"FILTER"_s ) || parameters.contains( u
"BBOX"_s ) ) )
869 || ( parameters.contains( u
"FILTER"_s ) && ( parameters.contains( u
"FEATUREID"_s ) || parameters.contains( u
"BBOX"_s ) ) )
870 || ( parameters.contains( u
"BBOX"_s ) && ( parameters.contains( u
"FEATUREID"_s ) || parameters.contains( u
"FILTER"_s ) ) ) )
877 QStringList typeNameList;
879 if ( parameters.contains( u
"FEATUREID"_s ) )
881 QStringList fidList = parameters.value( u
"FEATUREID"_s ).split(
',' );
883 QMap<QString, QStringList> fidsMap;
885 QStringList::const_iterator fidIt = fidList.constBegin();
886 for ( ; fidIt != fidList.constEnd(); ++fidIt )
889 QString fid = *fidIt;
892 if ( !fid.contains(
'.' ) )
897 QString typeName = fid.section(
'.', 0, 0 );
898 fid = fid.section(
'.', 1, 1 );
899 if ( !typeNameList.contains( typeName ) )
901 typeNameList << typeName;
905 if ( fidsMap.contains( typeName ) )
907 fids = fidsMap.value( typeName );
910 fidsMap.insert( typeName, fids );
913 QMap<QString, QStringList>::const_iterator fidsMapIt = fidsMap.constBegin();
914 for ( ; fidsMapIt != fidsMap.constEnd(); ++fidsMapIt )
922 request.
deletes.append( action );
927 if ( !parameters.contains( u
"TYPENAME"_s ) )
932 typeNameList = parameters.value( u
"TYPENAME"_s ).split(
',' );
935 QStringList::const_iterator typeNameIt = typeNameList.constBegin();
936 for ( ; typeNameIt != typeNameList.constEnd(); ++typeNameIt )
938 QString typeName = *typeNameIt;
939 typeName = typeName.trimmed();
944 request.
deletes.append( action );
948 if ( parameters.contains( u
"EXP_FILTER"_s ) )
950 QString expFilterName = parameters.value( u
"EXP_FILTER"_s );
951 QStringList expFilterList;
952 const thread_local QRegularExpression rx(
"\\(([^()]+)\\)" );
953 QRegularExpressionMatchIterator matchIt = rx.globalMatch( expFilterName );
954 if ( !matchIt.hasNext() )
956 expFilterList << expFilterName;
960 while ( matchIt.hasNext() )
962 const QRegularExpressionMatch match = matchIt.next();
963 if ( match.hasMatch() )
965 QStringList matches = match.capturedTexts();
967 expFilterList.append( matches );
973 if ( request.
deletes.size() == expFilterList.size() )
976 QList<transactionDelete>::iterator dIt = request.
deletes.begin();
977 QStringList::const_iterator expFilterIt = expFilterList.constBegin();
978 for ( ; dIt != request.
deletes.end(); ++dIt )
983 if ( expFilterIt != expFilterList.constEnd() )
985 expFilter = *expFilterIt;
987 std::shared_ptr<QgsExpression> filter(
new QgsExpression( expFilter ) );
990 if ( filter->hasParserError() )
996 if ( filter->needsGeometry() )
1007 QgsMessageLog::logMessage(
"There has to be a 1:1 mapping between each element in a TYPENAME and the EXP_FILTER list" );
1011 if ( parameters.contains( u
"BBOX"_s ) )
1014 QString bbox = parameters.value( u
"BBOX"_s );
1015 if ( bbox.isEmpty() )
1021 QStringList corners = bbox.split(
',' );
1022 if ( corners.size() != 4 )
1030 for (
int i = 0; i < 4; i++ )
1032 corners[i].replace(
' ',
'+' );
1033 d[i] = corners[i].toDouble( &ok );
1043 QList<transactionDelete>::iterator dIt = request.
deletes.begin();
1044 for ( ; dIt != request.
deletes.end(); ++dIt )
1051 else if ( parameters.contains( u
"FILTER"_s ) )
1053 QString filterName = parameters.value( u
"FILTER"_s );
1054 QStringList filterList;
1055 const thread_local QRegularExpression rx(
"\\(([^()]+)\\)" );
1056 QRegularExpressionMatchIterator matchIt = rx.globalMatch( filterName );
1057 if ( !matchIt.hasNext() )
1059 filterList << filterName;
1063 while ( matchIt.hasNext() )
1065 const QRegularExpressionMatch match = matchIt.next();
1066 if ( match.hasMatch() )
1068 QStringList matches = match.capturedTexts();
1069 matches.pop_front();
1070 filterList.append( matches );
1076 if ( request.
deletes.size() != filterList.size() )
1082 QList<transactionDelete>::iterator dIt = request.
deletes.begin();
1083 QStringList::const_iterator filterIt = filterList.constBegin();
1084 for ( ; dIt != request.
deletes.end(); ++dIt )
1089 QDomDocument filter;
1090 if ( filterIt != filterList.constEnd() )
1093 if ( !filter.setContent( *filterIt,
true, &errorMsg ) )
1099 QDomElement filterElem = filter.firstChildElement();
1100 QStringList serverFids;
1104 if ( filterIt != filterList.constEnd() )
1119 QDomNodeList docChildNodes = docElem.childNodes();
1121 QDomElement actionElem;
1124 for (
int i = docChildNodes.count(); 0 < i; --i )
1126 actionElem = docChildNodes.at( i - 1 ).toElement();
1127 actionName = actionElem.localName();
1129 if ( actionName ==
"Insert"_L1 )
1132 request.
inserts.append( action );
1134 else if ( actionName ==
"Update"_L1 )
1137 request.
updates.append( action );
1139 else if ( actionName ==
"Delete"_L1 )
1142 request.
deletes.append( action );
1151 QString typeName = actionElem.attribute( u
"typeName"_s );
1152 if ( typeName.contains(
':' ) )
1153 typeName = typeName.section(
':', 1, 1 );
1155 QDomElement filterElem = actionElem.firstChild().toElement();
1156 if ( filterElem.tagName() !=
"Filter"_L1 )
1161 QStringList serverFids;
1168 action.
error =
false;
1170 if ( actionElem.hasAttribute( u
"handle"_s ) )
1172 action.
handle = actionElem.attribute( u
"handle"_s );
1181 QString typeName = actionElem.attribute( u
"typeName"_s );
1182 if ( typeName.contains(
':' ) )
1183 typeName = typeName.section(
':', 1, 1 );
1185 QDomNodeList propertyNodeList = actionElem.elementsByTagName( u
"Property"_s );
1186 if ( propertyNodeList.isEmpty() )
1191 QMap<QString, QString> propertyMap;
1192 QDomElement propertyElem;
1193 QDomElement nameElem;
1194 QDomElement valueElem;
1195 QDomElement geometryElem;
1197 for (
int l = 0; l < propertyNodeList.count(); ++l )
1199 propertyElem = propertyNodeList.at( l ).toElement();
1200 nameElem = propertyElem.elementsByTagName( u
"Name"_s ).at( 0 ).toElement();
1201 valueElem = propertyElem.elementsByTagName( u
"Value"_s ).at( 0 ).toElement();
1202 if ( nameElem.text() !=
"geometry"_L1 )
1204 propertyMap.insert( nameElem.text(), valueElem.text() );
1208 geometryElem = valueElem;
1212 QDomNodeList filterNodeList = actionElem.elementsByTagName( u
"Filter"_s );
1214 QStringList serverFids;
1215 if ( filterNodeList.size() != 0 )
1217 QDomElement filterElem = filterNodeList.at( 0 ).toElement();
1228 action.
error =
false;
1230 if ( actionElem.hasAttribute( u
"handle"_s ) )
1232 action.
handle = actionElem.attribute( u
"handle"_s );
1240 QDomNodeList featureNodeList = actionElem.childNodes();
1241 if ( featureNodeList.size() != 1 )
1247 for (
int i = 0; i < featureNodeList.count(); ++i )
1249 QString tempTypeName = featureNodeList.at( i ).toElement().localName();
1250 if ( tempTypeName.contains(
':' ) )
1251 tempTypeName = tempTypeName.section(
':', 1, 1 );
1253 if ( typeName.isEmpty() )
1255 typeName = tempTypeName;
1257 else if ( tempTypeName != typeName )
1266 action.
error =
false;
1268 if ( actionElem.hasAttribute( u
"handle"_s ) )
1270 action.
handle = actionElem.attribute( u
"handle"_s );
1279 void addTransactionResult( QDomDocument &responseDoc, QDomElement &resultsElem,
const QString &locator,
const QString &message )
1281 QDomElement trElem = responseDoc.createElement( u
"Action"_s );
1282 resultsElem.appendChild( trElem );
1284 if ( !locator.isEmpty() )
1286 trElem.setAttribute( u
"locator"_s, locator );
1289 if ( !message.isEmpty() )
1291 QDomElement mesElem = responseDoc.createElement( u
"Message"_s );
1292 mesElem.appendChild( responseDoc.createTextNode( message ) );
1293 trElem.appendChild( mesElem );
@ AddFeatures
Allows adding features.
@ ChangeGeometries
Allows modifications of geometries.
@ DeleteFeatures
Allows deletion of features.
@ ChangeAttributeValues
Allows modification of attribute values.
@ NoFlags
No flags are set.
@ Info
Information message.
QFlags< VectorProviderCapability > VectorProviderCapabilities
Vector data provider capabilities.
A helper class that centralizes restrictions given by all the access control filter plugins.
bool layerUpdatePermission(const QgsVectorLayer *layer) const
Returns the layer update right.
void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures) const override
Filter the features of the layer.
bool layerInsertPermission(const QgsVectorLayer *layer) const
Returns the layer insert right.
bool allowToEdit(const QgsVectorLayer *layer, const QgsFeature &feature) const
Are we authorized to modify the following geometry.
bool layerDeletePermission(const QgsVectorLayer *layer) const
Returns the layer delete right.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
@ ConstraintNotNull
Field may not be null.
Encapsulate a field in an attribute table or data source.
QgsFieldConstraints constraints
Container of fields for a vector layer.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
A geometry is the spatial representation of a feature.
QString wfsTypeName() const
Returns WFS typename for the layer.
Base class for all map layer types.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
static void applyAccessControlLayerFilters(const QgsAccessControl *accessControl, QgsMapLayer *mapLayer, QHash< QgsMapLayer *, QString > &originalLayerFilters)
Apply filter from AccessControl.
Exception base class for service exceptions.
QString message() const
Returns the exception message.
static QgsGeometry geometryFromGML(const QString &xmlString, const QgsOgcUtils::Context &context=QgsOgcUtils::Context())
Static method that creates geometry from GML.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
A rectangle specified with double values.
static QgsFeatureRequest updateFeatureRequestFromServerFids(QgsFeatureRequest &featureRequest, const QStringList &serverFids, const QgsVectorDataProvider *provider)
Returns the feature request based on feature ids build with primary keys.
static QString getServerFid(const QgsFeature &feature, const QgsAttributeList &pkAttributes)
Returns the feature id based on primary keys.
Defines interfaces exposed by QGIS Server and made available to plugins.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
static QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
static QStringList wfstUpdateLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with update capabilities.
static QStringList wfstInsertLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with insert capabilities.
static QStringList wfstDeleteLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with delete capabilities.
Defines requests passed to QgsService classes.
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
QMap< QString, QString > Parameters
virtual QByteArray data() const
Returns post/put data Check for QByteArray::isNull() to check if data is available.
Defines the response interface passed to QgsService.
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Base class for vector data providers.
void clearErrors()
Clear recorded errors.
virtual Q_INVOKABLE Qgis::VectorProviderCapabilities capabilities() const
Returns flags containing the supported capabilities.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a list of features to the sink.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
QMap< QString, int > fieldNameMap() const
Returns a map where the key is the name of the field and the value is its index.
bool hasErrors() const
Provider has errors to report.
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE bool deleteFeatures(const QgsFeatureIds &fids, QgsVectorLayer::DeleteContext *context=nullptr)
Deletes a set of features from the layer (but does not commit it).
Q_INVOKABLE bool startEditing()
Makes the layer editable.
Q_INVOKABLE bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant(), bool skipDefaultValues=false, QgsVectorLayerToolsContext *context=nullptr)
Changes an attribute value for a feature (but does not immediately commit the changes).
bool isSpatial() const final
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QStringList commitErrors() const
Returns a list containing any error messages generated when attempting to commit changes to the layer...
Q_INVOKABLE bool rollBack(bool deleteBuffer=true)
Stops a current editing operation and discards any uncommitted edits.
Q_INVOKABLE bool commitChanges(bool stopEditing=true)
Attempts to commit to the underlying data provider any buffered changes made since the last to call t...
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
Q_INVOKABLE bool changeGeometry(QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue=false)
Changes a feature's geometry within the layer's edit buffer (but does not immediately commit the chan...
Exception thrown when data access violates access controls.
transactionRequest parseTransactionRequestBody(QDomElement &docElem, const QgsProject *project)
Transform RequestBody root element to getFeatureRequest.
const QString OGC_NAMESPACE
transactionRequest parseTransactionParameters(QgsServerRequest::Parameters parameters, const QgsProject *project)
const QString WFS_NAMESPACE
void performTransaction(transactionRequest &aRequest, QgsServerInterface *serverIface, const QgsProject *project)
Perform the transaction.
QgsFeatureList featuresFromGML(QDomNodeList featureNodeList, QgsVectorLayer *layer)
Transform GML feature nodes to features.
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
QgsFeatureRequest parseFilterElement(const QString &typeName, QDomElement &filterElem, QgsProject *project)
Transform a Filter element to a feature request.
QDomDocument createTransactionDocument(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request)
Create a wfs transaction document.
transactionInsert parseInsertActionElement(QDomElement &actionElem)
Transform Insert element to transactionInsert.
transactionDelete parseDeleteActionElement(QDomElement &actionElem, const QgsProject *project)
Transform Delete element to transactionDelete.
transactionUpdate parseUpdateActionElement(QDomElement &actionElem, const QgsProject *project)
Transform Update element to transactionUpdate.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
QList< int > QgsAttributeList
The Context struct stores the current layer and coordinate transform context.
QgsFeatureRequest featureRequest
QDomNodeList featureNodeList
QStringList insertFeatureIds
QList< transactionDelete > deletes
QList< transactionInsert > inserts
QList< transactionUpdate > updates
QgsFeatureRequest featureRequest
QDomElement geometryElement
QMap< QString, QString > propertyMap