Skip to content

Commit

Permalink
#8545 Layer download: WPS only case (#8668)
Browse files Browse the repository at this point in the history
  • Loading branch information
belom88 committed Oct 7, 2022
1 parent 4e1ff07 commit 0e3b035
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 8 deletions.
4 changes: 3 additions & 1 deletion web/client/components/data/download/DownloadDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class DownloadDialog extends React.Component {
const wfsFormats = validWFSFormats.length > 0 ?
validWFSFormats.filter(f => this.props.wfsFormats.find(wfsF => wfsF.name.toLowerCase() === f.name.toLowerCase())) :
this.props.wfsFormats;
const wfsAvailable = Boolean(this.props.layer.search?.url);

return this.props.enabled ? (<Portal><Dialog id="mapstore-export" draggable={false} modal>
<span role="header">
Expand All @@ -125,10 +126,11 @@ class DownloadDialog extends React.Component {
<div role="body">
{this.props.checkingWPSAvailability ?
<Loader size={100} style={{margin: '0 auto'}}/> :
this.props.service === 'wfs' && !this.props.layer.search?.url ?
!this.props.wpsAvailable && !wfsAvailable ?
<EmptyView title={<Message msgId="layerdownload.noSupportedServiceFound"/>}/> :
<DownloadOptions
wpsAvailable={this.props.wpsAvailable}
wfsAvailable={wfsAvailable}
service={this.props.service}
downloadOptions={this.props.downloadOptions}
setService={this.props.setService}
Expand Down
4 changes: 3 additions & 1 deletion web/client/components/data/download/DownloadOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import DownloadWPSOptions from './DownloadWPSOptions';
class DownloadOptions extends React.Component {
static propTypes = {
wpsAvailable: PropTypes.bool,
wfsAvailable: PropTypes.bool,
service: PropTypes.string,
downloadOptions: PropTypes.object,
formatOptionsFetch: PropTypes.func,
Expand All @@ -46,6 +47,7 @@ class DownloadOptions extends React.Component {

static defaultProps = {
wpsAvailable: false,
wfsAvailable: true,
service: 'wps',
downloadOptions: {},
formatsLoading: false,
Expand Down Expand Up @@ -74,7 +76,7 @@ class DownloadOptions extends React.Component {

render() {
return (<form>
{this.props.wpsAvailable &&
{this.props.wpsAvailable && this.props.wfsAvailable &&
<>
<label><Message msgId="layerdownload.service" /></label>
<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,29 @@ describe('Test for DownloadDialog component', () => {
});

it('render download options', () => {
ReactDOM.render(<DownloadDialog enabled service="wps"/>, document.getElementById("container"));
const selectedLayer =
{
type: 'wfs',
visibility: true,
id: 'mapstore:states__7',
search: {
url: 'http://u.r.l'
}
};
ReactDOM.render(<DownloadDialog enabled service="wps" layer={selectedLayer} />, document.getElementById("container"));
const dialog = document.getElementById('mapstore-export');
expect(dialog).toBeTruthy();
expect(dialog.getElementsByTagName('form')[0]).toBeTruthy();
});

it('render download options with only "wps" available', () => {
const selectedLayer =
{
type: 'wms',
visibility: true,
id: 'mapstore:states__7'
};
ReactDOM.render(<DownloadDialog enabled service="wps" wpsAvailable layer={selectedLayer} />, document.getElementById("container"));
const dialog = document.getElementById('mapstore-export');
expect(dialog).toBeTruthy();
expect(dialog.getElementsByTagName('form')[0]).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Test for DownloadOptions component', () => {
});

it('render serivce selector', () => {
ReactDOM.render(<DownloadOptions wpsAvailable />, document.getElementById("container"));
ReactDOM.render(<DownloadOptions wpsAvailable wfsAvailable />, document.getElementById("container"));
const form = document.getElementsByTagName('form')[0];
const firstChild = form.querySelector('label');
expect(firstChild.innerHTML).toBe('<span>layerdownload.service</span>');
Expand All @@ -39,9 +39,16 @@ describe('Test for DownloadOptions component', () => {
});

it('render service selector with WFS service', () => {
ReactDOM.render(<DownloadOptions wpsAvailable service="wfs" />, document.getElementById("container"));
ReactDOM.render(<DownloadOptions wpsAvailable wfsAvailable service="wfs" />, document.getElementById("container"));
const form = document.getElementsByTagName('form')[0];
const selectorValueLabel = form.querySelector('.Select .Select-value-label');
expect(selectorValueLabel.innerText).toBe('WFS');
});

it('should not render service selector', () => {
ReactDOM.render(<DownloadOptions wpsAvailable wfsAvailable={false} service="wps" />, document.getElementById("container"));
const form = document.getElementsByTagName('form')[0];
const selectors = form.querySelectorAll('.Select');
expect(selectors.length).toBe(2);
});
});
56 changes: 55 additions & 1 deletion web/client/epics/__tests__/layerdownload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,61 @@ describe('layerdownload Epics', () => {
};

mockAxios.onGet().reply(200, xmlData);
const state = { controls: { layerdownload: { enabled: false, downloadOptions: {}} } };
const state = {
controls: {
layerdownload: { enabled: false, downloadOptions: {}}
},
layers: {
flat: [
{
type: 'wfs',
visibility: true,
id: 'mapstore:states__7',
search: {
url: 'http://u.r.l'
}
}
],
selected: [
'mapstore:states__7'
]
}
};
testEpic(checkWPSAvailabilityEpic, 4, checkWPSAvailability('http://check.wps.availability.url', 'wfs'), epicResult, state);
});
it('should select WPS service', (done) => {
const epicResult = actions => {
expect(actions.length).toBe(4);
actions.map((action) => {
switch (action.type) {
case SET_SERVICE:
expect(action.service).toBe('wps');
break;
default:
break;
}
});
done();
};

mockAxios.onGet().reply(200, xmlData);
const state = {
controls: {
layerdownload: { enabled: false, downloadOptions: {}}
},
layers: {
flat: [
{
type: 'wms',
visibility: true,
id: 'mapstore:states__7'
}
],
selected: [
'mapstore:states__7'
]
}
};
testEpic(checkWPSAvailabilityEpic, 4, checkWPSAvailability('http://check.wps.availability.url', 'wfs'), epicResult, state);
});
it('downloads a layer', (done) => {
Expand Down
8 changes: 6 additions & 2 deletions web/client/epics/layerdownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,23 @@ const str2bytes = (str) => {
return bytes;
};
*/
export const checkWPSAvailabilityEpic = (action$) => action$
export const checkWPSAvailabilityEpic = (action$, store) => action$
.ofType(CHECK_WPS_AVAILABILITY)
.switchMap(({url, selectedService}) => {
return describeProcess(url, 'gs:DownloadEstimator,gs:Download')
.switchMap(response => Rx.Observable.defer(() => new Promise((resolve, reject) => parseString(response.data, {tagNameProcessors: [stripPrefix]}, (err, res) => err ? reject(err) : resolve(res)))))
.flatMap(xmlObj => {
const state = store.getState();
const layer = getSelectedLayer(state);
const ids = [
xmlObj?.ProcessDescriptions?.ProcessDescription?.[0]?.Identifier?.[0],
xmlObj?.ProcessDescriptions?.ProcessDescription?.[1]?.Identifier?.[0]
];
const isWpsAvailable = findIndex(ids, x => x === 'gs:DownloadEstimator') > -1 && findIndex(ids, x => x === 'gs:Download') > -1;
const isWfsAvailable = layer.search?.url;
const shouldSelectWps = isWpsAvailable && (selectedService === 'wps' || !isWfsAvailable);
return Rx.Observable.of(
setService(isWpsAvailable ? selectedService || 'wps' : 'wfs'),
setService(shouldSelectWps ? 'wps' : 'wfs'),
setWPSAvailability(isWpsAvailable),
checkingWPSAvailability(false)
);
Expand Down

0 comments on commit 0e3b035

Please sign in to comment.