QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgswfstransaction_1_0_0.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswfstransaction.cpp
3 -------------------------
4 begin : December 20 , 2016
5 copyright : (C) 2007 by Marco Hugentobler (original code)
6 (C) 2012 by René-Luc D'Hont (original code)
7 (C) 2014 by Alessandro Pasotti (original code)
8 (C) 2017 by David Marteau
9 email : marco dot hugentobler at karto dot baug dot ethz dot ch
10 a dot pasotti at itopen dot it
11 david dot marteau at 3liz dot com
12 ***************************************************************************/
13
14/***************************************************************************
15 * *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published by *
18 * the Free Software Foundation; either version 2 of the License, or *
19 * (at your option) any later version. *
20 * *
21 ***************************************************************************/
22
23
25
26#include "qgsexpression.h"
28#include "qgsfeatureiterator.h"
29#include "qgsfields.h"
30#include "qgsfilterrestorer.h"
31#include "qgsgeometry.h"
32#include "qgsmaplayer.h"
33#include "qgsogcutils.h"
34#include "qgsproject.h"
35#include "qgsserverfeatureid.h"
38#include "qgsvectorlayer.h"
39#include "qgswfsutils.h"
40
41#include <QRegularExpression>
42#include <QString>
43
44using namespace Qt::StringLiterals;
45
46namespace QgsWfs
47{
48 namespace v1_0_0
49 {
50 namespace
51 {
52 void addTransactionResult( QDomDocument &responseDoc, QDomElement &responseElem, const QString &status, const QString &locator, const QString &message );
53 }
54
55
56 void writeTransaction( QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response )
57
58 {
59 QDomDocument doc = createTransactionDocument( serverIface, project, version, request );
60
61 response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
62 response.write( doc.toByteArray() );
63 }
64
65 QDomDocument createTransactionDocument( QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request )
66 {
67 Q_UNUSED( version )
68
69 QgsServerRequest::Parameters parameters = request.parameters();
70 transactionRequest aRequest;
71
72 QDomDocument doc;
73 QString errorMsg;
74
75 if ( doc.setContent( request.data(), true, &errorMsg ) )
76 {
77 QDomElement docElem = doc.documentElement();
78 aRequest = parseTransactionRequestBody( docElem, project );
79 }
80 else
81 {
82 aRequest = parseTransactionParameters( parameters, project );
83 }
84
85 int actionCount = aRequest.inserts.size() + aRequest.updates.size() + aRequest.deletes.size();
86 if ( actionCount == 0 )
87 {
88 throw QgsRequestNotWellFormedException( u"No actions found"_s );
89 }
90
91 performTransaction( aRequest, serverIface, project );
92
93 // It's time to make the transaction
94 // Create the response document
95 QDomDocument resp;
96 //wfs:WFS_TransactionRespone element
97 QDomElement respElem = resp.createElement( u"WFS_TransactionResponse"_s /*wfs:WFS_TransactionResponse*/ );
98 respElem.setAttribute( u"xmlns"_s, WFS_NAMESPACE );
99 respElem.setAttribute( u"xmlns:xsi"_s, u"http://www.w3.org/2001/XMLSchema-instance"_s );
100 respElem.setAttribute( u"xsi:schemaLocation"_s, WFS_NAMESPACE + " http://schemas.opengis.net/wfs/1.0.0/wfs.xsd" );
101 respElem.setAttribute( u"xmlns:ogc"_s, OGC_NAMESPACE );
102 respElem.setAttribute( u"version"_s, u"1.0.0"_s );
103 resp.appendChild( respElem );
104
105 int errorCount = 0;
106 QStringList errorLocators;
107 QStringList errorMessages;
108
109 QList<transactionUpdate>::iterator tuIt = aRequest.updates.begin();
110 for ( ; tuIt != aRequest.updates.end(); ++tuIt )
111 {
112 transactionUpdate &action = *tuIt;
113 if ( action.error )
114 {
115 errorCount += 1;
116 if ( action.handle.isEmpty() )
117 {
118 errorLocators << u"Update:%1"_s.arg( action.typeName );
119 }
120 else
121 {
122 errorLocators << action.handle;
123 }
124 errorMessages << action.errorMsg;
125 }
126 }
127
128 QList<transactionDelete>::iterator tdIt = aRequest.deletes.begin();
129 for ( ; tdIt != aRequest.deletes.end(); ++tdIt )
130 {
131 transactionDelete &action = *tdIt;
132 if ( action.error )
133 {
134 errorCount += 1;
135 if ( action.handle.isEmpty() )
136 {
137 errorLocators << u"Delete:%1"_s.arg( action.typeName );
138 }
139 else
140 {
141 errorLocators << action.handle;
142 }
143 errorMessages << action.errorMsg;
144 }
145 }
146
147 QList<transactionInsert>::iterator tiIt = aRequest.inserts.begin();
148 for ( ; tiIt != aRequest.inserts.end(); ++tiIt )
149 {
150 transactionInsert &action = *tiIt;
151 if ( action.error )
152 {
153 errorCount += 1;
154 if ( action.handle.isEmpty() )
155 {
156 errorLocators << u"Insert:%1"_s.arg( action.typeName );
157 }
158 else
159 {
160 errorLocators << action.handle;
161 }
162 errorMessages << action.errorMsg;
163 }
164 else
165 {
166 QStringList::const_iterator fidIt = action.insertFeatureIds.constBegin();
167 for ( ; fidIt != action.insertFeatureIds.constEnd(); ++fidIt )
168 {
169 QString fidStr = *fidIt;
170 QDomElement irElem = doc.createElement( u"InsertResult"_s );
171 if ( !action.handle.isEmpty() )
172 {
173 irElem.setAttribute( u"handle"_s, action.handle );
174 }
175 QDomElement fiElem = doc.createElement( u"ogc:FeatureId"_s );
176 fiElem.setAttribute( u"fid"_s, fidStr );
177 irElem.appendChild( fiElem );
178 respElem.appendChild( irElem );
179 }
180 }
181 }
182
183 // addTransactionResult
184 if ( errorCount == 0 )
185 {
186 addTransactionResult( resp, respElem, u"SUCCESS"_s, QString(), QString() );
187 }
188 else
189 {
190 QString locator = errorLocators.join( "; "_L1 );
191 QString message = errorMessages.join( "; "_L1 );
192 if ( errorCount != actionCount )
193 {
194 addTransactionResult( resp, respElem, u"PARTIAL"_s, locator, message );
195 }
196 else
197 {
198 addTransactionResult( resp, respElem, u"ERROR"_s, locator, message );
199 }
200 }
201 return resp;
202 }
203
204 void performTransaction( transactionRequest &aRequest, QgsServerInterface *serverIface, const QgsProject *project )
205 {
206 // store typeName
207 QStringList typeNameList;
208
209 QList<transactionInsert>::iterator tiIt = aRequest.inserts.begin();
210 for ( ; tiIt != aRequest.inserts.end(); ++tiIt )
211 {
212 QString name = ( *tiIt ).typeName;
213 if ( !typeNameList.contains( name ) )
214 typeNameList << name;
215 }
216 QList<transactionUpdate>::iterator tuIt = aRequest.updates.begin();
217 for ( ; tuIt != aRequest.updates.end(); ++tuIt )
218 {
219 QString name = ( *tuIt ).typeName;
220 if ( !typeNameList.contains( name ) )
221 typeNameList << name;
222 }
223 QList<transactionDelete>::iterator tdIt = aRequest.deletes.begin();
224 for ( ; tdIt != aRequest.deletes.end(); ++tdIt )
225 {
226 QString name = ( *tdIt ).typeName;
227 if ( !typeNameList.contains( name ) )
228 typeNameList << name;
229 }
230
231#ifdef HAVE_SERVER_PYTHON_PLUGINS
232 // get access controls
233 QgsAccessControl *accessControl = serverIface->accessControls();
234#else
235 ( void ) serverIface;
236#endif
237
238 //scoped pointer to restore all original layer filters (subsetStrings) when pointer goes out of scope
239 //there's LOTS of potential exit paths here, so we avoid having to restore the filters manually
240 auto filterRestorer = std::make_unique<QgsOWSServerFilterRestorer>();
241
242 // get layers
243 QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *project );
244 QStringList wfstUpdateLayerIds = QgsServerProjectUtils::wfstUpdateLayerIds( *project );
245 QStringList wfstDeleteLayerIds = QgsServerProjectUtils::wfstDeleteLayerIds( *project );
246 QStringList wfstInsertLayerIds = QgsServerProjectUtils::wfstInsertLayerIds( *project );
247 QMap<QString, QgsVectorLayer *> mapLayerMap;
248 for ( int i = 0; i < wfsLayerIds.size(); ++i )
249 {
250 QgsMapLayer *layer = project->mapLayer( wfsLayerIds.at( i ) );
251 if ( !layer || layer->type() != Qgis::LayerType::Vector )
252 {
253 continue;
254 }
255
256 QString name = layer->serverProperties()->wfsTypeName();
257
258 if ( !typeNameList.contains( name ) )
259 {
260 continue;
261 }
262
263 // get vector layer
264 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
265 if ( !vlayer )
266 {
267 throw QgsRequestNotWellFormedException( u"Layer error on '%1'"_s.arg( name ) );
268 }
269
270 //get provider
271 QgsVectorDataProvider *provider = vlayer->dataProvider();
272 if ( !provider )
273 {
274 throw QgsRequestNotWellFormedException( u"Provider error on layer '%1'"_s.arg( name ) );
275 }
276
277 // get provider capabilities
283 {
284 throw QgsRequestNotWellFormedException( u"No capabilities to do WFS changes on layer '%1'"_s.arg( name ) );
285 }
286
287 if ( !wfstUpdateLayerIds.contains( vlayer->id() ) && !wfstDeleteLayerIds.contains( vlayer->id() ) && !wfstInsertLayerIds.contains( vlayer->id() ) )
288 {
289 throw QgsSecurityAccessException( u"No permissions to do WFS changes on layer '%1'"_s.arg( name ) );
290 }
291#ifdef HAVE_SERVER_PYTHON_PLUGINS
292 if ( accessControl && !accessControl->layerUpdatePermission( vlayer ) && !accessControl->layerDeletePermission( vlayer ) && !accessControl->layerInsertPermission( vlayer ) )
293 {
294 throw QgsSecurityAccessException( u"No permissions to do WFS changes on layer '%1'"_s.arg( name ) );
295 }
296
297 if ( accessControl )
298 {
299 QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( accessControl, vlayer, filterRestorer->originalFilters() );
300 }
301#endif
302 // store layers
303 mapLayerMap[name] = vlayer;
304 }
305
306 // perform updates
307 tuIt = aRequest.updates.begin();
308 for ( ; tuIt != aRequest.updates.end(); ++tuIt )
309 {
310 transactionUpdate &action = *tuIt;
311 QString typeName = action.typeName;
312
313 if ( !mapLayerMap.contains( typeName ) )
314 {
315 action.error = true;
316 action.errorMsg = u"TypeName '%1' unknown"_s.arg( typeName );
317 continue;
318 }
319
320 // get vector layer
321 QgsVectorLayer *vlayer = mapLayerMap[typeName];
322
323 // verifying specific permissions
324 if ( !wfstUpdateLayerIds.contains( vlayer->id() ) )
325 {
326 action.error = true;
327 action.errorMsg = u"No permissions to do WFS updates on layer '%1'"_s.arg( typeName );
328 continue;
329 }
330#ifdef HAVE_SERVER_PYTHON_PLUGINS
331 if ( accessControl && !accessControl->layerUpdatePermission( vlayer ) )
332 {
333 action.error = true;
334 action.errorMsg = u"No permissions to do WFS updates on layer '%1'"_s.arg( typeName );
335 continue;
336 }
337#endif
338 //get provider
339 QgsVectorDataProvider *provider = vlayer->dataProvider();
340
341 // verifying specific capabilities
344 {
345 action.error = true;
346 action.errorMsg = u"No capabilities to do WFS updates on layer '%1'"_s.arg( typeName );
347 continue;
348 }
349 // start editing
350 vlayer->startEditing();
351
352 // update request
353 QgsFeatureRequest featureRequest = action.featureRequest;
354
355 // expression context
356 QgsExpressionContext expressionContext;
358 featureRequest.setExpressionContext( expressionContext );
359
360 // verifying feature ids list
361 if ( !action.serverFids.isEmpty() )
362 {
363 // update request based on feature ids
364 QgsServerFeatureId::updateFeatureRequestFromServerFids( featureRequest, action.serverFids, provider );
365 }
366
367#ifdef HAVE_SERVER_PYTHON_PLUGINS
368 if ( accessControl )
369 {
371 accessControl->filterFeatures( vlayer, featureRequest );
373 }
374#endif
375 // get iterator
376 QgsFeatureIterator fit = vlayer->getFeatures( featureRequest );
377 QgsFeature feature;
378 // get action properties
379 QMap<QString, QString> propertyMap = action.propertyMap;
380 QDomElement geometryElem = action.geometryElement;
381 // get field information
382 QgsFields fields = provider->fields();
383 const QMap<QString, int> fieldMap = provider->fieldNameMap();
384 QMap<QString, int>::const_iterator fieldMapIt;
385 QString fieldName;
386 bool conversionSuccess;
387 // Update the features
388 while ( fit.nextFeature( feature ) )
389 {
390#ifdef HAVE_SERVER_PYTHON_PLUGINS
391 if ( accessControl && !accessControl->allowToEdit( vlayer, feature ) )
392 {
393 action.error = true;
394 action.errorMsg = u"Feature modify permission denied on layer '%1'"_s.arg( typeName );
395 vlayer->rollBack();
396 break;
397 }
398#endif
399 QMap<QString, QString>::const_iterator it = propertyMap.constBegin();
400 for ( ; it != propertyMap.constEnd(); ++it )
401 {
402 fieldName = it.key();
403 fieldMapIt = fieldMap.find( fieldName );
404 if ( fieldMapIt == fieldMap.constEnd() )
405 {
406 continue;
407 }
408 QgsField field = fields.at( fieldMapIt.value() );
409 QVariant value = it.value();
410 if ( QgsVariantUtils::isNull( value ) )
411 {
413 {
414 action.error = true;
415 action.errorMsg = u"NOT NULL constraint error on layer '%1', field '%2'"_s.arg( typeName, field.name() );
416 vlayer->rollBack();
417 break;
418 }
419 }
420 else // Not NULL
421 {
422 if ( field.type() == QMetaType::Type::Int )
423 {
424 value = it.value().toInt( &conversionSuccess );
425 if ( !conversionSuccess )
426 {
427 action.error = true;
428 action.errorMsg = u"Property conversion error on layer '%1'"_s.arg( typeName );
429 vlayer->rollBack();
430 break;
431 }
432 }
433 else if ( field.type() == QMetaType::Type::Double )
434 {
435 value = it.value().toDouble( &conversionSuccess );
436 if ( !conversionSuccess )
437 {
438 action.error = true;
439 action.errorMsg = u"Property conversion error on layer '%1'"_s.arg( typeName );
440 vlayer->rollBack();
441 break;
442 }
443 }
444 else if ( field.type() == QMetaType::Type::LongLong )
445 {
446 value = it.value().toLongLong( &conversionSuccess );
447 if ( !conversionSuccess )
448 {
449 action.error = true;
450 action.errorMsg = u"Property conversion error on layer '%1'"_s.arg( typeName );
451 vlayer->rollBack();
452 break;
453 }
454 }
455 }
456 vlayer->changeAttributeValue( feature.id(), fieldMapIt.value(), value );
457 }
458 if ( action.error )
459 {
460 break;
461 }
462
463 if ( !geometryElem.isNull() )
464 {
465 const QgsOgcUtils::Context context { vlayer, provider->transformContext() };
466 QgsGeometry g = QgsOgcUtils::geometryFromGML( geometryElem, context );
467
468 if ( g.isNull() )
469 {
470 action.error = true;
471 action.errorMsg = u"Geometry from GML error on layer '%1'"_s.arg( typeName );
472 vlayer->rollBack();
473 break;
474 }
475 if ( !vlayer->changeGeometry( feature.id(), g ) )
476 {
477 action.error = true;
478 action.errorMsg = u"Error in change geometry on layer '%1'"_s.arg( typeName );
479 vlayer->rollBack();
480 break;
481 }
482 }
483 }
484 if ( action.error )
485 {
486 continue;
487 }
488#ifdef HAVE_SERVER_PYTHON_PLUGINS
489 // verifying changes
490 if ( accessControl )
491 {
492 fit = vlayer->getFeatures( featureRequest );
493 while ( fit.nextFeature( feature ) )
494 {
495 if ( accessControl && !accessControl->allowToEdit( vlayer, feature ) )
496 {
497 action.error = true;
498 action.errorMsg = u"Feature modify permission denied on layer '%1'"_s.arg( typeName );
499 vlayer->rollBack();
500 break;
501 }
502 }
503 }
504 if ( action.error )
505 {
506 continue;
507 }
508#endif
509
510 // Commit the changes of the update elements
511 if ( !vlayer->commitChanges() )
512 {
513 action.error = true;
514 action.errorMsg = u"Error committing updates: %1"_s.arg( vlayer->commitErrors().join( "; "_L1 ) );
515 vlayer->rollBack();
516 continue;
517 }
518 // all the changes are OK!
519 action.error = false;
520 }
521
522 // perform deletes
523 tdIt = aRequest.deletes.begin();
524 for ( ; tdIt != aRequest.deletes.end(); ++tdIt )
525 {
526 transactionDelete &action = *tdIt;
527 QString typeName = action.typeName;
528
529 if ( !mapLayerMap.contains( typeName ) )
530 {
531 action.error = true;
532 action.errorMsg = u"TypeName '%1' unknown"_s.arg( typeName );
533 continue;
534 }
535
536 // get vector layer
537 QgsVectorLayer *vlayer = mapLayerMap[typeName];
538
539 // verifying specific permissions
540 if ( !wfstDeleteLayerIds.contains( vlayer->id() ) )
541 {
542 action.error = true;
543 action.errorMsg = u"No permissions to do WFS deletes on layer '%1'"_s.arg( typeName );
544 continue;
545 }
546#ifdef HAVE_SERVER_PYTHON_PLUGINS
547 if ( accessControl && !accessControl->layerDeletePermission( vlayer ) )
548 {
549 action.error = true;
550 action.errorMsg = u"No permissions to do WFS deletes on layer '%1'"_s.arg( typeName );
551 continue;
552 }
553#endif
554 //get provider
555 QgsVectorDataProvider *provider = vlayer->dataProvider();
556
557 // verifying specific capabilities
560 {
561 action.error = true;
562 action.errorMsg = u"No capabilities to do WFS deletes on layer '%1'"_s.arg( typeName );
563 continue;
564 }
565 // start editing
566 vlayer->startEditing();
567
568 // delete request
569 QgsFeatureRequest featureRequest = action.featureRequest;
570
571 // expression context
572 QgsExpressionContext expressionContext;
574 featureRequest.setExpressionContext( expressionContext );
575
576 // verifying feature ids list
577 if ( action.serverFids.isEmpty() )
578 {
579 action.error = true;
580 action.errorMsg = u"No feature ids to do WFS deletes on layer '%1'"_s.arg( typeName );
581 continue;
582 }
583
584 // update request based on feature ids
585 QgsServerFeatureId::updateFeatureRequestFromServerFids( featureRequest, action.serverFids, provider );
586
587#ifdef HAVE_SERVER_PYTHON_PLUGINS
588 if ( accessControl )
589 {
590 accessControl->filterFeatures( vlayer, featureRequest );
591 }
592#endif
593
594 // get iterator
595 QgsFeatureIterator fit = vlayer->getFeatures( featureRequest );
596 QgsFeature feature;
597 // get deleted fids
598 QgsFeatureIds fids;
599 while ( fit.nextFeature( feature ) )
600 {
601#ifdef HAVE_SERVER_PYTHON_PLUGINS
602 if ( accessControl && !accessControl->allowToEdit( vlayer, feature ) )
603 {
604 action.error = true;
605 action.errorMsg = u"Feature modify permission denied"_s;
606 vlayer->rollBack();
607 break;
608 }
609#endif
610 fids << feature.id();
611 }
612 if ( action.error )
613 {
614 continue;
615 }
616 // delete features
617 if ( !vlayer->deleteFeatures( fids ) )
618 {
619 action.error = true;
620 action.errorMsg = u"Delete features failed on layer '%1'"_s.arg( typeName );
621 vlayer->rollBack();
622 continue;
623 }
624
625 // Commit the changes of the update elements
626 if ( !vlayer->commitChanges() )
627 {
628 action.error = true;
629 action.errorMsg = u"Error committing deletes: %1"_s.arg( vlayer->commitErrors().join( "; "_L1 ) );
630 vlayer->rollBack();
631 continue;
632 }
633 // all the changes are OK!
634 action.error = false;
635 }
636
637 // perform inserts
638 tiIt = aRequest.inserts.begin();
639 for ( ; tiIt != aRequest.inserts.end(); ++tiIt )
640 {
641 transactionInsert &action = *tiIt;
642 QString typeName = action.typeName;
643
644 if ( !mapLayerMap.contains( typeName ) )
645 {
646 action.error = true;
647 action.errorMsg = u"TypeName '%1' unknown"_s.arg( typeName );
648 continue;
649 }
650
651 // get vector layer
652 QgsVectorLayer *vlayer = mapLayerMap[typeName];
653
654 // verifying specific permissions
655 if ( !wfstInsertLayerIds.contains( vlayer->id() ) )
656 {
657 action.error = true;
658 action.errorMsg = u"No permissions to do WFS inserts on layer '%1'"_s.arg( typeName );
659 continue;
660 }
661#ifdef HAVE_SERVER_PYTHON_PLUGINS
662 if ( accessControl && !accessControl->layerInsertPermission( vlayer ) )
663 {
664 action.error = true;
665 action.errorMsg = u"No permissions to do WFS inserts on layer '%1'"_s.arg( typeName );
666 continue;
667 }
668#endif
669 //get provider
670 QgsVectorDataProvider *provider = vlayer->dataProvider();
671
672 // verifying specific capabilities
675 {
676 action.error = true;
677 action.errorMsg = u"No capabilities to do WFS inserts on layer '%1'"_s.arg( typeName );
678 continue;
679 }
680
681 // start editing
682 vlayer->startEditing();
683
684 // get inserting features
685 QgsFeatureList featureList;
686 try
687 {
688 featureList = featuresFromGML( action.featureNodeList, vlayer );
689 }
690 catch ( QgsOgcServiceException &ex )
691 {
692 action.error = true;
693 action.errorMsg = u"%1 '%2'"_s.arg( ex.message(), typeName );
694 continue;
695 }
696
697 if ( featureList.empty() )
698 {
699 action.error = true;
700 action.errorMsg = u"No features to insert in layer '%1'"_s.arg( typeName );
701 continue;
702 }
703
704#ifdef HAVE_SERVER_PYTHON_PLUGINS
705 // control features
706 if ( accessControl )
707 {
708 QgsFeatureList::iterator featureIt = featureList.begin();
709 while ( featureIt != featureList.end() )
710 {
711 if ( !accessControl->allowToEdit( vlayer, *featureIt ) )
712 {
713 action.error = true;
714 action.errorMsg = u"Feature modify permission denied on layer '%1'"_s.arg( typeName );
715 vlayer->rollBack();
716 break;
717 }
718 featureIt++;
719 }
720 }
721#endif
722 if ( action.error )
723 {
724 continue;
725 }
726
727 // perform add features
728 if ( !provider->addFeatures( featureList ) )
729 {
730 action.error = true;
731 action.errorMsg = u"Insert features failed on layer '%1'"_s.arg( typeName );
732 if ( provider->hasErrors() )
733 {
734 provider->clearErrors();
735 }
736 vlayer->rollBack();
737 continue;
738 }
739
740 // Commit the changes of the update elements
741 if ( !vlayer->commitChanges() )
742 {
743 action.error = true;
744 action.errorMsg = u"Error committing inserts: %1"_s.arg( vlayer->commitErrors().join( "; "_L1 ) );
745 vlayer->rollBack();
746 continue;
747 }
748 // all changes are OK!
749 action.error = false;
750
751 // Get the Feature Ids of the inserted feature
752 QgsAttributeList pkAttributes = provider->pkAttributeIndexes();
753 for ( const QgsFeature &feat : std::as_const( featureList ) )
754 {
755 action.insertFeatureIds << u"%1.%2"_s.arg( typeName, QgsServerFeatureId::getServerFid( feat, pkAttributes ) );
756 }
757 }
758
759 //force restoration of original layer filters
760 filterRestorer.reset();
761 }
762
763 QgsFeatureList featuresFromGML( QDomNodeList featureNodeList, QgsVectorLayer *layer )
764 {
765 // Store the inserted features
766 QgsFeatureList featList;
767
768 const auto provider { layer->dataProvider() };
769 Q_ASSERT( provider );
770
771 // Get Layer Field Information
772 QgsFields fields = provider->fields();
773 const QMap<QString, int> fieldMap = provider->fieldNameMap();
774 QMap<QString, int>::const_iterator fieldMapIt;
775
776 for ( int i = 0; i < featureNodeList.count(); i++ )
777 {
778 QgsFeature feat( fields );
779
780 QDomElement featureElem = featureNodeList.at( i ).toElement();
781 QDomNode currentAttributeChild = featureElem.firstChild();
782 bool conversionSuccess = true;
783
784 for ( ; !currentAttributeChild.isNull(); currentAttributeChild = currentAttributeChild.nextSibling() )
785 {
786 QDomElement currentAttributeElement = currentAttributeChild.toElement();
787 QString attrName = currentAttributeElement.localName();
788
789 if ( attrName != "boundedBy"_L1 )
790 {
791 if ( attrName != "geometry"_L1 ) //a normal attribute
792 {
793 fieldMapIt = fieldMap.find( attrName );
794 if ( fieldMapIt == fieldMap.constEnd() )
795 {
796 QgsMessageLog::logMessage( u"Skipping unknown attribute: name=%1"_s.arg( attrName ) );
797 continue;
798 }
799
800 QgsField field = fields.at( fieldMapIt.value() );
801 QString attrValue = currentAttributeElement.text();
802 int attrType = field.type();
803
804 QgsMessageLog::logMessage( u"attr: name=%1 idx=%2 value=%3"_s.arg( attrName ).arg( fieldMapIt.value() ).arg( attrValue ) );
805
806 if ( attrType == QMetaType::Type::Int )
807 feat.setAttribute( fieldMapIt.value(), attrValue.toInt( &conversionSuccess ) );
808 else if ( attrType == QMetaType::Type::Double )
809 feat.setAttribute( fieldMapIt.value(), attrValue.toDouble( &conversionSuccess ) );
810 else
811 feat.setAttribute( fieldMapIt.value(), attrValue );
812
813 if ( !conversionSuccess )
814 {
815 throw QgsRequestNotWellFormedException( u"Property conversion error on layer insert"_s );
816 }
817 }
818 else //a geometry attribute
819 {
820 const QgsOgcUtils::Context context { layer, provider->transformContext() };
821 QgsGeometry g = QgsOgcUtils::geometryFromGML( currentAttributeElement, context );
822 if ( g.isNull() )
823 {
824 throw QgsRequestNotWellFormedException( u"Geometry from GML error on layer insert"_s );
825 }
826 feat.setGeometry( g );
827 }
828 }
829 }
830 // update feature list
831 featList << feat;
832 }
833 return featList;
834 }
835
837 {
838 if ( !parameters.contains( u"OPERATION"_s ) )
839 {
840 throw QgsRequestNotWellFormedException( u"OPERATION parameter is mandatory"_s );
841 }
842 if ( parameters.value( u"OPERATION"_s ).toUpper() != "DELETE"_L1 )
843 {
844 throw QgsRequestNotWellFormedException( u"Only DELETE value is defined for OPERATION parameter"_s );
845 }
846
847 // Verifying parameters mutually exclusive
848 if ( ( parameters.contains( u"FEATUREID"_s ) && ( parameters.contains( u"FILTER"_s ) || parameters.contains( u"BBOX"_s ) ) )
849 || ( parameters.contains( u"FILTER"_s ) && ( parameters.contains( u"FEATUREID"_s ) || parameters.contains( u"BBOX"_s ) ) )
850 || ( parameters.contains( u"BBOX"_s ) && ( parameters.contains( u"FEATUREID"_s ) || parameters.contains( u"FILTER"_s ) ) ) )
851 {
852 throw QgsRequestNotWellFormedException( u"FEATUREID FILTER and BBOX parameters are mutually exclusive"_s );
853 }
854
855 transactionRequest request;
856
857 QStringList typeNameList;
858 // parse FEATUREID
859 if ( parameters.contains( u"FEATUREID"_s ) )
860 {
861 QStringList fidList = parameters.value( u"FEATUREID"_s ).split( ',' );
862
863 QMap<QString, QStringList> fidsMap;
864
865 QStringList::const_iterator fidIt = fidList.constBegin();
866 for ( ; fidIt != fidList.constEnd(); ++fidIt )
867 {
868 // Get FeatureID
869 QString fid = *fidIt;
870 fid = fid.trimmed();
871 // testing typename in the WFS featureID
872 if ( !fid.contains( '.' ) )
873 {
874 throw QgsRequestNotWellFormedException( u"FEATUREID has to have TYPENAME in the values"_s );
875 }
876
877 QString typeName = fid.section( '.', 0, 0 );
878 fid = fid.section( '.', 1, 1 );
879 if ( !typeNameList.contains( typeName ) )
880 {
881 typeNameList << typeName;
882 }
883
884 QStringList fids;
885 if ( fidsMap.contains( typeName ) )
886 {
887 fids = fidsMap.value( typeName );
888 }
889 fids.append( fid );
890 fidsMap.insert( typeName, fids );
891 }
892
893 QMap<QString, QStringList>::const_iterator fidsMapIt = fidsMap.constBegin();
894 for ( ; fidsMapIt != fidsMap.constEnd(); ++fidsMapIt )
895 {
896 transactionDelete action;
897 action.typeName = fidsMapIt.key();
898
899 action.serverFids = fidsMapIt.value();
901
902 request.deletes.append( action );
903 }
904 return request;
905 }
906
907 if ( !parameters.contains( u"TYPENAME"_s ) )
908 {
909 throw QgsRequestNotWellFormedException( u"TYPENAME is mandatory except if FEATUREID is used"_s );
910 }
911
912 typeNameList = parameters.value( u"TYPENAME"_s ).split( ',' );
913
914 // Create actions based on TypeName
915 QStringList::const_iterator typeNameIt = typeNameList.constBegin();
916 for ( ; typeNameIt != typeNameList.constEnd(); ++typeNameIt )
917 {
918 QString typeName = *typeNameIt;
919 typeName = typeName.trimmed();
920
921 transactionDelete action;
922 action.typeName = typeName;
923
924 request.deletes.append( action );
925 }
926
927 // Manage extra parameter exp_filter
928 if ( parameters.contains( u"EXP_FILTER"_s ) )
929 {
930 QString expFilterName = parameters.value( u"EXP_FILTER"_s );
931 QStringList expFilterList;
932 const thread_local QRegularExpression rx( "\\(([^()]+)\\)" );
933 QRegularExpressionMatchIterator matchIt = rx.globalMatch( expFilterName );
934 if ( !matchIt.hasNext() )
935 {
936 expFilterList << expFilterName;
937 }
938 else
939 {
940 while ( matchIt.hasNext() )
941 {
942 const QRegularExpressionMatch match = matchIt.next();
943 if ( match.hasMatch() )
944 {
945 QStringList matches = match.capturedTexts();
946 matches.pop_front(); // remove whole match
947 expFilterList.append( matches );
948 }
949 }
950 }
951
952 // Verifying the 1:1 mapping between TYPENAME and EXP_FILTER but without exception
953 if ( request.deletes.size() == expFilterList.size() )
954 {
955 // set feature request filter expression based on filter element
956 QList<transactionDelete>::iterator dIt = request.deletes.begin();
957 QStringList::const_iterator expFilterIt = expFilterList.constBegin();
958 for ( ; dIt != request.deletes.end(); ++dIt )
959 {
960 transactionDelete &action = *dIt;
961 // Get Filter for this typeName
962 QString expFilter;
963 if ( expFilterIt != expFilterList.constEnd() )
964 {
965 expFilter = *expFilterIt;
966 }
967 std::shared_ptr<QgsExpression> filter( new QgsExpression( expFilter ) );
968 if ( filter )
969 {
970 if ( filter->hasParserError() )
971 {
972 QgsMessageLog::logMessage( filter->parserErrorString() );
973 }
974 else
975 {
976 if ( filter->needsGeometry() )
977 {
979 }
980 action.featureRequest.setFilterExpression( filter->expression() );
981 }
982 }
983 }
984 }
985 else
986 {
987 QgsMessageLog::logMessage( "There has to be a 1:1 mapping between each element in a TYPENAME and the EXP_FILTER list" );
988 }
989 }
990
991 if ( parameters.contains( u"BBOX"_s ) )
992 {
993 // get bbox value
994 QString bbox = parameters.value( u"BBOX"_s );
995 if ( bbox.isEmpty() )
996 {
997 throw QgsRequestNotWellFormedException( u"BBOX parameter is empty"_s );
998 }
999
1000 // get bbox corners
1001 QStringList corners = bbox.split( ',' );
1002 if ( corners.size() != 4 )
1003 {
1004 throw QgsRequestNotWellFormedException( u"BBOX has to be composed of 4 elements: '%1'"_s.arg( bbox ) );
1005 }
1006
1007 // convert corners to double
1008 double d[4];
1009 bool ok;
1010 for ( int i = 0; i < 4; i++ )
1011 {
1012 corners[i].replace( ' ', '+' );
1013 d[i] = corners[i].toDouble( &ok );
1014 if ( !ok )
1015 {
1016 throw QgsRequestNotWellFormedException( u"BBOX has to be composed of 4 double: '%1'"_s.arg( bbox ) );
1017 }
1018 }
1019 // create extent
1020 QgsRectangle extent( d[0], d[1], d[2], d[3] );
1021
1022 // set feature request filter rectangle
1023 QList<transactionDelete>::iterator dIt = request.deletes.begin();
1024 for ( ; dIt != request.deletes.end(); ++dIt )
1025 {
1026 transactionDelete &action = *dIt;
1027 action.featureRequest.setFilterRect( extent );
1028 }
1029 return request;
1030 }
1031 else if ( parameters.contains( u"FILTER"_s ) )
1032 {
1033 QString filterName = parameters.value( u"FILTER"_s );
1034 QStringList filterList;
1035
1036 const thread_local QRegularExpression rx( "\\(([^()]+)\\)" );
1037 QRegularExpressionMatchIterator matchIt = rx.globalMatch( filterName );
1038 if ( !matchIt.hasNext() )
1039 {
1040 filterList << filterName;
1041 }
1042 else
1043 {
1044 while ( matchIt.hasNext() )
1045 {
1046 const QRegularExpressionMatch match = matchIt.next();
1047 if ( match.hasMatch() )
1048 {
1049 QStringList matches = match.capturedTexts();
1050 matches.pop_front(); // remove whole match
1051 filterList.append( matches );
1052 }
1053 }
1054 }
1055
1056 // Verifying the 1:1 mapping between TYPENAME and FILTER
1057 if ( request.deletes.size() != filterList.size() )
1058 {
1059 throw QgsRequestNotWellFormedException( u"There has to be a 1:1 mapping between each element in a TYPENAME and the FILTER list"_s );
1060 }
1061
1062 // set feature request filter expression based on filter element
1063 QList<transactionDelete>::iterator dIt = request.deletes.begin();
1064 QStringList::const_iterator filterIt = filterList.constBegin();
1065 for ( ; dIt != request.deletes.end(); ++dIt )
1066 {
1067 transactionDelete &action = *dIt;
1068
1069 // Get Filter for this typeName
1070 QDomDocument filter;
1071 if ( filterIt != filterList.constEnd() )
1072 {
1073 QString errorMsg;
1074 if ( !filter.setContent( *filterIt, true, &errorMsg ) )
1075 {
1076 throw QgsRequestNotWellFormedException( u"error message: %1. The XML string was: %2"_s.arg( errorMsg, *filterIt ) );
1077 }
1078 }
1079
1080 QDomElement filterElem = filter.firstChildElement();
1081 QStringList serverFids;
1082 action.featureRequest = parseFilterElement( action.typeName, filterElem, serverFids, project );
1083 action.serverFids = serverFids;
1084
1085 if ( filterIt != filterList.constEnd() )
1086 {
1087 ++filterIt;
1088 }
1089 }
1090 return request;
1091 }
1092
1093 return request;
1094 }
1095
1096 transactionRequest parseTransactionRequestBody( QDomElement &docElem, const QgsProject *project )
1097 {
1098 transactionRequest request;
1099
1100 QDomNodeList docChildNodes = docElem.childNodes();
1101
1102 QDomElement actionElem;
1103 QString actionName;
1104
1105 for ( int i = docChildNodes.count(); 0 < i; --i )
1106 {
1107 actionElem = docChildNodes.at( i - 1 ).toElement();
1108 actionName = actionElem.localName();
1109
1110 if ( actionName == "Insert"_L1 )
1111 {
1112 transactionInsert action = parseInsertActionElement( actionElem );
1113 request.inserts.append( action );
1114 }
1115 else if ( actionName == "Update"_L1 )
1116 {
1117 transactionUpdate action = parseUpdateActionElement( actionElem, project );
1118 request.updates.append( action );
1119 }
1120 else if ( actionName == "Delete"_L1 )
1121 {
1122 transactionDelete action = parseDeleteActionElement( actionElem, project );
1123 request.deletes.append( action );
1124 }
1125 }
1126
1127 return request;
1128 }
1129
1130 transactionDelete parseDeleteActionElement( QDomElement &actionElem, const QgsProject *project )
1131 {
1132 QString typeName = actionElem.attribute( u"typeName"_s );
1133 if ( typeName.contains( ':' ) )
1134 typeName = typeName.section( ':', 1, 1 );
1135
1136 QDomElement filterElem = actionElem.firstChild().toElement();
1137 if ( filterElem.tagName() != "Filter"_L1 )
1138 {
1139 throw QgsRequestNotWellFormedException( u"Delete action element first child is not Filter"_s );
1140 }
1141
1142 QStringList serverFids;
1143 QgsFeatureRequest featureRequest = parseFilterElement( typeName, filterElem, serverFids, project );
1144
1145 transactionDelete action;
1146 action.typeName = typeName;
1147 action.featureRequest = featureRequest;
1148 action.serverFids = serverFids;
1149 action.error = false;
1150
1151 if ( actionElem.hasAttribute( u"handle"_s ) )
1152 {
1153 action.handle = actionElem.attribute( u"handle"_s );
1154 }
1155
1156 return action;
1157 }
1158
1159 transactionUpdate parseUpdateActionElement( QDomElement &actionElem, const QgsProject *project )
1160 {
1161 QString typeName = actionElem.attribute( u"typeName"_s );
1162 if ( typeName.contains( ':' ) )
1163 typeName = typeName.section( ':', 1, 1 );
1164
1165 QDomNodeList propertyNodeList = actionElem.elementsByTagName( u"Property"_s );
1166 if ( propertyNodeList.isEmpty() )
1167 {
1168 throw QgsRequestNotWellFormedException( u"Update action element must have one or more Property element"_s );
1169 }
1170
1171 QMap<QString, QString> propertyMap;
1172 QDomElement propertyElem;
1173 QDomElement nameElem;
1174 QDomElement valueElem;
1175 QDomElement geometryElem;
1176
1177 for ( int l = 0; l < propertyNodeList.count(); ++l )
1178 {
1179 propertyElem = propertyNodeList.at( l ).toElement();
1180 nameElem = propertyElem.elementsByTagName( u"Name"_s ).at( 0 ).toElement();
1181 valueElem = propertyElem.elementsByTagName( u"Value"_s ).at( 0 ).toElement();
1182 if ( nameElem.text() != "geometry"_L1 )
1183 {
1184 propertyMap.insert( nameElem.text(), valueElem.text() );
1185 }
1186 else
1187 {
1188 geometryElem = valueElem;
1189 }
1190 }
1191
1192 QDomNodeList filterNodeList = actionElem.elementsByTagName( u"Filter"_s );
1193 QgsFeatureRequest featureRequest;
1194 QStringList serverFids;
1195 if ( filterNodeList.size() != 0 )
1196 {
1197 QDomElement filterElem = filterNodeList.at( 0 ).toElement();
1198 featureRequest = parseFilterElement( typeName, filterElem, serverFids, project );
1199 }
1200
1201 transactionUpdate action;
1202 action.typeName = typeName;
1203 action.propertyMap = propertyMap;
1204 action.geometryElement = geometryElem;
1205 action.featureRequest = std::move( featureRequest );
1206 action.serverFids = serverFids;
1207 action.error = false;
1208
1209 if ( actionElem.hasAttribute( u"handle"_s ) )
1210 {
1211 action.handle = actionElem.attribute( u"handle"_s );
1212 }
1213
1214 return action;
1215 }
1216
1218 {
1219 QDomNodeList featureNodeList = actionElem.childNodes();
1220 if ( featureNodeList.size() != 1 )
1221 {
1222 throw QgsRequestNotWellFormedException( u"Insert action element must have one or more child node"_s );
1223 }
1224
1225 QString typeName;
1226 for ( int i = 0; i < featureNodeList.count(); ++i )
1227 {
1228 QString tempTypeName = featureNodeList.at( i ).toElement().localName();
1229 if ( tempTypeName.contains( ':' ) )
1230 tempTypeName = tempTypeName.section( ':', 1, 1 );
1231
1232 if ( typeName.isEmpty() )
1233 {
1234 typeName = tempTypeName;
1235 }
1236 else if ( tempTypeName != typeName )
1237 {
1238 throw QgsRequestNotWellFormedException( u"Insert action element must have one typename features"_s );
1239 }
1240 }
1241
1242 transactionInsert action;
1243 action.typeName = typeName;
1244 action.featureNodeList = featureNodeList;
1245 action.error = false;
1246
1247 if ( actionElem.hasAttribute( u"handle"_s ) )
1248 {
1249 action.handle = actionElem.attribute( u"handle"_s );
1250 }
1251
1252 return action;
1253 }
1254
1255 namespace
1256 {
1257
1258 void addTransactionResult( QDomDocument &responseDoc, QDomElement &responseElem, const QString &status, const QString &locator, const QString &message )
1259 {
1260 QDomElement trElem = responseDoc.createElement( u"TransactionResult"_s );
1261 QDomElement stElem = responseDoc.createElement( u"Status"_s );
1262 QDomElement successElem = responseDoc.createElement( status );
1263 stElem.appendChild( successElem );
1264 trElem.appendChild( stElem );
1265 responseElem.appendChild( trElem );
1266
1267 if ( !locator.isEmpty() )
1268 {
1269 QDomElement locElem = responseDoc.createElement( u"Locator"_s );
1270 locElem.appendChild( responseDoc.createTextNode( locator ) );
1271 trElem.appendChild( locElem );
1272 }
1273
1274 if ( !message.isEmpty() )
1275 {
1276 QDomElement mesElem = responseDoc.createElement( u"Message"_s );
1277 mesElem.appendChild( responseDoc.createTextNode( message ) );
1278 trElem.appendChild( mesElem );
1279 }
1280 }
1281
1282 } // namespace
1283
1284 } // namespace v1_0_0
1285} // namespace QgsWfs
@ AddFeatures
Allows adding features.
Definition qgis.h:527
@ ChangeGeometries
Allows modifications of geometries.
Definition qgis.h:534
@ DeleteFeatures
Allows deletion of features.
Definition qgis.h:528
@ ChangeAttributeValues
Allows modification of attribute values.
Definition qgis.h:529
@ NoFlags
No flags are set.
Definition qgis.h:2275
QFlags< VectorProviderCapability > VectorProviderCapabilities
Vector data provider capabilities.
Definition qgis.h:562
@ Vector
Vector layer.
Definition qgis.h:207
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...
Definition qgsfeature.h:60
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
QgsFeatureId id
Definition qgsfeature.h:68
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.
Definition qgsfield.h:56
QMetaType::Type type
Definition qgsfield.h:63
QString name
Definition qgsfield.h:65
QgsFieldConstraints constraints
Definition qgsfield.h:68
Container of fields for a vector layer.
Definition qgsfields.h:46
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.
Definition qgsmaplayer.h:83
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
QString id
Definition qgsmaplayer.h:86
Qgis::LayerType type
Definition qgsmaplayer.h:93
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
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,...
Definition qgsproject.h:113
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).
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 in case of malformed request.
Exception thrown when data access violates access controls.
transactionInsert parseInsertActionElement(QDomElement &actionElem)
Transform Insert element to transactionInsert.
transactionDelete parseDeleteActionElement(QDomElement &actionElem, const QgsProject *project)
Transform Delete element to transactionDelete.
void performTransaction(transactionRequest &aRequest, QgsServerInterface *serverIface, const QgsProject *project)
Perform the transaction.
QDomDocument createTransactionDocument(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request)
Create a wfs transaction document.
transactionRequest parseTransactionRequestBody(QDomElement &docElem, const QgsProject *project)
Transform RequestBody root element to getFeatureRequest.
transactionRequest parseTransactionParameters(QgsServerRequest::Parameters parameters, const QgsProject *project)
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
QgsFeatureList featuresFromGML(QDomNodeList featureNodeList, QgsVectorLayer *layer)
Transform GML feature nodes to features.
transactionUpdate parseUpdateActionElement(QDomElement &actionElem, const QgsProject *project)
Transform Update element to transactionUpdate.
WMS implementation.
Definition qgswfs.cpp:39
const QString OGC_NAMESPACE
Definition qgswfsutils.h:75
const QString WFS_NAMESPACE
Definition qgswfsutils.h:73
QgsFeatureRequest parseFilterElement(const QString &typeName, QDomElement &filterElem, QgsProject *project)
Transform a Filter element to a feature request.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7504
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7503
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
QList< int > QgsAttributeList
Definition qgsfield.h:30
The Context struct stores the current layer and coordinate transform context.
Definition qgsogcutils.h:63