Skip to content

Commit

Permalink
geosolutions-it#10193: Issue with WFS added via Query params
Browse files Browse the repository at this point in the history
- fix the issue behind not adding the wfs layer
- write the unit tests for this cahnge
  • Loading branch information
mahmoudadel54 committed Apr 12, 2024
1 parent dda2b69 commit 2c2d8c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
19 changes: 15 additions & 4 deletions web/client/api/WFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
})
}));
};
/**
Expand Down
12 changes: 12 additions & 0 deletions web/client/api/__tests__/WFS-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 2c2d8c5

Please sign in to comment.