From 2c2d8c5ba8abc3e108e5cb2caf0c0804b5b3e57d Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Fri, 12 Apr 2024 11:08:38 +0200 Subject: [PATCH 1/2] #10193: Issue with WFS added via Query params - fix the issue behind not adding the wfs layer - write the unit tests for this cahnge --- web/client/api/WFS.js | 19 +++++++++++++++---- web/client/api/__tests__/WFS-test.js | 12 ++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/web/client/api/WFS.js b/web/client/api/WFS.js index 155652ec9d..a5fb328086 100644 --- a/web/client/api/WFS.js +++ b/web/client/api/WFS.js @@ -12,6 +12,13 @@ import requestBuilder from '../utils/ogc/WFS/RequestBuilder'; import {toOGCFilterParts} from '../utils/FilterUtils'; import { getDefaultUrl } from '../utils/URLUtils'; +/** +* @note from this ref: https://www.npmjs.com/package/url#urlformaturlobj +* * in using [ url.format(urlObj) ] --> 'urlObj.search' will be used in place of 'urlObj.query' +* * and 'urlObj.query' (object; see querystring) will only be used if 'urlObj.search' is absent. +* * so in case adding new parameters or update existing ones in 'urlObj.query', we need to set 'urlObj.search' with undefined to ignore it +*/ + export const toDescribeURL = (url, typeName) => { const parsed = urlUtil.parse(getDefaultUrl(url), true); return urlUtil.format( @@ -48,24 +55,28 @@ export const getFeatureSimple = function(baseUrl, params) { export const getCapabilitiesURL = (url, {version = "1.1.0"} = {}) => { const parsed = urlUtil.parse(getDefaultUrl(url), true); return urlUtil.format(assign({}, parsed, { + search: undefined, // this allows to merge parameters correctly query: assign({ - service: "WFS", version, + ...parsed.query, + service: "WFS", request: "GetCapabilities" - }, parsed.query) + }) })); }; export const getFeatureURL = (url, typeName, { version = "1.1.0", ...params } = {}) => { const parsed = urlUtil.parse(getDefaultUrl(url), true); return urlUtil.format(assign({}, parsed, { + search: undefined, // this allows to merge parameters correctly query: assign({ - service: "WFS", typeName, version, + ...parsed.query, + service: "WFS", request: "GetFeature", ...params - }, parsed.query) + }) })); }; /** diff --git a/web/client/api/__tests__/WFS-test.js b/web/client/api/__tests__/WFS-test.js index 2b5145c91d..1bd1736b02 100644 --- a/web/client/api/__tests__/WFS-test.js +++ b/web/client/api/__tests__/WFS-test.js @@ -150,4 +150,16 @@ describe('Test WFS ogc API functions', () => { expect(getFeatureURL(_url).split('?')[0]).toBe(_url[0]); }); + it('getFeatureURL if it includes getCapabilites request', () => { + const _url = 'http://gs-stable.geosolutionsgroup.com:443/geoserver3/wfs?service=WFS&version=1.1.0&request=GetCapabilities'; + const featureURL = getFeatureURL(_url, "layerName"); + expect(featureURL.includes("request=GetFeature")).toBeTruthy(); + expect(featureURL.split('?')[1]).toEqual('typeName=layerName&version=1.1.0&service=WFS&request=GetFeature'); + }); + + it('getFeatureURL if it includes normal getFeature request with version different than the default one', () => { + const _url = 'http://gs-stable.geosolutionsgroup.com:443/geoserver3/wfs?service=WFS&version=1.1.1&request=GetFeature'; + const featureURL = getFeatureURL(_url, "layerName"); + expect(featureURL.split('?')[1]).toEqual('typeName=layerName&version=1.1.1&service=WFS&request=GetFeature'); + }); }); From 1e36acd706f8717934f0ba6f6d4d3275eb6e6170 Mon Sep 17 00:00:00 2001 From: Suren Date: Mon, 15 Apr 2024 18:05:41 +0530 Subject: [PATCH 2/2] Update web/client/api/WFS.js --- web/client/api/WFS.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/web/client/api/WFS.js b/web/client/api/WFS.js index a5fb328086..329f8469dc 100644 --- a/web/client/api/WFS.js +++ b/web/client/api/WFS.js @@ -12,13 +12,6 @@ import requestBuilder from '../utils/ogc/WFS/RequestBuilder'; import {toOGCFilterParts} from '../utils/FilterUtils'; import { getDefaultUrl } from '../utils/URLUtils'; -/** -* @note from this ref: https://www.npmjs.com/package/url#urlformaturlobj -* * in using [ url.format(urlObj) ] --> 'urlObj.search' will be used in place of 'urlObj.query' -* * and 'urlObj.query' (object; see querystring) will only be used if 'urlObj.search' is absent. -* * so in case adding new parameters or update existing ones in 'urlObj.query', we need to set 'urlObj.search' with undefined to ignore it -*/ - export const toDescribeURL = (url, typeName) => { const parsed = urlUtil.parse(getDefaultUrl(url), true); return urlUtil.format(