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

#10193: Issue with WFS added via Query params #10195

Merged
merged 2 commits into from
Apr 15, 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
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
*/

dsuren1 marked this conversation as resolved.
Show resolved Hide resolved
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');
});
});
Loading