Skip to content

Commit

Permalink
geosolutions-it#8603 Error downloading filtered dataset, where filter…
Browse files Browse the repository at this point in the history
… is based on another layer (geosolutions-it#8641)
  • Loading branch information
DavidQuartz committed Oct 3, 2022
1 parent 0f18d6a commit e10735a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
63 changes: 61 additions & 2 deletions web/client/observables/wps/__tests__/common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import expect from 'expect';

import {
getWPSURL
getWPSURL,
cdata
} from '../common';


Expand Down Expand Up @@ -40,5 +41,63 @@ describe('common WPS utils', () => {
expect(/https:\/\/host.?\/service\/wps\?service=WPS&IDENTIFIER=gs%3AAggregate&REQUEST=DescribeProcess&version=1\.0\.0/.test(getWPSURL(url, options))).toEqual(true);

});

it('test cdata wrapper on xml with no cdata', () => {
const filterString = `<wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
<ogc:Filter
xmlns:ogc="http://www.test.net/ogc"
xmlns:gml="http://www.test.net/gml">
<ogc:And>
<ogc:Intersects>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Function name="collectGeometries">
<ogc:Function name="queryCollection">
<ogc:Literal>geonode:test_export_filter0</ogc:Literal>
<ogc:Literal>the_geom</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Intersects>
</ogc:And>
</ogc:Filter>
</wps:ComplexData>`;
expect(cdata(filterString)).toEqual(`<![CDATA[<wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
<ogc:Filter
xmlns:ogc="http://www.test.net/ogc"
xmlns:gml="http://www.test.net/gml">
<ogc:And>
<ogc:Intersects>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Function name="collectGeometries">
<ogc:Function name="queryCollection">
<ogc:Literal>geonode:test_export_filter0</ogc:Literal>
<ogc:Literal>the_geom</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Intersects>
</ogc:And>
</ogc:Filter>
</wps:ComplexData>]]>`);
});
it('test cdata wrapper on xml with cdata', () => {
const filterString = `<wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
<ogc:Filter
xmlns:ogc="http://www.test.net/ogc"
xmlns:gml="http://www.test.net/gml">
<ogc:And>
<ogc:Intersects>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<ogc:Function name="collectGeometries">
<ogc:Function name="queryCollection">
<ogc:Literal>geonode:test_export_filter0</ogc:Literal>
<ogc:Literal>the_geom</ogc:Literal>
<ogc:Literal>
<![CDATA[INCLUDE]]>
</ogc:Literal>
</ogc:Function>
</ogc:Function>
</ogc:Intersects>
</ogc:And>
</ogc:Filter>
</wps:ComplexData>`;
expect(cdata(filterString)).toEqual(filterString);
});
});
8 changes: 7 additions & 1 deletion web/client/observables/wps/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ export const literalData = (literal) => `<wps:LiteralData>${literal}</wps:Litera
export const complexData = (data, mimeType, encoding) => `<wps:ComplexData${mimeType ? ` mimeType="${mimeType}"` : ''}${encoding ? ` encoding="${encoding}"` : ''}>${data}</wps:ComplexData>`;
/**
* Wrap data in CDATA
* Avoids wrapping data if it already contains CDATA
* @memberof observables.wps.common
* @param {string} data data to wrap
* @returns {string}
*/
export const cdata = (data) => `<![CDATA[${data}]]>`;
export const cdata = (data) => {
const regex = /\bCDATA\b/;
const isCdataIncluded = regex.test(data);
if (isCdataIncluded) return data;
return `<![CDATA[${data}]]>`;
};

/**
* Wrap XML in wps:ResponseForm
Expand Down

0 comments on commit e10735a

Please sign in to comment.