Skip to content

Commit

Permalink
Merge pull request #95 from geodatagouv/tusbar/fix-service-coupled-re…
Browse files Browse the repository at this point in the history
…sources

Fix coupled resources extraction
  • Loading branch information
tusbar committed Dec 3, 2018
2 parents 47b2778 + f706d30 commit e1b9b3a
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 5 deletions.
30 changes: 30 additions & 0 deletions __tests__/lib/metadata/iso/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lib.metadata.iso.index convert() extract featureTypes from a service metadata 1`] = `
Object {
"alternateTitle": undefined,
"contacts": Array [],
"description": undefined,
"featureTypes": Array [
Object {
"relatedTo": "7bcc8a8723759135feb7040380a2f2d7c921280f",
"serviceURL": "https://example.com/wfs",
"typeName": "bati_avap_paimpol",
},
Object {
"relatedTo": "46a8d50322e881fd4e8b7abc3bc45c38a247532e",
"serviceURL": "https://example.com/wfs",
"typeName": "elr_avap_paimpol",
},
],
"id": undefined,
"keywords": Array [],
"metadataType": "ISO 19139",
"resourceId": undefined,
"serviceProtocol": "wfs",
"serviceType": "download",
"serviceURL": "https://example.com/wfs",
"title": undefined,
"type": "service",
}
`;
36 changes: 36 additions & 0 deletions __tests__/lib/metadata/iso/__snapshots__/services.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lib.metadata.iso.services getCoupledResources() should dedup duplicated coupled resources 1`] = `
Array [
Object {
"identifier": "9fd801e3-976a-49b6-b84a-0bd448fec8d5",
"scopedName": "bati_avap_paimpol",
},
Object {
"identifier": "e3b34f32-8081-4451-83e0-4d5fcfd36512",
"scopedName": "elr_avap_paimpol",
},
]
`;

exports[`lib.metadata.iso.services getCoupledResources() should ignore incomplete resources 1`] = `
Array [
Object {
"identifier": "foo2",
"scopedName": "feature_type-2",
},
]
`;

exports[`lib.metadata.iso.services getCoupledResources() should return the coupled resources 1`] = `
Array [
Object {
"identifier": "foo1",
"scopedName": "feature_type-1",
},
Object {
"identifier": "foo2",
"scopedName": "feature_type-2",
},
]
`;
53 changes: 53 additions & 0 deletions __tests__/lib/metadata/iso/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const {convert} = require('../../../../lib/metadata/iso')

describe('lib.metadata.iso.index', () => {
describe('convert()', () => {
it('extract featureTypes from a service metadata', () => {
expect(convert({
hierarchyLevel: 'service',
identificationInfo: {
serviceType: 'download',
coupledResource: [
{
operationName: 'GetCapabilities',
identifier: '9fd801e3-976a-49b6-b84a-0bd448fec8d5',
scopedName: 'bati_avap_paimpol'
},
{
operationName: 'DescribeFeatureType',
identifier: '9fd801e3-976a-49b6-b84a-0bd448fec8d5',
scopedName: 'bati_avap_paimpol'
},
{
operationName: 'GetFeature',
identifier: '9fd801e3-976a-49b6-b84a-0bd448fec8d5',
scopedName: 'bati_avap_paimpol'
},
{
operationName: 'GetCapabilities',
identifier: 'e3b34f32-8081-4451-83e0-4d5fcfd36512',
scopedName: 'elr_avap_paimpol'
},
{
operationName: 'DescribeFeatureType',
identifier: 'e3b34f32-8081-4451-83e0-4d5fcfd36512',
scopedName: 'elr_avap_paimpol'
}
]
},
distributionInfo: {
transferOptions: [
{
onLine: [
{
linkage: 'https://example.com/wfs?SERVICE=WFS&REQUEST=GetCapabilities&',
protocol: 'OGC:WFS-2.0.0-http-get-capabilities'
}
]
}
]
}
})).toMatchSnapshot()
})
})
})
99 changes: 98 additions & 1 deletion __tests__/lib/metadata/iso/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {getWFSServiceLocation} = require('../../../../lib/metadata/iso/services')
const {getWFSServiceLocation, getCoupledResources} = require('../../../../lib/metadata/iso/services')

describe('lib.metadata.iso.services', () => {
describe('getWFSServiceLocation()', () => {
Expand Down Expand Up @@ -89,4 +89,101 @@ describe('lib.metadata.iso.services', () => {
expect(getWFSServiceLocation(metadata)).toBeNull()
})
})

describe('getCoupledResources()', () => {
it('should return the coupled resources', () => {
const metadata = {
identificationInfo: {
coupledResource: [
{
operationName: 'GetFeature',
identifier: 'foo1',
scopedName: 'feature_type-1'
},
{
operationName: 'GetFeature',
identifier: 'foo2',
scopedName: 'feature_type-2'
}
]
}
}

expect(getCoupledResources(metadata)).toMatchSnapshot()
})

it('should dedup duplicated coupled resources', () => {
const metadata = {
identificationInfo: {
coupledResource: [
{
operationName: 'GetCapabilities',
identifier: '9fd801e3-976a-49b6-b84a-0bd448fec8d5',
scopedName: 'bati_avap_paimpol'
},
{
operationName: 'DescribeFeatureType',
identifier: '9fd801e3-976a-49b6-b84a-0bd448fec8d5',
scopedName: 'bati_avap_paimpol'
},
{
operationName: 'GetFeature',
identifier: '9fd801e3-976a-49b6-b84a-0bd448fec8d5',
scopedName: 'bati_avap_paimpol'
},
{
operationName: 'GetCapabilities',
identifier: 'e3b34f32-8081-4451-83e0-4d5fcfd36512',
scopedName: 'elr_avap_paimpol'
},
{
operationName: 'DescribeFeatureType',
identifier: 'e3b34f32-8081-4451-83e0-4d5fcfd36512',
scopedName: 'elr_avap_paimpol'
}
]
}
}

expect(getCoupledResources(metadata)).toMatchSnapshot()
})

it('should ignore incomplete resources', () => {
const metadata = {
identificationInfo: {
coupledResource: [
{
operationName: 'GetFeature',
identifier: 'foo1'
},
{
identifier: 'foo2',
scopedName: 'feature_type-2'
},
{
scopedName: 'feature_type-3'
}
]
}
}

expect(getCoupledResources(metadata)).toMatchSnapshot()
})

it('should return an empty array if there are no coupled resources', () => {
const testCases = [
[],
null,
undefined
]

for (const coupledResource of testCases) {
expect(getCoupledResources({
identificationInfo: {
coupledResource
}
})).toEqual([])
}
})
})
})
13 changes: 9 additions & 4 deletions lib/metadata/iso/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {get, pick, chain} = require('lodash')
const {get, chain, isEqual} = require('lodash')

const {isPublicURL} = require('../../utils/url')
const {getNormalizedWfsServiceLocation} = require('../common/services')
Expand Down Expand Up @@ -48,9 +48,14 @@ function getWFSServiceLocation(record) {
}

function getCoupledResources(record) {
return get(record, 'identificationInfo.coupledResource', [])
.filter(cr => (cr.identifier && cr.scopedName))
.map(cr => pick(cr, 'identifier', 'scopedName'))
return chain(
get(record, 'identificationInfo.coupledResource', [])
).filter(
cr => cr.identifier && cr.scopedName
).map(({identifier, scopedName}) => ({
identifier,
scopedName
})).uniqWith(isEqual).value()
}

module.exports = {
Expand Down

0 comments on commit e1b9b3a

Please sign in to comment.