Skip to content

Commit

Permalink
Merge pull request #872 from geonetwork/ogc-api-fixes
Browse files Browse the repository at this point in the history
Datahub: OGC API fixes
  • Loading branch information
tkohr authored May 17, 2024
2 parents c4b41b4 + 53b7078 commit 8918855
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class DataServiceMock {
])
getDownloadLinksFromOgcApiFeatures = jest.fn((link) =>
link.url.toString().indexOf('error') > -1
? throwError(() => new Error('would not fetch links'))
: of([
? Promise.reject(new Error('ogc.unreachable.unknown'))
: Promise.resolve([
{
...link,
mimeType: 'application/geo+json',
Expand Down Expand Up @@ -233,6 +233,13 @@ describe('DataDownloadsComponent', () => {
type: 'service',
accessServiceProtocol: 'ogcFeatures',
},
{
name: 'Some erroneous OGC API service',
description: 'OGC API service',
url: newUrl('https://error.org/collections/airports/items'),
type: 'service',
accessServiceProtocol: 'ogcFeatures',
},
])
fixture.detectChanges()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,26 @@ export class RecordDownloadsComponent {
return combineLatest([
...(wfsLinks.length > 0
? wfsLinks.map((link) =>
this.dataService.getDownloadLinksFromWfs(
link as DatasetServiceDistribution
)
this.dataService
.getDownloadLinksFromWfs(link as DatasetServiceDistribution)
.pipe(
catchError((e) => {
this.error = e.message
return [of([] as DatasetDistribution[])]
})
)
)
: [of([] as DatasetDistribution[])]),
...(ogcLinks.length > 0
? ogcLinks.map((link) =>
this.dataService.getDownloadLinksFromOgcApiFeatures(
link as DatasetServiceDistribution
)
this.dataService
.getDownloadLinksFromOgcApiFeatures(
link as DatasetServiceDistribution
)
.catch((e) => {
this.error = e.message
return Promise.resolve([])
})
)
: [of([] as DatasetDistribution[])]),
]).pipe(
Expand Down
8 changes: 8 additions & 0 deletions libs/common/fixtures/src/lib/link.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export const LINK_FIXTURES: Record<string, DatasetDistribution> = deepFreeze({
url: new URL('https://my.ogc.server/wfs'),
accessServiceProtocol: 'wfs',
},
geodataWfsDownload: {
name: 'mylayer',
type: 'download',
url: new URL(
'https://my.ogc.server/wfs?GetFeature&FeatureType=surval_parametre_ligne&format=csv'
),
accessServiceProtocol: 'wfs',
},
geodataWms2: {
name: 'myotherlayer',
type: 'service',
Expand Down
68 changes: 46 additions & 22 deletions libs/feature/dataviz/src/lib/service/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ jest.mock('@camptocamp/ogc-client', () => ({
newEndpointCall(url) // to track endpoint creation
}
getCollectionInfo() {
if (this.url.indexOf('error.http') > -1) {
return Promise.reject({
type: 'http',
info: 'Something went wrong',
httpStatus: 403,
})
}
return Promise.resolve({
bulkDownloadLinks: { json: 'http://json', csv: 'http://csv' },
})
Expand Down Expand Up @@ -457,30 +464,47 @@ describe('DataService', () => {
})

describe('#getDownloadLinksFromOgcApiFeatures', () => {
it('returns links with formats for link', async () => {
const url = new URL('https://my.ogc.api/features')
const links = await service.getDownloadLinksFromOgcApiFeatures({
name: 'mycollection',
url,
type: 'service',
accessServiceProtocol: 'ogcFeatures',
})
expect(links).toEqual([
{
describe('calling getDownloadLinksFromOgcApiFeatures() with a valid URL', () => {
it('returns links with formats for link', async () => {
const url = new URL('https://my.ogc.api/features')
const links = await service.getDownloadLinksFromOgcApiFeatures({
name: 'mycollection',
mimeType: 'application/json',
url: new URL('http://json'),
type: 'download',
accessServiceProtocol: 'ogcFeatures',
},
{
name: 'mycollection',
mimeType: 'text/csv',
url: new URL('http://csv'),
type: 'download',
url,
type: 'service',
accessServiceProtocol: 'ogcFeatures',
},
])
})
expect(links).toEqual([
{
name: 'mycollection',
mimeType: 'application/json',
url: new URL('http://json'),
type: 'download',
accessServiceProtocol: 'ogcFeatures',
},
{
name: 'mycollection',
mimeType: 'text/csv',
url: new URL('http://csv'),
type: 'download',
accessServiceProtocol: 'ogcFeatures',
},
])
})
})
describe('calling getDownloadLinksFromOgcApiFeatures() with a erroneous URL', () => {
it('returns an error', async () => {
try {
const url = new URL('http://error.http/ogcapi')
await service.getDownloadLinksFromOgcApiFeatures({
name: 'mycollection',
url,
type: 'service',
accessServiceProtocol: 'ogcFeatures',
})
} catch (e) {
expect(e.message).toBe('ogc.unreachable.unknown')
}
})
})
})

Expand Down
21 changes: 2 additions & 19 deletions libs/feature/dataviz/src/lib/service/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ marker('wfs.unreachable.http')
marker('wfs.unreachable.unknown')
marker('wfs.featuretype.notfound')
marker('wfs.geojsongml.notsupported')
marker('ogc.unreachable.unknown')
marker('dataset.error.network')
marker('dataset.error.http')
marker('dataset.error.parse')
Expand Down Expand Up @@ -159,7 +160,6 @@ export class DataService {
const collectionInfo = await this.getDownloadUrlsFromOgcApi(
ogcApiLink.url.href
)

return Object.keys(collectionInfo.bulkDownloadLinks).map((downloadLink) => {
return {
...ogcApiLink,
Expand All @@ -179,24 +179,7 @@ export class DataService {
return endpoint.getCollectionInfo(collections[0])
})
.catch((error) => {
if (error instanceof Error) {
throw new Error(`wfs.unreachable.unknown`)
} else {
if (error.type === 'network') {
throw new Error(`wfs.unreachable.cors`)
}
if (error.type === 'http') {
throw new Error(`wfs.unreachable.http`)
}
if (error.type === 'parse') {
throw new Error(`wfs.unreachable.parse`)
}
if (error.type === 'unsupportedType') {
throw new Error(`wfs.unreachable.unsupportedType`)
} else {
throw new Error(`wfs.unreachable.unknown`)
}
}
throw new Error(`ogc.unreachable.unknown`)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ describe('DownloadsListComponent', () => {
expect(items[0].componentInstance.isFromWfs).toEqual(false)
})
})
describe('displaying download links from WFS', () => {
let items: DebugElement[]

beforeEach(() => {
component.links = [LINK_FIXTURES.geodataWfsDownload]
fixture.detectChanges()
items = de.queryAll(By.directive(MockDownloadItemComponent))
})
it('sets isFromWfs to true', () => {
expect(items[0].componentInstance.isFromWfs).toEqual(true)
})
})
describe('filtering links', () => {
beforeEach(() => {
component.links = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ export class DownloadsListComponent {
}

isFromWfs(link: DatasetDistribution) {
return link.type === 'service' && link.accessServiceProtocol === 'wfs'
return link.type === 'download' && link.accessServiceProtocol === 'wfs'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,12 @@ describe('RecordApFormComponent', () => {
])
})
})
describe('When apiLink input is undefined', () => {
it('should not call parseOutputFormats()', () => {
const spy = jest.spyOn(component, 'parseOutputFormats')
component.apiLink = undefined
fixture.detectChanges()
expect(spy).not.toHaveBeenCalled()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const DEFAULT_PARAMS = {
})
export class RecordApiFormComponent {
@Input() set apiLink(value: DatasetServiceDistribution) {
this.apiBaseUrl = value ? value.url.href : undefined
this.outputFormats = [{ value: 'json', label: 'JSON' }]
this.parseOutputFormats()
if (value) {
this.apiBaseUrl = value.url.href
this.parseOutputFormats()
}
this.resetUrl()
}
offset$ = new BehaviorSubject('')
Expand Down
23 changes: 9 additions & 14 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
"multiselect.filter.placeholder": "Suche",
"nav.back": "Zurück",
"next": "weiter",
"ogc.unreachable.unknown": "Der Dienst konnte nicht erreicht werden",
"organisation.filter.placeholder": "Ergebnisse filtern",
"organisation.sort.sortBy": "Sortieren nach:",
"organisations.hits.found": "{hits, plural, =0{Keine Organisation gefunden} other{{hits} von {total} Organisationen angezeigt}}",
Expand Down Expand Up @@ -290,14 +291,6 @@
"record.metadata.quality.updateFrequency.failed": "Aktualisierungsfrequenz nicht angegeben",
"record.metadata.quality.updateFrequency.success": "Aktualisierungsfrequenz angegeben",
"record.metadata.related": "Ähnliche Datensätze",
"record.metadata.userFeedbacks": "",
"record.metadata.userFeedbacks.anonymousUser": "",
"record.metadata.userFeedbacks.sortSelector.label": "",
"record.metadata.userFeedbacks.sortSelector.choices.newestFirst": "",
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.sheet": "Weitere Informationen verfügbar unter:",
"record.metadata.status": "Status",
"record.metadata.technical": "Technische Informationen",
Expand All @@ -312,6 +305,14 @@
"record.metadata.updateFrequency": "Aktualisierungsfrequenz der Daten",
"record.metadata.updatedOn": "Letzte Aktualisierung der Dateninformationen",
"record.metadata.usage": "Nutzung und Einschränkungen",
"record.metadata.userFeedbacks": "",
"record.metadata.userFeedbacks.anonymousUser": "",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "",
"record.metadata.userFeedbacks.newAnswer.placeholder": "",
"record.metadata.userFeedbacks.newComment.placeholder": "",
"record.metadata.userFeedbacks.sortSelector.choices.newestFirst": "",
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "",
"record.metadata.userFeedbacks.sortSelector.label": "",
"record.more.details": "Weitere Details",
"record.tab.chart": "Diagramm",
"record.tab.data": "Tabelle",
Expand Down Expand Up @@ -371,12 +372,6 @@
"table.loading.data": "Daten werden geladen...",
"table.object.count": "Objekte in diesem Datensatz",
"table.select.data": "Datenquelle",
"timeSincePipe.lessThanAMinute": "",
"timeSincePipe.minutesAgo": "",
"timeSincePipe.hoursAgo": "",
"timeSincePipe.daysAgo": "",
"timeSincePipe.monthsAgo": "",
"timeSincePipe.yearsAgo": "",
"tooltip.html.copy": "HTML kopieren",
"tooltip.id.copy": "Eindeutige Kennung kopieren",
"tooltip.url.copy": "URL kopieren",
Expand Down
23 changes: 9 additions & 14 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
"multiselect.filter.placeholder": "Search",
"nav.back": "Back",
"next": "next",
"ogc.unreachable.unknown": "The service could not be reached",
"organisation.filter.placeholder": "Filter results",
"organisation.sort.sortBy": "Sort by:",
"organisations.hits.found": "{hits, plural, =0{No organizations found} other{{hits} out of {total} organizations shown}}",
Expand Down Expand Up @@ -290,14 +291,6 @@
"record.metadata.quality.updateFrequency.failed": "Update frequency is not specified",
"record.metadata.quality.updateFrequency.success": "Update frequency is specified",
"record.metadata.related": "Related records",
"record.metadata.userFeedbacks": "Questions / Answers",
"record.metadata.userFeedbacks.anonymousUser": "In order to leave a comment, please log in.",
"record.metadata.userFeedbacks.sortSelector.label": "Sort by ...",
"record.metadata.userFeedbacks.sortSelector.choices.newestFirst": "Newest comments first",
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "Oldest comments first",
"record.metadata.userFeedbacks.newComment.placeholder": "Write your comment here...",
"record.metadata.userFeedbacks.newAnswer.placeholder": "Answer...",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "Publish",
"record.metadata.sheet": "Original metadata",
"record.metadata.status": "Status",
"record.metadata.technical": "Technical information",
Expand All @@ -312,6 +305,14 @@
"record.metadata.updateFrequency": "Data Update Frequency",
"record.metadata.updatedOn": "Last Data Information Update",
"record.metadata.usage": "License and Conditions",
"record.metadata.userFeedbacks": "Questions / Answers",
"record.metadata.userFeedbacks.anonymousUser": "In order to leave a comment, please log in.",
"record.metadata.userFeedbacks.newAnswer.buttonTitle": "Publish",
"record.metadata.userFeedbacks.newAnswer.placeholder": "Answer...",
"record.metadata.userFeedbacks.newComment.placeholder": "Write your comment here...",
"record.metadata.userFeedbacks.sortSelector.choices.newestFirst": "Newest comments first",
"record.metadata.userFeedbacks.sortSelector.choices.oldestFirst": "Oldest comments first",
"record.metadata.userFeedbacks.sortSelector.label": "Sort by ...",
"record.more.details": "Read more",
"record.tab.chart": "Chart",
"record.tab.data": "Table",
Expand Down Expand Up @@ -371,12 +372,6 @@
"table.loading.data": "Loading data...",
"table.object.count": "objects in this dataset",
"table.select.data": "Data source",
"timeSincePipe.lessThanAMinute": "Less than a minute ago",
"timeSincePipe.minutesAgo": "{value} minute{s} ago",
"timeSincePipe.hoursAgo": "{value} hour{s} ago",
"timeSincePipe.daysAgo": "{value} day{s} ago",
"timeSincePipe.monthsAgo": "{value} month{s} ago",
"timeSincePipe.yearsAgo": "{value} year{s} ago",
"tooltip.html.copy": "Copy HTML",
"tooltip.id.copy": "Copy unique identifier",
"tooltip.url.copy": "Copy URL",
Expand Down
Loading

0 comments on commit 8918855

Please sign in to comment.