Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part of #1885. Add WFS-T update and delete with fid filter #1900

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/client/test-resources/wfst/delete/museam_1_1_0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<wfs:Transaction service="WFS" version="1.1.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" xmlns:tiger="http://www.census.gov"><wfs:Delete typeName="tiger:poi"><ogc:Filter><ogc:FeatureId fid="poi.1"/></ogc:Filter></wfs:Delete></wfs:Transaction>
2 changes: 1 addition & 1 deletion web/client/test-resources/wfst/insert/Wyoming_1_1_0.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<wfs:Transaction service="WFS" version="1.1.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" xmlns:topp="http://www.openplans.org/topp"><wfs:Insert><topp:states><topp:STATE_NAME>Wyoming</topp:STATE_NAME><topp:STATE_FIPS>56</topp:STATE_FIPS><topp:SUB_REGION>Mtn</topp:SUB_REGION><topp:STATE_ABBR>WY</topp:STATE_ABBR><topp:LAND_KM>251500.801</topp:LAND_KM><topp:WATER_KM>1848.149</topp:WATER_KM><topp:PERSONS>453588</topp:PERSONS><topp:FAMILIES>119825</topp:FAMILIES><topp:HOUSHOLD>168839</topp:HOUSHOLD><topp:MALE>227007</topp:MALE><topp:FEMALE>226581</topp:FEMALE><topp:WORKERS>164561</topp:WORKERS><topp:DRVALONE>153679</topp:DRVALONE><topp:CARPOOL>28109</topp:CARPOOL><topp:PUBTRANS>2963</topp:PUBTRANS><topp:EMPLOYED>207868</topp:EMPLOYED><topp:UNEMPLOY>13112</topp:UNEMPLOY><topp:SERVICE>71419</topp:SERVICE><topp:MANUAL>29157</topp:MANUAL><topp:P_MALE>0.5</topp:P_MALE><topp:P_FEMALE>0.5</topp:P_FEMALE><topp:SAMP_POP>83202</topp:SAMP_POP><topp:the_geom><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList>-104.053108 41.698246 -104.054993 41.564247 -104.053505 41.388107 -104.051201 41.003227 -104.933968 40.994305 -105.278259 40.996365 -106.202896 41.000111 -106.328545 41.001316 -106.864838 40.998489 -107.303436 41.000168 -107.918037 41.00341 -109.047638 40.998474 -110.001457 40.997646 -110.062477 40.99794 -111.050285 40.996635 -111.050911 41.25848 -111.050323 41.578648 -111.047951 41.996265 -111.046028 42.503323 -111.048447 43.019962 -111.04673 43.284813 -111.045998 43.515606 -111.049629 43.982632 -111.050789 44.473396 -111.050842 44.664562 -111.05265 44.995766 -110.428894 44.992348 -110.392006 44.998688 -109.994789 45.002853 -109.798653 44.99958 -108.624573 44.997643 -108.258568 45.00016 -107.893715 44.999813 -106.258644 44.996174 -106.020576 44.997227 -105.084465 44.999832 -105.04126 45.001091 -104.059349 44.997349 -104.058975 44.574368 -104.060547 44.181843 -104.059242 44.145844 -104.05899 43.852928 -104.057426 43.503738 -104.05867 43.47916 -104.05571 43.003094 -104.055725 42.614704 -104.053009 41.999851 -104.053108 41.698246</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:polygonMember></gml:MultiPolygon></topp:the_geom></topp:states></wfs:Insert></wfs:Transaction>
<wfs:Transaction service="WFS" version="1.1.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" xmlns:topp="http://www.openplans.org/topp"><wfs:Insert><topp:states><topp:STATE_NAME>Wyoming</topp:STATE_NAME><topp:STATE_FIPS>56</topp:STATE_FIPS><topp:SUB_REGION>Mtn</topp:SUB_REGION><topp:STATE_ABBR>WY</topp:STATE_ABBR><topp:LAND_KM>251500.801</topp:LAND_KM><topp:WATER_KM>1848.149</topp:WATER_KM><topp:PERSONS>453588</topp:PERSONS><topp:FAMILIES>119825</topp:FAMILIES><topp:HOUSHOLD>168839</topp:HOUSHOLD><topp:MALE>227007</topp:MALE><topp:FEMALE>226581</topp:FEMALE><topp:WORKERS>164561</topp:WORKERS><topp:DRVALONE>153679</topp:DRVALONE><topp:CARPOOL>28109</topp:CARPOOL><topp:PUBTRANS>2963</topp:PUBTRANS><topp:EMPLOYED>207868</topp:EMPLOYED><topp:UNEMPLOY>13112</topp:UNEMPLOY><topp:SERVICE>71419</topp:SERVICE><topp:MANUAL>29157</topp:MANUAL><topp:P_MALE>0.5</topp:P_MALE><topp:P_FEMALE>0.5</topp:P_FEMALE><topp:SAMP_POP>83202</topp:SAMP_POP><topp:the_geom><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList>-104.053108 41.698246 -104.054993 41.564247 -104.053505 41.388107 -104.051201 41.003227 -104.933968 40.994305 -105.278259 40.996365 -106.202896 41.000111 -106.328545 41.001316 -106.864838 40.998489 -107.303436 41.000168 -107.918037 41.00341 -109.047638 40.998474 -110.001457 40.997646 -110.062477 40.99794 -111.050285 40.996635 -111.050911 41.25848 -111.050323 41.578648 -111.047951 41.996265 -111.046028 42.503323 -111.048447 43.019962 -111.04673 43.284813 -111.045998 43.515606 -111.049629 43.982632 -111.050789 44.473396 -111.050842 44.664562 -111.05265 44.995766 -110.428894 44.992348 -110.392006 44.998688 -109.994789 45.002853 -109.798653 44.99958 -108.624573 44.997643 -108.258568 45.00016 -107.893715 44.999813 -106.258644 44.996174 -106.020576 44.997227 -105.084465 44.999832 -105.04126 45.001091 -104.059349 44.997349 -104.058975 44.574368 -104.060547 44.181843 -104.059242 44.145844 -104.05899 43.852928 -104.057426 43.503738 -104.05867 43.47916 -104.05571 43.003094 -104.055725 42.614704 -104.053009 41.999851 -104.053108 41.698246</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:polygonMember></gml:MultiPolygon></topp:the_geom></topp:states></wfs:Insert></wfs:Transaction>
2 changes: 1 addition & 1 deletion web/client/test-resources/wfst/insert/museam_1_1_0.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<wfs:Transaction service="WFS" version="1.1.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" xmlns:tiger="http://www.census.gov"><wfs:Insert><tiger:poi><tiger:NAME>museam</tiger:NAME><tiger:THUMBNAIL>pics/22037827-Ti.jpg</tiger:THUMBNAIL><tiger:MAINPAGE>pics/22037827-L.jpg</tiger:MAINPAGE><tiger:the_geom><gml:Point srsDimension="2" srsName="EPSG:4326"><gml:pos>-74.0104611 40.70758763</gml:pos></gml:Point></tiger:the_geom></tiger:poi></wfs:Insert></wfs:Transaction>
<wfs:Transaction service="WFS" version="1.1.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" xmlns:tiger="http://www.census.gov"><wfs:Insert><tiger:poi><tiger:NAME>museam</tiger:NAME><tiger:THUMBNAIL>pics/22037827-Ti.jpg</tiger:THUMBNAIL><tiger:MAINPAGE>pics/22037827-L.jpg</tiger:MAINPAGE><tiger:the_geom><gml:Point srsDimension="2" srsName="EPSG:4326"><gml:pos>-74.0104611 40.70758763</gml:pos></gml:Point></tiger:the_geom></tiger:poi></wfs:Insert></wfs:Transaction>
1 change: 1 addition & 0 deletions web/client/test-resources/wfst/update/museam_1_1_0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<wfs:Transaction service="WFS" version="1.1.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" xmlns:tiger="http://www.census.gov"><wfs:Update typeName="tiger:poi"><wfs:Property><wfs:Name>NAME</wfs:Name><wfs:Value>newName</wfs:Value></wfs:Property><ogc:Filter><ogc:FeatureId fid="poi.7"/></ogc:Filter></wfs:Update></wfs:Transaction>
6 changes: 6 additions & 0 deletions web/client/utils/ogc/Filter/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const fidFilter = (fid) =>
`<ogc:Filter><ogc:FeatureId fid="${fid}"/></ogc:Filter>`;

module.exports = {
fidFilter
};
File renamed without changes.
27 changes: 27 additions & 0 deletions web/client/utils/ogc/WFST/v1_1_0/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/


const {fidFilter} = require('../../Filter/base');
const {getTypeName} = require('../../WFS/base');
/**
* Generate WFS delete features
* @function
* @param {string} content The content of the delete request, e.g. the filter to use
* @param {object} describeFeatureType describeFeatureType object
* @return {string} the XML for the update
*/
const deleteFeatures = (content, typeName) =>
`<wfs:Delete typeName="${typeName}">${content}</wfs:Delete>`;
const deleteById = (fid, typeName) => deleteFeatures(fidFilter(fid), typeName);
const deleteFeature = (feature, describe) => deleteById(feature.features && feature.features.length === 1 ? feature.features[0].id : feature.id, getTypeName(describe));
module.exports = {
deleteFeatures,
deleteById,
deleteFeature
};
8 changes: 7 additions & 1 deletion web/client/utils/ogc/WFST/v1_1_0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
*/
const {transaction} = require('./transaction');
const {insert} = require('./insert');

const {update, property} = require('./update');
const {deleteFeature, deleteFeatures, deleteById} = require('./delete');
module.exports = {
insert,
update,
property,
deleteFeature,
deleteFeatures,
deleteById,
transaction
};
2 changes: 1 addition & 1 deletion web/client/utils/ogc/WFST/v1_1_0/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const feature = (f, describeFeatureType) => `<${getTypeName(describeFeatureType)
const features = (fs, describeFeatureType) => fs.map(f => feature(f, describeFeatureType)).join("");

const insert = (fs, describeFeatureType) => '<wfs:Insert>'
+ `${features(fs.features, describeFeatureType)}`
+ `${features(fs.features || fs, describeFeatureType)}`
+ '</wfs:Insert>';

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions web/client/utils/ogc/WFST/v1_1_0/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const transaction = (operations, schemaLocation) => '<wfs:Transaction '
+ 'version="1.1.0" '
+ 'xmlns:wfs="http://www.opengis.net/wfs" '
+ 'xmlns:gml="http://www.opengis.net/gml" '
+ 'xmlns:ogc="http://www.opengis.net/ogc" '
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+ 'xsi:schemaLocation="http://www.opengis.net/wfs '
+ 'http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" '
Expand Down
26 changes: 26 additions & 0 deletions web/client/utils/ogc/WFST/v1_1_0/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const {getTypeName} = require("../../WFS/base");

const property = (propName, value) => '<wfs:Property>'
+ `<wfs:Name>${propName}</wfs:Name>`
+ `<wfs:Value>${value}</wfs:Value>`
+ '</wfs:Property>';

/**
* Generate update XML.
* @function
* @param {string} content the properties to update and/or features to use (inXML)
* @param {object} describeFeatureType describeFeatureType object
* @return {string} the XML for the update
*/
const update = (content, describeFeatureType) => `<wfs:Update typeName="${getTypeName(describeFeatureType)}">${Array.isArray(content) ? content.join("") : content}</wfs:Update>`;
module.exports = {
update,
property
};
19 changes: 17 additions & 2 deletions web/client/utils/ogc/__tests__/WFS-T-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
*/

const expect = require('expect');
const {insert, transaction} = require('../WFST');
const {insert, update, property, deleteFeature, transaction} = require('../WFST');
const {fidFilter} = require('../Filter/base');
const {featureTypeSchema} = require('../WFS/base');
const describeStates = require('json-loader!../../../test-resources/wfs/describe-states.json');
const describePois = require('json-loader!../../../test-resources/wfs/describe-pois.json');
const wyoming = require('json-loader!../../../test-resources/wfs/Wyoming.json');
const museam = require('json-loader!../../../test-resources/wfs/museam.json');
const expectedInsertWyoming = require('raw-loader!../../../test-resources/wfst/insert/Wyoming_1_1_0.xml');
const expectedInsertmuseam = require('raw-loader!../../../test-resources/wfst/insert/museam_1_1_0.xml');

const expectedDelete = require('raw-loader!../../../test-resources/wfst/delete/museam_1_1_0.xml');
const expectedUpdate = require('raw-loader!../../../test-resources/wfst/update/museam_1_1_0.xml');
describe('Test WFS-T request bodies generation', () => {
it('WFS-T insert', () => {
const result = insert(wyoming, describeStates);
Expand All @@ -36,4 +38,17 @@ describe('Test WFS-T request bodies generation', () => {
expect(result).toExist();
expect(result + '\n').toEqual(expectedInsertmuseam);
});
it('WFS-T transaction with delete', () => {
const result = transaction([deleteFeature(museam, describePois)], featureTypeSchema(describePois));
expect(result).toExist();
expect(result + '\n').toEqual(expectedDelete);
});
it('WFS-T transaction with update', () => {
const result = transaction(
[update([property("NAME", "newName"), fidFilter("poi.7")], describePois)
],
featureTypeSchema(describePois));
expect(result).toExist();
expect(result + '\n').toEqual(expectedUpdate);
});
});