Skip to content

Commit

Permalink
Fixed geosolutions-it#1263. Updated WFST functionalities.
Browse files Browse the repository at this point in the history
 - externalized, functionalized and tested ogc operators
 - improved WFS-T functions
  • Loading branch information
offtherailz committed Jun 6, 2017
1 parent ea63593 commit 2b11bb8
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 237 deletions.
386 changes: 167 additions & 219 deletions web/client/utils/FilterUtils.jsx

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions web/client/utils/__tests__/FilterUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,6 @@ describe('FilterUtils', () => {
+ '</ogc:Function></ogc:Function>'
+ "</ogc:Intersects>";

// this is a workarround for this issue : https://github.com/geosolutions-it/MapStore2/issues/1263
// please remove when fixed
FilterUtils.nsplaceholder = "ogc";
FilterUtils.setOperatorsPlaceholders("{namespace}");

let filter = FilterUtils.processOGCCrossLayerFilter(crossLayerFilterObj);
expect(filter).toEqual(expected);
});
Expand Down
32 changes: 32 additions & 0 deletions web/client/utils/ogc/Filter/__tests__/operators-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.
*/
// Disable ESLint because some of the names to include are not in camel case
const expect = require('expect');
const {ogcComparisonOperators, ogcLogicalOperators} = require('../operators');

describe('Test WFS-T request bodies generation', () => {
it('ogcComparisonOperators', () => {
expect(ogcComparisonOperators["="]("ogc", "TEST")).toBe("<ogc:PropertyIsEqualTo>TEST</ogc:PropertyIsEqualTo>");
expect(ogcComparisonOperators[">"]("ogc", "TEST")).toBe("<ogc:PropertyIsGreaterThan>TEST</ogc:PropertyIsGreaterThan>");
expect(ogcComparisonOperators["<"]("ogc", "TEST")).toBe("<ogc:PropertyIsLessThan>TEST</ogc:PropertyIsLessThan>");
expect(ogcComparisonOperators[">="]("ogc", "TEST")).toBe("<ogc:PropertyIsGreaterThanOrEqualTo>TEST</ogc:PropertyIsGreaterThanOrEqualTo>");
expect(ogcComparisonOperators["<="]("ogc", "TEST")).toBe("<ogc:PropertyIsLessThanOrEqualTo>TEST</ogc:PropertyIsLessThanOrEqualTo>");
expect(ogcComparisonOperators["<>"]("ogc", "TEST")).toBe("<ogc:PropertyIsNotEqualTo>TEST</ogc:PropertyIsNotEqualTo>");
expect(ogcComparisonOperators.like("ogc", "TEST")).toBe('<ogc:PropertyIsLike matchCase="true" wildCard="*" singleChar="." escapeChar="!">TEST</ogc:PropertyIsLike>');
expect(ogcComparisonOperators.ilike("ogc", "TEST")).toBe('<ogc:PropertyIsLike matchCase="false" wildCard="*" singleChar="." escapeChar="!">TEST</ogc:PropertyIsLike>');
expect(ogcComparisonOperators.isNull("ogc", "TEST")).toBe('<ogc:PropertyIsNull>TEST</ogc:PropertyIsNull>');
});
it('ogcLogicalOperators', () => {
const AND = "AND";
const OR = "OR";
const AND_NOT = "AND NOT";
expect(ogcLogicalOperators[AND]("ogc", "TEST")).toBe("<ogc:And>TEST</ogc:And>");
expect(ogcLogicalOperators[OR]("ogc", "TEST")).toBe("<ogc:Or>TEST</ogc:Or>");
expect(ogcLogicalOperators[AND_NOT]("ogc", "TEST")).toBe("<ogc:Not>TEST</ogc:Not>");
});
});
15 changes: 12 additions & 3 deletions web/client/utils/ogc/Filter/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
const fidFilter = (fid) =>
`<ogc:Filter><ogc:FeatureId fid="${fid}"/></ogc:Filter>`;
/**
* 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 filter = (content, ns = "ogc") => `<${ns}:Filter>${Array.isArray(content) ? content.join("") : content}</${ns}:Filter>`;
const fidFilter = (fid, ns = "ogc") =>
filter(`<${ns}:FeatureId fid="${fid}"/>`, ns);

module.exports = {
fidFilter
fidFilter,
filter
};
37 changes: 37 additions & 0 deletions web/client/utils/ogc/Filter/operators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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 ogcComparisonOperators = {
"=": (ns, content) => `<${ns}:PropertyIsEqualTo>${content}</${ns}:PropertyIsEqualTo>`,
">": (ns, content) => `<${ns}:PropertyIsGreaterThan>${content}</${ns}:PropertyIsGreaterThan>`,
"<": (ns, content) => `<${ns}:PropertyIsLessThan>${content}</${ns}:PropertyIsLessThan>`,
">=": (ns, content) => `<${ns}:PropertyIsGreaterThanOrEqualTo>${content}</${ns}:PropertyIsGreaterThanOrEqualTo>`,
"<=": (ns, content) => `<${ns}:PropertyIsLessThanOrEqualTo>${content}</${ns}:PropertyIsLessThanOrEqualTo>`,
"<>": (ns, content) => `<${ns}:PropertyIsNotEqualTo>${content}</${ns}:PropertyIsNotEqualTo>`,
"><": (ns, content) => `<${ns}:PropertyIsBetween>${content}</${ns}:PropertyIsBetween>`,
"like": (ns, content) => `<${ns}:PropertyIsLike matchCase="true" wildCard="*" singleChar="." escapeChar="!">${content}</${ns}:PropertyIsLike>`,
"ilike": (ns, content) => `<${ns}:PropertyIsLike matchCase="false" wildCard="*" singleChar="." escapeChar="!">${content}</${ns}:PropertyIsLike>`,
"isNull": (ns, content) => `<${ns}:PropertyIsNull>${content}</${ns}:PropertyIsNull>`
};
const ogcLogicalOperators = {
"AND": (ns, content) => `<${ns}:And>${content}</${ns}:And>`,
"OR": (ns, content) => `<${ns}:Or>${content}</${ns}:Or>`,
"AND NOT": (ns, content) => `<${ns}:Not>${content}</${ns}:Not>`
};

var ogcSpatialOperators = {
"INTERSECTS": (ns, content) => `<${ns}:Intersects>${content}</${ns}:Intersects>`,
"BBOX": (ns, content) => `<${ns}:BBOX>${content}</${ns}:BBOX>`,
"CONTAINS": (ns, content) => `<${ns}:Contains>${content}</${ns}:Contains>`,
"DWITHIN": (ns, content) => `<${ns}:DWithin>${content}</${ns}:DWithin>`,
"WITHIN": (ns, content) => `<${ns}:Within>${content}</${ns}:Within`
};
module.exports = {
ogcComparisonOperators,
ogcLogicalOperators,
ogcSpatialOperators
};
16 changes: 15 additions & 1 deletion web/client/utils/ogc/WFS/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

const {head, get} = require('lodash');
const {processOGCGeometry} = require("../GML");
/**
* Provides the array of featureType properties
* @param {object} describeFeatureType the describeFeatureType object
* @return {object[]} The array of featuretypes properties
*/
const getFeatureTypeProperties = (describeFeatureType) => get(describeFeatureType, "featureTypes[0].properties");
/**
* Provides the first geometry type found
* @param {object} describeFeatureType the describeFeatureType object
* @return {object} the featureType property
*/
const findGeometryProperty = (describeFeatureType) => head(getFeatureTypeProperties(describeFeatureType).filter( d => d.type.indexOf("gml:") === 0));
/**
* Retrives the descriptor for a property in the describeFeatureType (supports single featureTypes)
* @memberof utils.ogc.WFS
Expand All @@ -17,7 +29,7 @@ const {processOGCGeometry} = require("../GML");
*/
const getPropertyDesciptor = (propName, describeFeatureType) =>
head(
get(describeFeatureType, "featureTypes[0].properties").filter(d => d.name === propName)
getFeatureTypeProperties(describeFeatureType).filter(d => d.name === propName)
);
/**
* @name schemaLocation
Expand Down Expand Up @@ -59,6 +71,8 @@ module.exports = {
return value;
},
getPropertyDesciptor,
findGeometryProperty,
getFeatureTypeProperties,
/**
* retrives the featureTypeName from the describeFeatureType json object.
* It prepends the targetPrefix to the first typename found in the featureTypes array.
Expand Down
6 changes: 3 additions & 3 deletions web/client/utils/ogc/WFST/v1_1_0/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const {getTypeName} = require('../../WFS/base');
* @param {object} describeFeatureType describeFeatureType object
* @return {string} the XML for the update
*/
const deleteFeatures = (content, typeName) =>
const deleteFeaturesByFilter = (content, typeName) =>
`<wfs:Delete typeName="${typeName}">${content}</wfs:Delete>`;
const deleteById = (fid, typeName) => deleteFeatures(fidFilter(fid), typeName);
const deleteById = (fid, typeName) => deleteFeaturesByFilter(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,
deleteFeaturesByFilter,
deleteById,
deleteFeature
};
4 changes: 2 additions & 2 deletions web/client/utils/ogc/WFST/v1_1_0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
const {transaction} = require('./transaction');
const {insert} = require('./insert');
const {update, property} = require('./update');
const {deleteFeature, deleteFeatures, deleteById} = require('./delete');
const {deleteFeature, deleteFeaturesByFilter, deleteById} = require('./delete');
module.exports = {
insert,
update,
property,
deleteFeature,
deleteFeatures,
deleteFeaturesByFilter,
deleteById,
transaction
};
7 changes: 4 additions & 3 deletions web/client/utils/ogc/WFST/v1_1_0/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/

const getAttributeName = (k, d) => d.targetPrefix ? d.targetPrefix + ":" + k : k;
const {getValue, getTypeName, getPropertyDesciptor} = require("../../WFS/base");
const {getValue, getTypeName, getPropertyDesciptor, findGeometryProperty} = require("../../WFS/base");

const attribute = (key, value) => `<${key}>${value}</${key}>`;
const attributes = (f, describeFeatureType) =>
Object.keys(f.properties)
Object.keys(f.properties || [])
.filter(k => getPropertyDesciptor(k, describeFeatureType))
.map((key) => attribute(getAttributeName(key, describeFeatureType), getValue(f.properties[key], key, describeFeatureType)));
const geometryAttribute = (f, describeFeatureType) =>
attribute(getAttributeName(f.geometry_name, describeFeatureType), getValue(f.geometry, f.geometry_name, describeFeatureType));
attribute(getAttributeName(f.geometry_name || findGeometryProperty(describeFeatureType).name, describeFeatureType), getValue(f.geometry, f.geometry_name, describeFeatureType));

const feature = (f, describeFeatureType) => `<${getTypeName(describeFeatureType)}>`
+ (attributes(f, describeFeatureType)
Expand Down
2 changes: 1 addition & 1 deletion web/client/utils/ogc/WFST/v1_1_0/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const transaction = (operations, schemaLocation) => '<wfs:Transaction '
+ 'xsi:schemaLocation="http://www.opengis.net/wfs '
+ 'http://schemas.opengis.net/wfs/1.1.0/WFS-transaction.xsd" '
+ `${schemaLocation}>`
+ `${operations.map((o)=> o)}`
+ `${operations.join("")}`
+ '</wfs:Transaction>';
module.exports = {
transaction
Expand Down

0 comments on commit 2b11bb8

Please sign in to comment.