Skip to content

Commit b67aed7

Browse files
authored
add mime type on wps download output (#7648) (#7675)
1 parent 67ee5ab commit b67aed7

File tree

3 files changed

+149
-3
lines changed

3 files changed

+149
-3
lines changed

web/client/components/data/download/ExportDataResults.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const ExportDataResults = ({
5454
</OverlayTrigger> : null}
5555
{status === 'failed' && (!result || !result.msgId) ? failButton : null}
5656
{status === 'completed' &&
57-
<a href={result}>
57+
<a href={result} target="_blank" rel="noopener noreferrer">
5858
<Button bsStyle="primary" bsSize="small">
5959
<Glyphicon glyph="floppy-disk"/>
6060
</Button>

web/client/observables/wps/__tests__/download-test.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,144 @@ describe('WPS download tests', () => {
381381
}
382382
);
383383
});
384+
it('should use the resultOutput property', (done) => {
385+
386+
const options = {
387+
layerName: 'layer',
388+
resultOutput: 'application/zip',
389+
outputFormat: 'application/json',
390+
asynchronous: true,
391+
outputAsReference: true,
392+
notifyDownloadEstimatorSuccess: true
393+
};
394+
395+
const expectedDataPayload = `<?xml version="1.0" encoding="UTF-8"?>` +
396+
`<wps:Execute version="1.0.0" service="WPS" ` +
397+
`xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ` +
398+
`xmlns="http://www.opengis.net/wps/1.0.0" ` +
399+
`xmlns:wfs="http://www.opengis.net/wfs" ` +
400+
`xmlns:wps="http://www.opengis.net/wps/1.0.0" ` +
401+
`xmlns:ows="http://www.opengis.net/ows/1.1" ` +
402+
`xmlns:gml="http://www.opengis.net/gml" ` +
403+
`xmlns:ogc="http://www.opengis.net/ogc" ` +
404+
`xmlns:wcs="http://www.opengis.net/wcs/1.1.1" ` +
405+
`xmlns:dwn="http://geoserver.org/wps/download" ` +
406+
`xmlns:xlink="http://www.w3.org/1999/xlink" ` +
407+
`xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">` +
408+
`<ows:Identifier>gs:Download</ows:Identifier>` +
409+
`<wps:DataInputs>` +
410+
`<wps:Input>` +
411+
`<ows:Identifier>layerName</ows:Identifier>` +
412+
`<wps:Data>` +
413+
`<wps:LiteralData>layer</wps:LiteralData>` +
414+
`</wps:Data>` +
415+
`</wps:Input>` +
416+
`<wps:Input>` +
417+
`<ows:Identifier>outputFormat</ows:Identifier>` +
418+
`<wps:Data>` +
419+
`<wps:LiteralData>application/json</wps:LiteralData>` +
420+
`</wps:Data>` +
421+
`</wps:Input>` +
422+
`<wps:Input>` +
423+
`<ows:Identifier>cropToROI</ows:Identifier>` +
424+
`<wps:Data>` +
425+
`<wps:LiteralData>false</wps:LiteralData>` +
426+
`</wps:Data>` +
427+
`</wps:Input>` +
428+
`</wps:DataInputs>` +
429+
`<wps:ResponseForm>` +
430+
`<wps:ResponseDocument storeExecuteResponse="true" status="true">` +
431+
`<wps:Output mimeType="application/zip" asReference="true">` +
432+
`<ows:Identifier>result</ows:Identifier>` +
433+
`</wps:Output>` +
434+
`</wps:ResponseDocument>` +
435+
`</wps:ResponseForm>` +
436+
`</wps:Execute>`;
437+
438+
mockAxios
439+
.onPost()
440+
.replyOnce(200, downloadEstimatorSucceededResponse, {'content-type': 'application/xml'})
441+
.onPost()
442+
.replyOnce((config) => {
443+
try {
444+
expect(config.data).toBe(expectedDataPayload);
445+
} catch (e) {
446+
done(e);
447+
}
448+
done();
449+
return [200, responseWithComplexDataOutput, {'content-type': 'application/xml'}];
450+
});
451+
452+
download('http://testserver', options, {executeStatusUpdateInterval: 0}).subscribe();
453+
});
454+
455+
it('should use the outputFormat if resultOutput is undefined as output format', (done) => {
456+
457+
const options = {
458+
layerName: 'layer',
459+
outputFormat: 'application/json',
460+
asynchronous: true,
461+
outputAsReference: true,
462+
notifyDownloadEstimatorSuccess: true
463+
};
464+
465+
const expectedDataPayload = `<?xml version="1.0" encoding="UTF-8"?>` +
466+
`<wps:Execute version="1.0.0" service="WPS" ` +
467+
`xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ` +
468+
`xmlns="http://www.opengis.net/wps/1.0.0" ` +
469+
`xmlns:wfs="http://www.opengis.net/wfs" ` +
470+
`xmlns:wps="http://www.opengis.net/wps/1.0.0" ` +
471+
`xmlns:ows="http://www.opengis.net/ows/1.1" ` +
472+
`xmlns:gml="http://www.opengis.net/gml" ` +
473+
`xmlns:ogc="http://www.opengis.net/ogc" ` +
474+
`xmlns:wcs="http://www.opengis.net/wcs/1.1.1" ` +
475+
`xmlns:dwn="http://geoserver.org/wps/download" ` +
476+
`xmlns:xlink="http://www.w3.org/1999/xlink" ` +
477+
`xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">` +
478+
`<ows:Identifier>gs:Download</ows:Identifier>` +
479+
`<wps:DataInputs>` +
480+
`<wps:Input>` +
481+
`<ows:Identifier>layerName</ows:Identifier>` +
482+
`<wps:Data>` +
483+
`<wps:LiteralData>layer</wps:LiteralData>` +
484+
`</wps:Data>` +
485+
`</wps:Input>` +
486+
`<wps:Input>` +
487+
`<ows:Identifier>outputFormat</ows:Identifier>` +
488+
`<wps:Data>` +
489+
`<wps:LiteralData>application/json</wps:LiteralData>` +
490+
`</wps:Data>` +
491+
`</wps:Input>` +
492+
`<wps:Input>` +
493+
`<ows:Identifier>cropToROI</ows:Identifier>` +
494+
`<wps:Data>` +
495+
`<wps:LiteralData>false</wps:LiteralData>` +
496+
`</wps:Data>` +
497+
`</wps:Input>` +
498+
`</wps:DataInputs>` +
499+
`<wps:ResponseForm>` +
500+
`<wps:ResponseDocument storeExecuteResponse="true" status="true">` +
501+
`<wps:Output mimeType="application/json" asReference="true">` +
502+
`<ows:Identifier>result</ows:Identifier>` +
503+
`</wps:Output>` +
504+
`</wps:ResponseDocument>` +
505+
`</wps:ResponseForm>` +
506+
`</wps:Execute>`;
507+
508+
mockAxios
509+
.onPost()
510+
.replyOnce(200, downloadEstimatorSucceededResponse, {'content-type': 'application/xml'})
511+
.onPost()
512+
.replyOnce((config) => {
513+
try {
514+
expect(config.data).toBe(expectedDataPayload);
515+
} catch (e) {
516+
done(e);
517+
}
518+
done();
519+
return [200, responseWithComplexDataOutput, {'content-type': 'application/xml'}];
520+
});
521+
522+
download('http://testserver', options, {executeStatusUpdateInterval: 0}).subscribe();
523+
});
384524
});

web/client/observables/wps/download.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ export const download = (url, downloadOptions, executeOptions) => {
116116
dataFilter: downloadOptions.dataFilter,
117117
targetCRS: downloadOptions.targetCRS
118118
}), {outputsExtractor: makeOutputsExtractor(literalDataOutputExtractor)});
119+
120+
// use the same format of outputFormat for result
121+
// if resultOutput param is undefined
122+
const resultOutput = downloadOptions.resultOutput || downloadOptions.outputFormat || 'application/zip';
123+
119124
const executeProcess$ = executeProcess(url, downloadXML({
120125
...omit(downloadOptions, 'notifyDownloadEstimatorSuccess'),
121-
outputAsReference: downloadOptions.asynchronous ? downloadOptions.outputAsReference : false
122-
}), executeOptions, {headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, ${downloadOptions.resultOutput || 'application/zip'}`}});
126+
outputAsReference: downloadOptions.asynchronous ? downloadOptions.outputAsReference : false,
127+
resultOutput
128+
}), executeOptions, {headers: {'Content-Type': 'application/xml', 'Accept': `application/xml, ${resultOutput}`}});
123129

124130
return downloadEstimator$
125131
.catch(() => {

0 commit comments

Comments
 (0)