diff --git a/web/client/utils/ogc/Filter/FilterBuilder.js b/web/client/utils/ogc/Filter/FilterBuilder.js index 1646c0cbb9..25d4d3ccab 100644 --- a/web/client/utils/ogc/Filter/FilterBuilder.js +++ b/web/client/utils/ogc/Filter/FilterBuilder.js @@ -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. diff --git a/web/client/utils/ogc/Filter/__tests__/FilterBuilder-test.js b/web/client/utils/ogc/Filter/__tests__/FilterBuilder-test.js index 81a550c742..496d3c6bed 100644 --- a/web/client/utils/ogc/Filter/__tests__/FilterBuilder-test.js +++ b/web/client/utils/ogc/Filter/__tests__/FilterBuilder-test.js @@ -66,7 +66,6 @@ describe('FilterBuilder', () => { expect( b.or([b.property("GEOMETRY").intersects(testGeom1), b.property("GEOMETRY").intersects(testGeom2)]) ).toBe(`${intersectsElem1}${intersectsElem2}`); - // not expect( b.not(b.property("GEOMETRY").intersects(testGeom1)) @@ -79,6 +78,12 @@ describe('FilterBuilder', () => { )).toBe(`${intersectsElem1}${intersectsElem2}` + `${intersectsElem2}${intersectsElem1}` + ``); + // empty array returns empty filter instead of undefined + // to check if is better to return an empty filter like or + expect(b.and()).toBe(""); + expect(b.or()).toBe(""); + expect(b.not()).toBe(""); + expect(b.nor()).toBe(""); }); it('valueReference 1.1.0', () => { diff --git a/web/client/utils/ogc/Filter/__tests__/operators-test.js b/web/client/utils/ogc/Filter/__tests__/operators-test.js index cac96b224b..d8fc4ddc85 100644 --- a/web/client/utils/ogc/Filter/__tests__/operators-test.js +++ b/web/client/utils/ogc/Filter/__tests__/operators-test.js @@ -72,6 +72,11 @@ describe('OGC Operators', () => { ogcComparisonOperators["="]("ogc", "TEST") )).toBe('TEST'); }); + it('logical functions with empty content', () => { + expect(logical.and("ogc")).toBe(''); + expect(logical.or("ogc")).toBe(''); + expect(logical.not("ogc")).toBe(''); + }); it('spatial functions', () => { expect(spatial.intersects("ogc", propertyName("ogc", "GEOMETRY"), "TEST")).toBe("GEOMETRYTEST"); expect(spatial.bbox("ogc", propertyName("ogc", "GEOMETRY"), "TEST")).toBe("GEOMETRYTEST"); diff --git a/web/client/utils/ogc/Filter/operators.js b/web/client/utils/ogc/Filter/operators.js index 14e8341f26..bcc9da2f6f 100644 --- a/web/client/utils/ogc/Filter/operators.js +++ b/web/client/utils/ogc/Filter/operators.js @@ -18,10 +18,10 @@ const ogcComparisonOperators = { "isNull": (ns, content) => `<${ns}:PropertyIsNull>${content}` }; const ogcLogicalOperators = { - "AND": (ns, content) => `<${ns}:And>${content}`, - "OR": (ns, content) => `<${ns}:Or>${content}`, - "NOR": (ns, content) => `<${ns}:Not><${ns}:Or>${content}`, - "NOT": (ns, content) => `<${ns}:Not>${content}` + "AND": (ns, content) => content ? `<${ns}:And>${content}` : "", + "OR": (ns, content) => content ? `<${ns}:Or>${content}` : "", + "NOR": (ns, content) => content ? `<${ns}:Not><${ns}:Or>${content}` : "", + "NOT": (ns, content) => content ? `<${ns}:Not>${content}` : "" }; const ogcSpatialOperators = {