From c9569ed9e240d2af6f27b7b82b025b9e63472d2b Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 24 Oct 2013 14:51:04 +0200 Subject: [PATCH] more tests and typedefs. Once feature editing is more stable, this format can be extended with Update, Delete and Insert --- src/objectliterals.jsdoc | 11 ++- src/ol/parser/ogc/wfsparser_v1.js | 43 ++++++++++- test/spec/ol/parser/ogc/wfs_v1.test.js | 71 +++++++++++++++++++ .../ol/parser/ogc/xml/wfs_v1/GetFeature.xml | 3 + .../ogc/xml/wfs_v1/GetFeatureMultiple.xml | 4 ++ test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml | 1 + .../ol/parser/ogc/xml/wfs_v1/Transaction.xml | 1 + 7 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 test/spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml create mode 100644 test/spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml create mode 100644 test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml create mode 100644 test/spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index ef153d8169..1de0782977 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -597,9 +597,16 @@ /** * @typedef {Object} ol.parser.WFSOptions + * @property {string} featureNS The feature namespace to use. + * @property {string} featurePrefix The prefix for the namespace. * @property {Array.} featureTypes The feature types to use. - * @property {string} featureNS The featureNS to use. - * @property {string} featurePrefix The prefix to use for the featureNS. + */ + +/** + * @typedef {Object} ol.parser.WFSNative + * @property {string} vendorId The vendor id to use. + * @property {boolean} safeToIgnore Is it safe to ignore? + * @property {string} value The value of the Native element. */ /** diff --git a/src/ol/parser/ogc/wfsparser_v1.js b/src/ol/parser/ogc/wfsparser_v1.js index d4ea23f0d1..fff9f4fba2 100644 --- a/src/ol/parser/ogc/wfsparser_v1.js +++ b/src/ol/parser/ogc/wfsparser_v1.js @@ -21,6 +21,7 @@ ol.parser.ogc.WFS_v1 = function() { this.writers = {}; this.writers[this.defaultNamespaceURI] = { 'GetFeature': function(options) { + options = /** @type {ol.parser.WFSOptions} */(options); var node = this.createElementNS('wfs:GetFeature'); node.setAttribute('service', 'WFS'); node.setAttribute('version', this.version); @@ -43,6 +44,46 @@ ol.parser.ogc.WFS_v1 = function() { node, 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', this.schemaLocation); return {node: node, options: options}; + }, + 'Transaction': function(obj) { + obj = obj || {}; + var options = obj.options || {}; + var node = this.createElementNS('wfs:Transaction'); + node.setAttribute('service', 'WFS'); + node.setAttribute('version', this.version); + if (goog.isDef(options.handle)) { + node.setAttribute('handle', options.handle); + } + var i, ii; + var features = obj.features; + if (goog.isDefAndNotNull(features)) { + // TODO implement multi option for geometry types + var name, feature; + for (i = 0, ii = features.length; i < ii; ++i) { + feature = features[i]; + // TODO Update (use feature.getOriginal()) + // TODO Insert and Delete + if (goog.isDef(name)) { + this.writeNode(name, { + feature: feature, + options: options + }, null, node); + } + } + } + if (goog.isDef(options.nativeElements)) { + for (i = 0, ii = options.nativeElements.length; i < ii; ++i) { + this.writeNode('Native', options.nativeElements[i], null, node); + } + } + return node; + }, + 'Native': function(nativeElement) { + var node = this.createElementNS('wfs:Native'); + node.setAttribute('vendorId', nativeElement.vendorId); + node.setAttribute('safeToIgnore', nativeElement.safeToIgnore); + node.appendChild(this.createTextNode(nativeElement.value)); + return node; } }; goog.base(this); @@ -115,7 +156,7 @@ ol.parser.ogc.WFS_v1.prototype.read = function(data) { * @return {string} A serialized WFS transaction. */ ol.parser.ogc.WFS_v1.prototype.write = function(features, options) { - var root = this.writeNode('wfs:Transaction', {features: features, + var root = this.writeNode('Transaction', {features: features, options: options}); this.setAttributeNS( root, 'http://www.w3.org/2001/XMLSchema-instance', diff --git a/test/spec/ol/parser/ogc/wfs_v1.test.js b/test/spec/ol/parser/ogc/wfs_v1.test.js index db767e5fc0..a64b00b203 100644 --- a/test/spec/ol/parser/ogc/wfs_v1.test.js +++ b/test/spec/ol/parser/ogc/wfs_v1.test.js @@ -15,9 +15,80 @@ describe('ol.parser.ogc.WFS', function() { }); }); + it('handles writing out GetFeature with a handle', function(done) { + var url = 'spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml'; + afterLoadXml(url, function(xml) { + var p = new ol.parser.ogc.WFS_v1_0_0(); + var output = p.writers[p.defaultNamespaceURI]['GetFeature']. + apply(p, [{ + featureNS: 'http://www.openplans.org/topp', + featureTypes: ['states'], + featurePrefix: 'topp', + handle: 'handle_g', + maxFeatures: 1, + outputFormat: 'json' + } + ]); + expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml); + done(); + }); + }); + + it('handles writing out Transaction with a handle', function(done) { + var url = 'spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml'; + afterLoadXml(url, function(xml) { + var p = new ol.parser.ogc.WFS_v1_0_0(); + var output = p.writers[p.defaultNamespaceURI]['Transaction']. + apply(p, [{ + options: {handle: 'handle_t'} + } + ]); + expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml); + done(); + }); + }); + + it('handles writing out Native', function(done) { + var url = 'spec/ol/parser/ogc/xml/wfs_v1/Native.xml'; + afterLoadXml(url, function(xml) { + var p = new ol.parser.ogc.WFS_v1_1_0(); + var output = p.write(null, { + nativeElements: [{ + vendorId: 'ORACLE', + safeToIgnore: true, + value: 'ALTER SESSION ENABLE PARALLEL DML' + }, { + vendorId: 'ORACLE', + safeToIgnore: false, + value: 'Another native line goes here' + }] + }); + expect(goog.dom.xml.loadXml(output)).to.xmleql(xml); + done(); + }); + }); + + it('handles writing out GetFeature with > 1 typename', function(done) { + var url = 'spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml'; + afterLoadXml(url, function(xml) { + var p = new ol.parser.ogc.WFS_v1_0_0(); + var output = p.writers[p.defaultNamespaceURI]['GetFeature']. + apply(p, [{ + featureNS: 'http://www.openplans.org/topp', + featureTypes: ['states', 'cities'], + featurePrefix: 'topp' + } + ]); + expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml); + done(); + }); + }); + }); }); goog.require('goog.dom.xml'); goog.require('ol.parser.ogc.WFS'); +goog.require('ol.parser.ogc.WFS_v1_0_0'); +goog.require('ol.parser.ogc.WFS_v1_1_0'); diff --git a/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml b/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml new file mode 100644 index 0000000000..8d597268c0 --- /dev/null +++ b/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml @@ -0,0 +1,3 @@ + + + diff --git a/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml b/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml new file mode 100644 index 0000000000..e1717ddc38 --- /dev/null +++ b/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml @@ -0,0 +1,4 @@ + + + + diff --git a/test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml b/test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml new file mode 100644 index 0000000000..d3ff10f227 --- /dev/null +++ b/test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml @@ -0,0 +1 @@ +ALTER SESSION ENABLE PARALLEL DMLAnother native line goes here diff --git a/test/spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml b/test/spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml new file mode 100644 index 0000000000..b147dc07f4 --- /dev/null +++ b/test/spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml @@ -0,0 +1 @@ +