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

[Backport 2023.01.xx] #9030 improve metadata display interoperability with mapserver/mapproxy (#7865) #9059

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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/WMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,23 @@ export const extractCredits = attribution => {
};
};


export const flatLayers = (root) => {
return root.Layer ? (isArray(root.Layer) && root.Layer || [root.Layer]).reduce((previous, current) => {
return previous.concat(flatLayers(current)).concat(current.Layer && current.Name ? [current] : []);
}, []) : root.Name && [root] || [];
const rootLayer = root.Layer ?? root.layer;
const rootName = root.Name ?? root.name;
return rootLayer
? (castArray(rootLayer))
.reduce((acc, current) => {
const currentLayer = current.Layer ?? current.layer;
const currentName = current.Name ?? current.name;
return [
...acc,
...flatLayers(current),
...(currentLayer && currentName ? [current] : [])
];
}, [])
: rootName && [root] || [];
};

export const getOnlineResource = (c) => {
return c.Request && c.Request.GetMap && c.Request.GetMap.DCPType && c.Request.GetMap.DCPType.HTTP && c.Request.GetMap.DCPType.HTTP.Get && c.Request.GetMap.DCPType.HTTP.Get.OnlineResource && c.Request.GetMap.DCPType.HTTP.Get.OnlineResource.$ || undefined;
};
Expand Down
48 changes: 48 additions & 0 deletions web/client/api/__tests__/WMS-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,54 @@ describe('Test correctness of the WMS APIs', () => {
const capability = API.parseLayerCapabilities(capabilities, {name: 'mytest'});
expect(capability).toExist();
});
it('should parse nested layers from capabilities', () => {
expect(API.flatLayers({
Layer: {
Name: 'layer1',
Layer: {
Name: 'layer2',
Layer: {
Name: 'layer3',
Layer: {
Name: 'layer4',
Layer: {
Name: 'layer5'
}
}
}
}
}
})).toEqual([
{ Name: 'layer5' },
{ Name: 'layer4', Layer: { Name: 'layer5' } },
{ Name: 'layer3', Layer: { Name: 'layer4', Layer: { Name: 'layer5' } } },
{ Name: 'layer2', Layer: { Name: 'layer3', Layer: { Name: 'layer4', Layer: { Name: 'layer5' } } } },
{ Name: 'layer1', Layer: { Name: 'layer2', Layer: { Name: 'layer3', Layer: { Name: 'layer4', Layer: { Name: 'layer5' } } } } }
]);
expect(API.flatLayers({
layer: {
name: 'layer1',
layer: {
name: 'layer2',
layer: {
name: 'layer3',
layer: {
name: 'layer4',
layer: {
name: 'layer5'
}
}
}
}
}
})).toEqual([
{ name: 'layer5' },
{ name: 'layer4', layer: { name: 'layer5' } },
{ name: 'layer3', layer: { name: 'layer4', layer: { name: 'layer5' } } },
{ name: 'layer2', layer: { name: 'layer3', layer: { name: 'layer4', layer: { name: 'layer5' } } } },
{ name: 'layer1', layer: { name: 'layer2', layer: { name: 'layer3', layer: { name: 'layer4', layer: { name: 'layer5' } } } } }
]);
});
});

describe('Test correctness of the WMS APIs (mock axios)', () => {
Expand Down
96 changes: 95 additions & 1 deletion web/client/epics/__tests__/catalog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {
} = catalog(API);
import {SHOW_NOTIFICATION} from '../../actions/notifications';
import {SET_CONTROL_PROPERTY, toggleControl} from '../../actions/controls';
import {ADD_LAYER, CHANGE_LAYER_PROPERTIES, selectNode} from '../../actions/layers';
import {ADD_LAYER, CHANGE_LAYER_PROPERTIES, selectNode, SHOW_LAYER_METADATA} from '../../actions/layers';
import {PURGE_MAPINFO_RESULTS, HIDE_MAPINFO_MARKER} from '../../actions/mapInfo';
import {testEpic, addTimeoutEpic, TEST_TIMEOUT} from './epicTestUtils';
import {
Expand Down Expand Up @@ -65,7 +65,101 @@ describe('catalog Epics', () => {
}
});
});
it('should return metadata TC211 with getMetadataRecordById (mapserver)', (done) => {

testEpic(getMetadataRecordById, 2, initAction({
xmlNamespaces: {
gmd: 'http://www.isotc211.org/2005/gmd',
srv: 'http://www.isotc211.org/2005/srv',
gco: 'http://www.isotc211.org/2005/gco',
gmx: 'http://www.isotc211.org/2005/gmx',
gfc: 'http://www.isotc211.org/2005/gfc',
gts: 'http://www.isotc211.org/2005/gts',
gml: 'http://www.opengis.net/gml'
},
extractors: [{
layersRegex: '^opendata_raw$',
properties: {
title: '/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString'
}
}]
}), (actions) => {
try {
const [
showLayerMetadataEmptyAction,
showLayerMetadataResponseAction
] = actions;
expect(showLayerMetadataEmptyAction.type).toBe(SHOW_LAYER_METADATA);
expect(showLayerMetadataEmptyAction.maskLoading).toBe(true);
expect(showLayerMetadataEmptyAction.metadataRecord).toEqual({});
expect(showLayerMetadataResponseAction.type).toBe(SHOW_LAYER_METADATA);
expect(showLayerMetadataResponseAction.maskLoading).toBe(false);
expect(showLayerMetadataResponseAction.metadataRecord).toEqual({ title: 'Images brutes en open data' });
} catch (e) {
done(e);
}
done();
}, {
layers: {
selected: ["opendata_raw"],
flat: [{
id: "opendata_raw",
name: "opendata_raw",
type: "wms",
url: "base/web/client/test-resources/wms/getCapabilities-mapserver.xml"
}]
}
});
});

it('should return metadata TC211 with getMetadataRecordById (mapproxy single)', (done) => {
testEpic(getMetadataRecordById, 2, initAction({
xmlNamespaces: {
gmd: 'http://www.isotc211.org/2005/gmd',
srv: 'http://www.isotc211.org/2005/srv',
gco: 'http://www.isotc211.org/2005/gco',
gmx: 'http://www.isotc211.org/2005/gmx',
gfc: 'http://www.isotc211.org/2005/gfc',
gts: 'http://www.isotc211.org/2005/gts',
gml: 'http://www.opengis.net/gml'
},
extractors: [{
layersRegex: '^cadastre$',
properties: {
title: '/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString'
}
}]
}), (actions) => {
try {
const [
showLayerMetadataEmptyAction,
showLayerMetadataResponseAction
] = actions;
expect(showLayerMetadataEmptyAction.type).toBe(SHOW_LAYER_METADATA);
expect(showLayerMetadataEmptyAction.maskLoading).toBe(true);
expect(showLayerMetadataEmptyAction.metadataRecord).toEqual({});
expect(showLayerMetadataResponseAction.type).toBe(SHOW_LAYER_METADATA);
expect(showLayerMetadataResponseAction.maskLoading).toBe(false);
expect(showLayerMetadataResponseAction.metadataRecord).toEqual({
metadataUrl: 'https://ids.craig.fr/geocat/srv/api/records/3bedb35a-a9ba-4f48-8796-de127becd578',
title: 'Plan Cadastral Informatisé (PCI) au format vecteur - Auvergne-Rhône-Alpes - 01/2022'
});
} catch (e) {
done(e);
}
done();
}, {
layers: {
selected: ["cadastre"],
flat: [{
id: "cadastre",
name: "cadastre",
type: "wms",
url: "base/web/client/test-resources/wms/getCapabilities-mapproxy-singlelayer.xml"
}]
}
});
});
it('autoSearchEpic', (done) => {
const NUM_ACTIONS = 1;
testEpic(autoSearchEpic, NUM_ACTIONS, changeText(""), (actions) => {
Expand Down
15 changes: 9 additions & 6 deletions web/client/epics/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ import {
buildSRSMap,
extractOGCServicesReferences
} from '../utils/CatalogUtils';
import { getSupportedFormat, getCapabilities, describeLayers } from '../api/WMS';
import { getSupportedFormat, getCapabilities, describeLayers, flatLayers } from '../api/WMS';
import CoordinatesUtils from '../utils/CoordinatesUtils';
import ConfigUtils from '../utils/ConfigUtils';
import {getCapabilitiesUrl, getLayerId, getLayerUrl} from '../utils/LayersUtils';
import {getCapabilitiesUrl, getLayerId, getLayerUrl, removeWorkspace } from '../utils/LayersUtils';
import { wrapStartStop } from '../observables/epics';
import {zoomToExtent} from "../actions/map";
import CSW from '../api/CSW';
Expand Down Expand Up @@ -338,13 +338,16 @@ export default (API) => ({

return Rx.Observable.defer(() => getCapabilities(getCapabilitiesUrl(layer)))
.switchMap((caps) => {
const layersXml = get(caps, 'capability.layer.layer', []);
const metadataUrls = layersXml.length === 1 ? layersXml[0].metadataURL : find(layersXml, l => l.name === layer.name.split(':')[1]);
const layersXml = flatLayers(caps.capability);
const metadataUrls = (layersXml.length === 1
? layersXml[0].metadataURL
: find(layersXml, l => removeWorkspace(l.name) === removeWorkspace(layer.name))?.metadataURL)
|| [];
const metadataUrl = get(find(metadataUrls, mUrl => isString(mUrl.type) &&
mUrl.type.toLowerCase() === 'iso19115:2003' &&
(mUrl.type.toLowerCase() === 'iso19115:2003' || mUrl.type.toLowerCase() === 'tc211') &&
(mUrl.format === 'application/xml' || mUrl.format === 'text/xml')), 'onlineResource.href');
const metadataUrlHTML = get(find(metadataUrls, mUrl => isString(mUrl.type) &&
mUrl.type.toLowerCase() === 'iso19115:2003' &&
(mUrl.type.toLowerCase() === 'iso19115:2003' || mUrl.type.toLowerCase() === 'tc211') &&
mUrl.format === 'text/html'), 'onlineResource.href');
const extractor = find(get(metadataOptions, 'extractors', []),
({properties, layersRegex}) => {
Expand Down
9 changes: 1 addition & 8 deletions web/client/epics/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getLayersWithDimension, layerSettingSelector, getLayerFromId } from '..
import { setControlProperty } from '../actions/controls';
import { initialSettingsSelector, originalSettingsSelector } from '../selectors/controls';
import { basicError } from '../utils/NotificationUtils';
import { getCapabilitiesUrl, getLayerTitleTranslations} from '../utils/LayersUtils';
import { getCapabilitiesUrl, getLayerTitleTranslations, removeWorkspace } from '../utils/LayersUtils';
import assign from 'object-assign';
import { isArray, head } from 'lodash';

Expand All @@ -38,13 +38,6 @@ export const getUpdates = (updates, options) => {
}, {});
};

export const removeWorkspace = (layer) => {
if (layer.indexOf(':') !== -1) {
return layer.split(':')[1];
}
return layer;
};

/**
* Runs refresh requests for all requested layers and accumulates results
* @memberof epics.layers
Expand Down
Loading