@@ -36,7 +36,7 @@ namespace QgsWfs
36
36
{
37
37
namespace
38
38
{
39
- void addTransactionResult ( QDomDocument &responseDoc, QDomElement &responseElem, const QString &status ,
39
+ void addTransactionResult ( QDomDocument &responseDoc, QDomElement &resultsElem ,
40
40
const QString &locator, const QString &message );
41
41
}
42
42
@@ -84,110 +84,125 @@ namespace QgsWfs
84
84
// It's time to make the transaction
85
85
// Create the response document
86
86
QDomDocument resp;
87
- // wfs:WFS_TransactionRespone element
88
- QDomElement respElem = resp.createElement ( QStringLiteral ( " WFS_TransactionResponse " )/* wfs:WFS_TransactionResponse */ );
87
+ // wfs:TransactionRespone element
88
+ QDomElement respElem = resp.createElement ( QStringLiteral ( " TransactionResponse " )/* wfs:TransactionResponse */ );
89
89
respElem.setAttribute ( QStringLiteral ( " xmlns" ), WFS_NAMESPACE );
90
90
respElem.setAttribute ( QStringLiteral ( " xmlns:xsi" ), QStringLiteral ( " http://www.w3.org/2001/XMLSchema-instance" ) );
91
- respElem.setAttribute ( QStringLiteral ( " xsi:schemaLocation" ), WFS_NAMESPACE + " http://schemas.opengis.net/wfs/1.0 .0/wfs.xsd" );
91
+ respElem.setAttribute ( QStringLiteral ( " xsi:schemaLocation" ), WFS_NAMESPACE + " http://schemas.opengis.net/wfs/1.1 .0/wfs.xsd" );
92
92
respElem.setAttribute ( QStringLiteral ( " xmlns:ogc" ), OGC_NAMESPACE );
93
- respElem.setAttribute ( QStringLiteral ( " version" ), QStringLiteral ( " 1.0 .0" ) );
93
+ respElem.setAttribute ( QStringLiteral ( " version" ), QStringLiteral ( " 1.1 .0" ) );
94
94
resp.appendChild ( respElem );
95
95
96
+ int totalInserted = 0 ;
97
+ int totalUpdated = 0 ;
98
+ int totalDeleted = 0 ;
96
99
int errorCount = 0 ;
97
- QStringList errorLocators;
98
- QStringList errorMessages;
99
100
100
- QList<transactionUpdate>::iterator tuIt = aRequest.updates .begin ();
101
- for ( ; tuIt != aRequest.updates .end (); ++tuIt )
102
- {
103
- transactionUpdate &action = *tuIt;
104
- if ( action.error )
105
- {
106
- errorCount += 1 ;
107
- if ( action.handle .isEmpty () )
108
- {
109
- errorLocators << QStringLiteral ( " Update:%1" ).arg ( action.typeName );
110
- }
111
- else
112
- {
113
- errorLocators << action.handle ;
114
- }
115
- errorMessages << action.errorMsg ;
116
- }
117
- }
118
-
119
- QList<transactionDelete>::iterator tdIt = aRequest.deletes .begin ();
120
- for ( ; tdIt != aRequest.deletes .end (); ++tdIt )
121
- {
122
- transactionDelete &action = *tdIt;
123
- if ( action.error )
124
- {
125
- errorCount += 1 ;
126
- if ( action.handle .isEmpty () )
127
- {
128
- errorLocators << QStringLiteral ( " Delete:%1" ).arg ( action.typeName );
129
- }
130
- else
131
- {
132
- errorLocators << action.handle ;
133
- }
134
- errorMessages << action.errorMsg ;
135
- }
136
- }
101
+ // wfs:TransactionResults element
102
+ QDomElement trsElem = doc.createElement ( QStringLiteral ( " TransactionResults" ) );
137
103
104
+ // wfs:InsertResults element
105
+ QDomElement irsElem = doc.createElement ( QStringLiteral ( " InsertResults" ) );
138
106
QList<transactionInsert>::iterator tiIt = aRequest.inserts .begin ();
139
107
for ( ; tiIt != aRequest.inserts .end (); ++tiIt )
140
108
{
141
109
transactionInsert &action = *tiIt;
142
110
if ( action.error )
143
111
{
144
112
errorCount += 1 ;
145
- if ( action.handle .isEmpty () )
146
- {
147
- errorLocators << QStringLiteral ( " Insert:%1" ).arg ( action.typeName );
148
- }
149
- else
113
+ QString locator = action.handle ;
114
+ if ( locator.isEmpty () )
150
115
{
151
- errorLocators << action.handle ;
116
+ locator = QStringLiteral ( " Insert:%1 " ). arg ( action.typeName ) ;
152
117
}
153
- errorMessages << action.errorMsg ;
118
+ addTransactionResult ( resp, trsElem, locator, action.errorMsg ) ;
154
119
}
155
120
else
156
121
{
157
122
QStringList::const_iterator fidIt = action.insertFeatureIds .constBegin ();
158
123
for ( ; fidIt != action.insertFeatureIds .constEnd (); ++fidIt )
159
124
{
160
125
QString fidStr = *fidIt;
161
- QDomElement irElem = doc.createElement ( QStringLiteral ( " InsertResult " ) );
126
+ QDomElement irElem = doc.createElement ( QStringLiteral ( " Feature " ) );
162
127
if ( !action.handle .isEmpty () )
163
128
{
164
129
irElem.setAttribute ( QStringLiteral ( " handle" ), action.handle );
165
130
}
166
131
QDomElement fiElem = doc.createElement ( QStringLiteral ( " ogc:FeatureId" ) );
167
132
fiElem.setAttribute ( QStringLiteral ( " fid" ), fidStr );
168
133
irElem.appendChild ( fiElem );
169
- respElem .appendChild ( irElem );
134
+ irsElem .appendChild ( irElem );
170
135
}
171
136
}
137
+ totalInserted += action.insertFeatureIds .count ();
172
138
}
173
139
174
- // addTransactionResult
175
- if ( errorCount == 0 )
176
- {
177
- addTransactionResult ( resp, respElem, QStringLiteral ( " SUCCESS" ), QString (), QString () );
178
- }
179
- else
140
+ QList<transactionUpdate>::iterator tuIt = aRequest.updates .begin ();
141
+ for ( ; tuIt != aRequest.updates .end (); ++tuIt )
180
142
{
181
- QString locator = errorLocators.join ( QStringLiteral ( " ; " ) );
182
- QString message = errorMessages.join ( QStringLiteral ( " ; " ) );
183
- if ( errorCount != actionCount )
143
+ transactionUpdate &action = *tuIt;
144
+ if ( action.error )
184
145
{
185
- addTransactionResult ( resp, respElem, QStringLiteral ( " PARTIAL" ), locator, message );
146
+ errorCount += 1 ;
147
+ QString locator = action.handle ;
148
+ if ( locator.isEmpty () )
149
+ {
150
+ locator = QStringLiteral ( " Update:%1" ).arg ( action.typeName );
151
+ }
152
+ addTransactionResult ( resp, trsElem, locator, action.errorMsg );
186
153
}
187
- else
154
+ totalUpdated += action.totalUpdated ;
155
+ }
156
+
157
+ QList<transactionDelete>::iterator tdIt = aRequest.deletes .begin ();
158
+ for ( ; tdIt != aRequest.deletes .end (); ++tdIt )
159
+ {
160
+ transactionDelete &action = *tdIt;
161
+ if ( action.error )
188
162
{
189
- addTransactionResult ( resp, respElem, QStringLiteral ( " ERROR" ), locator, message );
163
+ errorCount += 1 ;
164
+ QString locator = action.handle ;
165
+ if ( locator.isEmpty () )
166
+ {
167
+ locator = QStringLiteral ( " Delete:%1" ).arg ( action.typeName );
168
+ }
169
+ addTransactionResult ( resp, trsElem, locator, action.errorMsg );
190
170
}
171
+ totalDeleted += action.totalDeleted ;
172
+ }
173
+
174
+ // wfs:TransactionSummary element
175
+ QDomElement summaryElem = doc.createElement ( QStringLiteral ( " TransactionSummary" ) );
176
+ if ( aRequest.inserts .size () > 0 )
177
+ {
178
+ QDomElement totalInsertedElem = doc.createElement ( QStringLiteral ( " TotalInserted" ) );
179
+ totalInsertedElem.appendChild ( doc.createTextNode ( QString::number ( totalInserted ) ) );
180
+ summaryElem.appendChild ( totalInsertedElem );
181
+ }
182
+ if ( aRequest.updates .size () > 0 )
183
+ {
184
+ QDomElement totalUpdatedElem = doc.createElement ( QStringLiteral ( " TotalUpdated" ) );
185
+ totalUpdatedElem.appendChild ( doc.createTextNode ( QString::number ( totalUpdated ) ) );
186
+ summaryElem.appendChild ( totalUpdatedElem );
187
+ }
188
+ if ( aRequest.deletes .size () > 0 )
189
+ {
190
+ QDomElement totalDeletedElem = doc.createElement ( QStringLiteral ( " TotalDeleted" ) );
191
+ totalDeletedElem.appendChild ( doc.createTextNode ( QString::number ( totalDeleted ) ) );
192
+ summaryElem.appendChild ( totalDeletedElem );
193
+ }
194
+ respElem.appendChild ( summaryElem );
195
+
196
+ // add TransactionResults
197
+ if ( errorCount > 0 && trsElem.hasChildNodes () )
198
+ {
199
+ respElem.appendChild ( trsElem );
200
+ }
201
+
202
+ // add InsertResults
203
+ if ( aRequest.inserts .size () > 0 && irsElem.hasChildNodes () )
204
+ {
205
+ respElem.appendChild ( irsElem );
191
206
}
192
207
return resp;
193
208
}
@@ -356,6 +371,7 @@ namespace QgsWfs
356
371
// get iterator
357
372
QgsFeatureIterator fit = vlayer->getFeatures ( featureRequest );
358
373
QgsFeature feature;
374
+ int totalUpdated = 0 ;
359
375
// get action properties
360
376
QMap<QString, QString> propertyMap = action.propertyMap ;
361
377
QDomElement geometryElem = action.geometryElement ;
@@ -433,6 +449,7 @@ namespace QgsWfs
433
449
break ;
434
450
}
435
451
}
452
+ totalUpdated += 1 ;
436
453
}
437
454
if ( action.error )
438
455
{
@@ -467,6 +484,7 @@ namespace QgsWfs
467
484
continue ;
468
485
}
469
486
// all the changes are OK!
487
+ action.totalUpdated = totalUpdated;
470
488
action.error = false ;
471
489
472
490
}
@@ -564,6 +582,7 @@ namespace QgsWfs
564
582
continue ;
565
583
}
566
584
// all the changes are OK!
585
+ action.totalDeleted = fids.count ();
567
586
action.error = false ;
568
587
}
569
588
@@ -1159,21 +1178,15 @@ namespace QgsWfs
1159
1178
namespace
1160
1179
{
1161
1180
1162
- void addTransactionResult ( QDomDocument &responseDoc, QDomElement &responseElem, const QString &status ,
1181
+ void addTransactionResult ( QDomDocument &responseDoc, QDomElement &resultsElem ,
1163
1182
const QString &locator, const QString &message )
1164
1183
{
1165
- QDomElement trElem = responseDoc.createElement ( QStringLiteral ( " TransactionResult" ) );
1166
- QDomElement stElem = responseDoc.createElement ( QStringLiteral ( " Status" ) );
1167
- QDomElement successElem = responseDoc.createElement ( status );
1168
- stElem.appendChild ( successElem );
1169
- trElem.appendChild ( stElem );
1170
- responseElem.appendChild ( trElem );
1184
+ QDomElement trElem = responseDoc.createElement ( QStringLiteral ( " Action" ) );
1185
+ resultsElem.appendChild ( trElem );
1171
1186
1172
1187
if ( !locator.isEmpty () )
1173
1188
{
1174
- QDomElement locElem = responseDoc.createElement ( QStringLiteral ( " Locator" ) );
1175
- locElem.appendChild ( responseDoc.createTextNode ( locator ) );
1176
- trElem.appendChild ( locElem );
1189
+ trElem.setAttribute ( QStringLiteral ( " locator" ), locator );
1177
1190
}
1178
1191
1179
1192
if ( !message.isEmpty () )
0 commit comments