Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10695 Handle empty values for and/or/not/nor filters #10696

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/client/utils/ogc/Filter/FilterBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module.exports = function({filterNS = "ogc", gmlVersion, wfsVersion = "1.1.0"} =
and: logical.and.bind(null, filterNS),
or: logical.or.bind(null, filterNS),
not: logical.not.bind(null, filterNS),
nor: logical.nor.bind(null, filterNS),
func: func.bind(null, filterNS),
literal: getValue,
// note: use valueReference method for filters and SortBy conditions. PropertyName is used in WFS 2.0 only for listing required attributes, while the rest uses ValueReference.
Expand Down
15 changes: 14 additions & 1 deletion web/client/utils/ogc/Filter/__tests__/FilterBuilder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe('FilterBuilder', () => {
expect(
b.or([b.property("GEOMETRY").intersects(testGeom1), b.property("GEOMETRY").intersects(testGeom2)])
).toBe(`<ogc:Or>${intersectsElem1}${intersectsElem2}</ogc:Or>`);

// not
expect(
b.not(b.property("GEOMETRY").intersects(testGeom1))
Expand All @@ -79,6 +78,20 @@ describe('FilterBuilder', () => {
)).toBe(`<ogc:Or><ogc:And>${intersectsElem1}<ogc:Not>${intersectsElem2}</ogc:Not></ogc:And>`
+ `<ogc:And>${intersectsElem2}<ogc:Not>${intersectsElem1}</ogc:Not></ogc:And>`
+ `</ogc:Or>`);
// empty array returns empty filter instead of <And>undefined</And>
// to check if is better to return an empty filter like <ogc:And></ogc:And> or <ogc:Or/>
expect(
b.and()
).toBe("");
expect(
b.or()
).toBe("");
expect(
b.not()
).toBe("");
expect(
b.nor()
).toBe("");
offtherailz marked this conversation as resolved.
Show resolved Hide resolved
});

it('valueReference 1.1.0', () => {
Expand Down
11 changes: 11 additions & 0 deletions web/client/utils/ogc/Filter/__tests__/operators-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ describe('OGC Operators', () => {
ogcComparisonOperators["="]("ogc", "TEST")
)).toBe('<ogc:Not><ogc:PropertyIsEqualTo>TEST</ogc:PropertyIsEqualTo></ogc:Not>');
});
it('logical functions with empty content', () => {
expect(logical.and("ogc"

)).toBe('');
expect(logical.or("ogc"

)).toBe('');
expect(logical.not("ogc"

)).toBe('');
offtherailz marked this conversation as resolved.
Show resolved Hide resolved
});
it('spatial functions', () => {
expect(spatial.intersects("ogc", propertyName("ogc", "GEOMETRY"), "TEST")).toBe("<ogc:Intersects><ogc:PropertyName>GEOMETRY</ogc:PropertyName>TEST</ogc:Intersects>");
expect(spatial.bbox("ogc", propertyName("ogc", "GEOMETRY"), "TEST")).toBe("<ogc:BBOX><ogc:PropertyName>GEOMETRY</ogc:PropertyName>TEST</ogc:BBOX>");
Expand Down
10 changes: 5 additions & 5 deletions web/client/utils/ogc/Filter/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const ogcComparisonOperators = {
"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>`,
"NOR": (ns, content) => `<${ns}:Not><${ns}:Or>${content}</${ns}:Or></${ns}:Not>`,
"NOT": (ns, content) => `<${ns}:Not>${content}</${ns}:Not>`
"AND": (ns, content) => content ? `<${ns}:And>${content}</${ns}:And>` : "",
"OR": (ns, content) => content ? `<${ns}:Or>${content}</${ns}:Or>` : "",
"NOR": (ns, content) => content ? `<${ns}:Not><${ns}:Or>${content}</${ns}:Or></${ns}:Not>` : "",
"NOT": (ns, content) => content ? `<${ns}:Not>${content}</${ns}:Not>` : ""
};

const ogcSpatialOperators = {
Expand All @@ -44,7 +44,7 @@ const upper = (ns, value) => `<${ns}:UpperBoundary>${value}</${ns}:UpperBoundary
* @param {string|Array} content content
* @returns the operation result
*/
const multiop = (ns, op, content) => op(ns, Array.isArray(content) ? content.join("") : content);
const multiop = (ns, op, content) => op(ns, Array.isArray(content) ? content.join("") : content );
offtherailz marked this conversation as resolved.
Show resolved Hide resolved
const logical = {
and: (ns, content, ...other) => other && other.length > 0 ? multiop(ns, ogcLogicalOperators.AND, [content, ...other]) : multiop(ns, ogcLogicalOperators.AND, content),
or: (ns, content, ...other) => other && other.length > 0 ? multiop(ns, ogcLogicalOperators.OR, [content, ...other]) : multiop(ns, ogcLogicalOperators.OR, content),
Expand Down