Skip to content

Commit

Permalink
Merge pull request #916 from geonetwork/catch-ogc-api-geom
Browse files Browse the repository at this point in the history
Datahub: Catch OGC API error for geometry
  • Loading branch information
tkohr authored Jun 26, 2024
2 parents 4e89bca + 03828b5 commit 81e72b2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
62 changes: 35 additions & 27 deletions libs/feature/record/src/lib/state/mdview.facade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,30 @@ describe('MdViewFacade', () => {
})

describe('geoDataLinksWithGeometry$', () => {
const links = [
{
type: 'download',
url: new URL('http://my-org.net/download/2.geojson'),
mimeType: 'application/geo+json',
name: 'Direct download',
},
{
type: 'service',
url: new URL('https://my-org.net/wfs'),
accessServiceProtocol: 'wfs',
name: 'my:featuretype', // FIXME: same as identifier otherwise it will be lost in iso...
description: 'This WFS service offers direct download capability',
identifierInService: 'my:featuretype',
},
{
type: 'service',
url: new URL('https://my-org.net/ogc'),
accessServiceProtocol: 'ogcFeatures',
name: 'my:featuretype',
description: 'This OGC service offers direct download capability',
identifierInService: 'my:featuretype',
},
]
beforeEach(() => {
testScheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected)
Expand All @@ -251,32 +275,6 @@ describe('MdViewFacade', () => {
})
})
it('should return OGC links that have geometry', fakeAsync(() => {
const values = {
a: [
{
type: 'download',
url: new URL('http://my-org.net/download/2.geojson'),
mimeType: 'application/geo+json',
name: 'Direct download',
},
{
type: 'service',
url: new URL('https://my-org.net/wfs'),
accessServiceProtocol: 'wfs',
name: 'my:featuretype', // FIXME: same as identifier otherwise it will be lost in iso...
description: 'This WFS service offers direct download capability',
identifierInService: 'my:featuretype',
},
{
type: 'service',
url: new URL('https://my-org.net/ogc'),
accessServiceProtocol: 'ogcFeatures',
name: 'my:featuretype',
description: 'This OGC service offers direct download capability',
identifierInService: 'my:featuretype',
},
],
}
jest.spyOn(facade.dataService, 'getItemsFromOgcApi').mockResolvedValue({
id: '123',
type: 'Feature',
Expand All @@ -291,7 +289,17 @@ describe('MdViewFacade', () => {
let result
facade.geoDataLinksWithGeometry$.subscribe((v) => (result = v))
tick()
expect(result).toEqual(values.a)
expect(result).toEqual(links)
}))
it('should return links that have geometry if OGC API does not respond', fakeAsync(() => {
jest
.spyOn(facade.dataService, 'getItemsFromOgcApi')
.mockRejectedValue(new Error('An error occurred'))
let result
facade.geoDataLinksWithGeometry$.subscribe((v) => (result = v))
tick()
const linksWithoutOgcApi = links.slice(0, -1)
expect(result).toEqual(linksWithoutOgcApi)
}))
it('should not return OGC links that do not have geometry', fakeAsync(() => {
const values = {
Expand Down
8 changes: 6 additions & 2 deletions libs/feature/record/src/lib/state/mdview.facade.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable } from '@angular/core'
import { select, Store } from '@ngrx/store'
import {
catchError,
defaultIfEmpty,
filter,
map,
mergeMap,
scan,
switchMap,
toArray,
} from 'rxjs/operators'
Expand Down Expand Up @@ -119,7 +119,11 @@ export class MdViewFacade {
? link
: null
}),
defaultIfEmpty(null)
defaultIfEmpty(null),
catchError((e) => {
console.error(e)
return of(null)
})
)
} else {
return of(link)
Expand Down

0 comments on commit 81e72b2

Please sign in to comment.