Add Insert, Update and Delete writers

This change also adds some type annotations for better type
checking, introduces different write options for writing
transactions and queries, and provides new writeGetFeature and
writeTransaction methods.
This commit is contained in:
ahocevar
2013-12-06 10:57:58 +01:00
parent f539eb140f
commit b3b9add06e
5 changed files with 324 additions and 66 deletions

View File

@@ -19,17 +19,15 @@ describe('ol.parser.ogc.WFS', function() {
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);
var output = p.writeGetFeature({
featureNS: 'http://www.openplans.org/topp',
featureTypes: ['states'],
featurePrefix: 'topp',
handle: 'handle_g',
maxFeatures: 1,
outputFormat: 'json'
});
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
done();
});
});
@@ -38,12 +36,44 @@ describe('ol.parser.ogc.WFS', function() {
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);
var output = p.writeTransaction(null, null, null, {handle: 'handle_t'});
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
done();
});
});
it('handles writing out transactions', function(done) {
var url = 'spec/ol/parser/ogc/xml/wfs_v1/TransactionMulti.xml';
afterLoadXml(url, function(xml) {
var parser = new ol.parser.ogc.WFS_v1_0_0();
var insertFeature = new ol.Feature({
the_geom: new ol.geom.MultiPoint([[1, 2]]),
foo: 'bar',
nul: null
});
var inserts = [insertFeature];
var updateFeature = new ol.Feature({
the_geom: new ol.geom.MultiPoint([[1, 2]]),
foo: 'bar',
// null value gets Property element with no Value
nul: null,
// undefined value means don't create a Property element
unwritten: undefined
});
updateFeature.setId('fid.42');
var updates = [updateFeature];
var deleteFeature = new ol.Feature();
deleteFeature.setId('fid.37');
var deletes = [deleteFeature];
var output = parser.writeTransaction(inserts, updates, deletes, {
featureNS: 'http://www.openplans.org/topp',
featureType: 'states',
featurePrefix: 'topp'
});
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
done();
});
});
@@ -52,7 +82,7 @@ describe('ol.parser.ogc.WFS', function() {
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: [{
var output = p.writeTransaction(null, null, null, {nativeElements: [{
vendorId: 'ORACLE',
safeToIgnore: true,
value: 'ALTER SESSION ENABLE PARALLEL DML'
@@ -70,14 +100,12 @@ describe('ol.parser.ogc.WFS', function() {
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);
var output = p.writeGetFeature({
featureNS: 'http://www.openplans.org/topp',
featureTypes: ['states', 'cities'],
featurePrefix: 'topp'
});
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
done();
});
});
@@ -87,6 +115,8 @@ describe('ol.parser.ogc.WFS', function() {
});
goog.require('goog.dom.xml');
goog.require('ol.Feature');
goog.require('ol.geom.MultiPoint');
goog.require('ol.parser.ogc.WFS');
goog.require('ol.parser.ogc.WFS_v1_0_0');
goog.require('ol.parser.ogc.WFS_v1_1_0');