Skip to content

Commit

Permalink
geosolutions-it#9326 Fixed propertyName override
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Aug 3, 2023
1 parent 08140f1 commit 68dfc3f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
6 changes: 5 additions & 1 deletion web/client/utils/ogc/Filter/FilterBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const {logical, spatial, comparison, literal, propertyName, valueReference, distance, lower, upper, func} = require('./operators');
const {filter, fidFilter} = require('./filter');
const {processOGCGeometry} = require("../GML");
const {castArray} = require('lodash');
// const isValidXML = (value, {filterNS, gmlNS}) => value.indexOf(`<${filterNS}:` === 0) || value.indexOf(`<${gmlNS}:`) === 0;
/**
* Returns OGC Filter Builder. The FilterBuilder returns the method to compose the filter.
Expand Down Expand Up @@ -112,7 +113,10 @@ module.exports = function({filterNS = "ogc", gmlVersion, wfsVersion = "1.1.0"} =
not: logical.not.bind(null, filterNS),
func: func.bind(null, filterNS),
literal: getValue,
propertyName: propName.bind(null, filterNS),
propertyName: (property) =>
castArray(property)
.map(p => propertyName(filterNS, p))
.join(""),
property: function(name) {
return {
equalTo: (value) => comparison.equal(filterNS, propName(filterNS, name), getValue(value)),
Expand Down
9 changes: 8 additions & 1 deletion web/client/utils/ogc/Filter/__tests__/FilterBuilder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,12 @@ describe('FilterBuilder', () => {
+ `<ogc:And>${intersectsElem2}<ogc:Not>${intersectsElem1}</ogc:Not></ogc:And>`
+ `</ogc:Or>`);
});

it('propertyName', () => {
const b = new FilterBuilder();
expect(b.propertyName("PROPERTY")).toBe("<ogc:PropertyName>PROPERTY</ogc:PropertyName>");
});
it('array of propertyNames translated into a sequesnce of propertyName tags', () => {
const b = new FilterBuilder();
expect(b.propertyName(["PROPERTY1", "PROPERTY2"])).toBe("<ogc:PropertyName>PROPERTY1</ogc:PropertyName><ogc:PropertyName>PROPERTY2</ogc:PropertyName>");
});
});
12 changes: 4 additions & 8 deletions web/client/utils/ogc/WFS/RequestBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/
const filterBuilder = require('../Filter/FilterBuilder');
const castArray = require('lodash/castArray');
const {wfsToGmlVersion} = require("./base");
const getStaticAttributesWFS1 = (ver) => 'service="WFS" version="' + ver + '" ' +
(ver === "1.0.0" ? 'outputFormat="GML2" ' : "") +
Expand Down Expand Up @@ -87,16 +86,13 @@ module.exports = function({wfsVersion = "1.1.0", gmlVersion, filterNS, wfsNS = "
+ ((maxFeatures || maxFeatures === 0) ? ` ${getMaxFeatures(maxFeatures)}` : "")
+ (viewParams ? ` viewParams="${viewParams}"` : "");
};
const propertyName = (property) =>
castArray(property)
.map(p => `<${wfsVersion === "2.0" ? "fes" : "ogc"}:PropertyName>${p}</${wfsVersion === "2.0" ? "fes" : "ogc"}:PropertyName>`)
.join("");
const fb = filterBuilder({gmlVersion: gmlV, wfsVersion, filterNS: filterNS || wfsVersion === "2.0" ? "fes" : "ogc"});

return {
propertyName,
...filterBuilder({gmlVersion: gmlV, wfsVersion, filterNS: filterNS || wfsVersion === "2.0" ? "fes" : "ogc"}),
...fb,
getFeature: (content, opts) => `<${wfsNS}:GetFeature ${requestAttributes(opts)}>${Array.isArray(content) ? content.join("") : content}</${wfsNS}:GetFeature>`,
sortBy: (property, order = "ASC") =>
`<${wfsNS}:SortBy><${wfsNS}:SortProperty>${propertyName(property)}<${wfsNS}:SortOrder>${order}</${wfsNS}:SortOrder></${wfsNS}:SortProperty></${wfsNS}:SortBy>`,
`<${wfsNS}:SortBy><${wfsNS}:SortProperty>${fb.propertyName(property)}<${wfsNS}:SortOrder>${order}</${wfsNS}:SortOrder></${wfsNS}:SortProperty></${wfsNS}:SortBy>`,
query: (featureName, content, {srsName = "EPSG:4326"} = {}) =>
`<${wfsNS}:Query ${wfsVersion === "2.0" ? "typeNames" : "typeName"}="${featureName}" ${srsName !== 'native' ? `srsName="${srsName}"` : ''}>`
+ `${Array.isArray(content) ? content.join("") : content}`
Expand Down
38 changes: 38 additions & 0 deletions web/client/utils/ogc/WFS/__tests__/RequestBuilder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,42 @@ describe('RequestBuilder Operators', () => {
), {outputFormat: "application/json"})
).toBe(expected3);
});
it('test PropertyName and sortBy usage', () => {
const {filter, getFeature, property, query, propertyName, sortBy} = requestBuilder({wfsVersion: "2.0"});
const expected = '<wfs:GetFeature service="WFS" version="2.0"'
+ ' xmlns:wfs="http://www.opengis.net/wfs/2.0"'
+ ' xmlns:fes="http://www.opengis.net/fes/2.0"'
+ ' xmlns:gml="http://www.opengis.net/gml/3.2"'
+ ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd">'
+ '<wfs:Query typeNames="ft_name_test" srsName="EPSG:4326">'
+ '<wfs:SortBy>'
+ '<wfs:SortProperty>'
+ '<fes:PropertyName>highway_system</fes:PropertyName>'
+ '<wfs:SortOrder>A</wfs:SortOrder>'
+ '</wfs:SortProperty>'
+ '</wfs:SortBy>'
+ '<fes:PropertyName>highway_system</fes:PropertyName>'
+ '<fes:PropertyName>name</fes:PropertyName>'
+ '<fes:Filter>'
+ '<fes:PropertyIsEqualTo>'
+ '<fes:ValueReference>highway_system</fes:ValueReference>'
+ '<fes:Literal>state</fes:Literal>'
+ '</fes:PropertyIsEqualTo>'
+ '</fes:Filter>'
+ '</wfs:Query>'
+ '</wfs:GetFeature>';
expect(
getFeature(query("ft_name_test",
[
sortBy("highway_system", "A"),
propertyName(["highway_system", "name"]),
filter(property("highway_system").equalTo("state"))
]

))
).toBe(
expected
);

});
});

0 comments on commit 68dfc3f

Please sign in to comment.