Refactor transaction serialization
This commit is contained in:
+54
-73
@@ -529,12 +529,11 @@ class WFS extends XMLFeature {
|
|||||||
const objectStack = [];
|
const objectStack = [];
|
||||||
const version = options.version ? options.version : this.version_;
|
const version = options.version ? options.version : this.version_;
|
||||||
const node = createElementNS(WFSNS[version], 'Transaction');
|
const node = createElementNS(WFSNS[version], 'Transaction');
|
||||||
const gmlVersion = version === '1.0.0' ? 2 : 3;
|
|
||||||
node.setAttribute('service', 'WFS');
|
node.setAttribute('service', 'WFS');
|
||||||
node.setAttribute('version', version);
|
node.setAttribute('version', version);
|
||||||
let baseObj;
|
let baseObj;
|
||||||
/** @type {import("../xml.js").NodeStackItem} */
|
/** @type {import("../xml.js").NodeStackItem} */
|
||||||
let obj;
|
|
||||||
if (options) {
|
if (options) {
|
||||||
baseObj = options.gmlOptions ? options.gmlOptions : {};
|
baseObj = options.gmlOptions ? options.gmlOptions : {};
|
||||||
if (options.handle) {
|
if (options.handle) {
|
||||||
@@ -546,85 +545,23 @@ class WFS extends XMLFeature {
|
|||||||
'xsi:schemaLocation',
|
'xsi:schemaLocation',
|
||||||
SCHEMA_LOCATIONS[version]
|
SCHEMA_LOCATIONS[version]
|
||||||
);
|
);
|
||||||
const featurePrefix = options.featurePrefix
|
|
||||||
? options.featurePrefix
|
const request = createTransactionRequest(node, baseObj, version, options);
|
||||||
: FEATURE_PREFIX;
|
|
||||||
if (inserts) {
|
if (inserts) {
|
||||||
obj = assign(
|
serializeTransactionRequest('Insert', inserts, objectStack, request);
|
||||||
{node},
|
|
||||||
{
|
|
||||||
version,
|
|
||||||
'featureNS': options.featureNS,
|
|
||||||
'featureType': options.featureType,
|
|
||||||
'featurePrefix': featurePrefix,
|
|
||||||
'gmlVersion': gmlVersion,
|
|
||||||
'hasZ': options.hasZ,
|
|
||||||
'srsName': options.srsName,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assign(obj, baseObj);
|
|
||||||
pushSerializeAndPop(
|
|
||||||
obj,
|
|
||||||
TRANSACTION_SERIALIZERS,
|
|
||||||
makeSimpleNodeFactory('Insert'),
|
|
||||||
inserts,
|
|
||||||
objectStack
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (updates) {
|
if (updates) {
|
||||||
obj = assign(
|
serializeTransactionRequest('Update', updates, objectStack, request);
|
||||||
{node},
|
|
||||||
{
|
|
||||||
version,
|
|
||||||
'featureNS': options.featureNS,
|
|
||||||
'featureType': options.featureType,
|
|
||||||
'featurePrefix': featurePrefix,
|
|
||||||
'gmlVersion': gmlVersion,
|
|
||||||
'hasZ': options.hasZ,
|
|
||||||
'srsName': options.srsName,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assign(obj, baseObj);
|
|
||||||
pushSerializeAndPop(
|
|
||||||
obj,
|
|
||||||
TRANSACTION_SERIALIZERS,
|
|
||||||
makeSimpleNodeFactory('Update'),
|
|
||||||
updates,
|
|
||||||
objectStack
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (deletes) {
|
if (deletes) {
|
||||||
pushSerializeAndPop(
|
serializeTransactionRequest('Delete', deletes, objectStack, request);
|
||||||
{
|
|
||||||
node,
|
|
||||||
version,
|
|
||||||
'featureNS': options.featureNS,
|
|
||||||
'featureType': options.featureType,
|
|
||||||
'featurePrefix': featurePrefix,
|
|
||||||
'gmlVersion': gmlVersion,
|
|
||||||
'srsName': options.srsName,
|
|
||||||
},
|
|
||||||
TRANSACTION_SERIALIZERS,
|
|
||||||
makeSimpleNodeFactory('Delete'),
|
|
||||||
deletes,
|
|
||||||
objectStack
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (options.nativeElements) {
|
if (options.nativeElements) {
|
||||||
pushSerializeAndPop(
|
serializeTransactionRequest(
|
||||||
{
|
'Native',
|
||||||
node,
|
|
||||||
version,
|
|
||||||
'featureNS': options.featureNS,
|
|
||||||
'featureType': options.featureType,
|
|
||||||
'featurePrefix': featurePrefix,
|
|
||||||
'gmlVersion': gmlVersion,
|
|
||||||
'srsName': options.srsName,
|
|
||||||
},
|
|
||||||
TRANSACTION_SERIALIZERS,
|
|
||||||
makeSimpleNodeFactory('Native'),
|
|
||||||
options.nativeElements,
|
options.nativeElements,
|
||||||
objectStack
|
objectStack,
|
||||||
|
request
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
@@ -668,6 +605,50 @@ class WFS extends XMLFeature {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Element} node Node.
|
||||||
|
* @param {*} baseObj Base object.
|
||||||
|
* @param {string} version Version.
|
||||||
|
* @param {WriteTransactionOptions} options Options.
|
||||||
|
* @return {Object} Request object.
|
||||||
|
*/
|
||||||
|
function createTransactionRequest(node, baseObj, version, options) {
|
||||||
|
const featurePrefix = options.featurePrefix
|
||||||
|
? options.featurePrefix
|
||||||
|
: FEATURE_PREFIX;
|
||||||
|
const gmlVersion = version === '1.0.0' ? 2 : 3;
|
||||||
|
const obj = assign(
|
||||||
|
{node},
|
||||||
|
{
|
||||||
|
version,
|
||||||
|
'featureNS': options.featureNS,
|
||||||
|
'featureType': options.featureType,
|
||||||
|
'featurePrefix': featurePrefix,
|
||||||
|
'gmlVersion': gmlVersion,
|
||||||
|
'hasZ': options.hasZ,
|
||||||
|
'srsName': options.srsName,
|
||||||
|
},
|
||||||
|
baseObj
|
||||||
|
);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} type Request type.
|
||||||
|
* @param {Array<import("../Feature.js").default>} features Features.
|
||||||
|
* @param {Array<*>} objectStack Object stack.
|
||||||
|
* @param {Element} request Transaction Request.
|
||||||
|
*/
|
||||||
|
function serializeTransactionRequest(type, features, objectStack, request) {
|
||||||
|
pushSerializeAndPop(
|
||||||
|
request,
|
||||||
|
TRANSACTION_SERIALIZERS,
|
||||||
|
makeSimpleNodeFactory(type),
|
||||||
|
features,
|
||||||
|
objectStack
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Element} node Node.
|
* @param {Element} node Node.
|
||||||
* @param {Array<*>} objectStack Object stack.
|
* @param {Array<*>} objectStack Object stack.
|
||||||
|
|||||||
Reference in New Issue
Block a user