From 6ed48e9715cde78914995634775b0365f55863cd Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Fri, 26 Apr 2024 08:31:08 +0200 Subject: [PATCH] feat(dh): add ogc api links to downloads section --- .../record-downloads.component.ts | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/apps/datahub/src/app/record/record-downloads/record-downloads.component.ts b/apps/datahub/src/app/record/record-downloads/record-downloads.component.ts index 65f013ed6b..ee05d3d240 100644 --- a/apps/datahub/src/app/record/record-downloads/record-downloads.component.ts +++ b/apps/datahub/src/app/record/record-downloads/record-downloads.component.ts @@ -36,33 +36,45 @@ export class RecordDownloadsComponent { link as DatasetServiceDistribution ) ) + const ogcLinks = links.filter( + (link) => + link.type === 'service' && + link.accessServiceProtocol === 'ogcFeatures' + ) + const otherLinks = links.filter( (link) => link.type !== 'service' || (link.type === 'service' && link.accessServiceProtocol !== 'esriRest' && - link.accessServiceProtocol !== 'wfs') + link.accessServiceProtocol !== 'wfs' && + link.accessServiceProtocol !== 'ogcFeatures') ) this.error = null - return combineLatest( - wfsLinks.length > 0 + return combineLatest([ + ...(wfsLinks.length > 0 ? wfsLinks.map((link) => this.dataService.getDownloadLinksFromWfs( link as DatasetServiceDistribution ) ) - : [of([] as DatasetDistribution[])] - ).pipe( + : [of([] as DatasetDistribution[])]), + ...(ogcLinks.length > 0 + ? ogcLinks.map((link) => + this.dataService.getDownloadLinksFromOgcApiFeatures( + link as DatasetServiceDistribution + ) + ) + : [of([] as DatasetDistribution[])]), + ]).pipe( map(flattenArray), map(removeLinksWithUnknownFormat), map(removeDuplicateLinks), - map((wfsDownloadLinks) => [ - ...otherLinks, - ...wfsDownloadLinks, - ...esriRestLinks, - ]), + map((downloadLinks) => { + return [...otherLinks, ...downloadLinks, ...esriRestLinks] + }), catchError((e) => { this.error = e.message return of([...otherLinks, ...esriRestLinks]) @@ -73,14 +85,16 @@ export class RecordDownloadsComponent { ) } -const flattenArray = (arrayOfArrays) => - arrayOfArrays.reduce((prev, curr) => [...prev, ...curr], []) +const flattenArray = (arrayOfArrays) => { + return arrayOfArrays.reduce((prev, curr) => [...prev, ...curr], []) +} -const removeLinksWithUnknownFormat = (wfsDownloadLinks) => - wfsDownloadLinks.filter((link) => !!getFileFormat(link)) +const removeLinksWithUnknownFormat = (downloadLinks) => { + return downloadLinks.filter((link) => !!getFileFormat(link)) +} -const removeDuplicateLinks = (wfsDownloadLinks) => - wfsDownloadLinks.filter( +const removeDuplicateLinks = (downloadLinks) => + downloadLinks.filter( (link, i, links) => links.findIndex( (firstLink) =>