From 05f183e1c1a85a73c5cf64197d1ae0c2edb52498 Mon Sep 17 00:00:00 2001 From: Ronan Date: Fri, 17 May 2024 14:54:04 +0200 Subject: [PATCH] feat(metadata): mapping protocole ignDl #1 --- .../src/lib/common/distribution.mapper.ts | 1 + .../src/lib/gn4/gn4.field.mapper.ts | 11 +- .../src/lib/model/record/metadata.model.ts | 1 + .../lib/ign-api-dl/ign-api-dl.component.ts | 105 ++++-------------- .../src/lib/api-card/api-card.component.ts | 1 + .../src/lib/link-card/link-card.component.ts | 4 + .../src/lib/links/link-classifier.service.ts | 3 + 7 files changed, 39 insertions(+), 87 deletions(-) diff --git a/libs/api/metadata-converter/src/lib/common/distribution.mapper.ts b/libs/api/metadata-converter/src/lib/common/distribution.mapper.ts index e5d66e3b66..7c53f46fe8 100644 --- a/libs/api/metadata-converter/src/lib/common/distribution.mapper.ts +++ b/libs/api/metadata-converter/src/lib/common/distribution.mapper.ts @@ -7,6 +7,7 @@ export function matchProtocol(protocol: string): ServiceProtocol { if (/wps/i.test(protocol)) return 'wps' if (/ogc\W*api\W*features/i.test(protocol)) return 'ogcFeatures' if (/esri/i.test(protocol)) return 'esriRest' + if (/DOWNLOAD-1/i.test(protocol)) return 'ignDl' return 'other' } diff --git a/libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.ts b/libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.ts index cda6afbc21..084a64060e 100644 --- a/libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.ts +++ b/libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.ts @@ -135,6 +135,7 @@ export class Gn4FieldMapper { const distributions = rawLinks .map((link) => this.mapLink(link)) .filter((v) => v !== null) + console.log("je suis la distribution" ,distributions) return { ...output, distributions, @@ -316,6 +317,8 @@ export class Gn4FieldMapper { } getLinkType(url: string, protocol?: string): DatasetDistributionType { + + console.log("hello proto",protocol); if (!protocol) { return 'link' } @@ -324,7 +327,8 @@ export class Gn4FieldMapper { /^OGC:WMS/.test(protocol) || /^OGC:WFS/.test(protocol) || /^OGC:WMTS/.test(protocol) || - /ogc\W*api\W*features/i.test(protocol) + /ogc\W*api\W*features/i.test(protocol)|| + /^WWW:DOWNLOAD-/.test(protocol) ) { return 'service' } @@ -367,12 +371,15 @@ export class Gn4FieldMapper { const accessServiceProtocol = matchProtocol(protocol) const mimeTypeMatches = protocol && protocol.match(/^WWW:DOWNLOAD:(.+\/.+)$/) + console.log("je suis le mimetypeMatches" ,mimeTypeMatches) const mimeType = mimeTypeMatches && mimeTypeMatches[1] - + console.log("je suis le mimeTyep", mimeType) const distribution = { ...(name && { name }), ...(description && { description }), } + console.log("hello type",type); + switch (type) { case 'service': return { diff --git a/libs/common/domain/src/lib/model/record/metadata.model.ts b/libs/common/domain/src/lib/model/record/metadata.model.ts index 38ebcd6e1e..be0e6c3087 100644 --- a/libs/common/domain/src/lib/model/record/metadata.model.ts +++ b/libs/common/domain/src/lib/model/record/metadata.model.ts @@ -99,6 +99,7 @@ export type ServiceProtocol = | 'wmts' | 'esriRest' | 'ogcFeatures' + | 'ignDl' | 'other' export type DatasetDistributionType = 'service' | 'download' | 'link' diff --git a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts index 83f3657709..a889232838 100644 --- a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts +++ b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts @@ -94,20 +94,20 @@ export class IgnApiDlComponent implements OnInit { apiQueryUrl$ = combineLatest([this.zone$, this.format$,this.editionDate$,this.spatialDatasetIdentifierCode$]).pipe( map(([zone, format, editionDate,spatialDatasetIdentifierCode]) => { console.log('on change de valeur') - let outputUrl - if (this.apiBaseUrl) { - const url = new URL(this.apiBaseUrl) // initialisation de l'url avec l'url de base - const params = { zone: zone, format: format, editionDate: editionDate ,spatialDatasetIdentifierCode: spatialDatasetIdentifierCode} // initialisation des paramètres de filtres - for (const [key, value] of Object.entries(params)) { - if (value && value !== '0') { - url.searchParams.set(key, value) - } else { - url.searchParams.delete(key) - } + if(!this.apiBaseUrl){ + return null; + } + const url = new URL(this.apiBaseUrl) // initialisation de l'url avec l'url de base + const params = { zone: zone, format: format, editionDate: editionDate ,spatialDatasetIdentifierCode: spatialDatasetIdentifierCode} // initialisation des paramètres de filtres + for (const [key, value] of Object.entries(params)) { + if (value && value !== '0') { + url.searchParams.set(key, value) + } else { + url.searchParams.delete(key) } - outputUrl = url.toString() - console.log(outputUrl) } + let outputUrl = url.toString() + console.log(outputUrl) return outputUrl }) ) @@ -124,39 +124,6 @@ export class IgnApiDlComponent implements OnInit { tap((el) => console.log(el)) ) } - // getSubProduct(url: string) { - // return this.http - // .get(url, { headers: { accept: 'application/json' } }) - // .pipe(map((response) => response['entry'].map((el) => el['id']))) - // } - - // getDownloadLink(url: string) { - // return this.http - // .get(url, { headers: { accept: 'application/json' } }) - // .pipe(map((response) => response['entry'])) - // } - // getProduct(){ - // return this.apiQueryUrl$.pipe( - // concatMap(url=> this.getSubProduct(url).pipe( - // map((link) => { - // const element = [] as Array - // for (let indexLink = 0; indexLink < link.length; indexLink++) { - // const elementToAdd = this.getDownloadLink(link[indexLink]).subscribe( - // // eslint-disable-next-line prefer-spread - // (linkDownload) => element.push.apply(element, linkDownload) - // ) - // } - // console.log("sortie de requete produit : ",element) - // return element - // }) - // ))) - // } - - // getClassForFilter(index: number) { - // return ( - // (this.isOpen ? 'block' : 'hidden') + ' ' + (index < 2 ? 'sm:block' : '') - // ) - // } setEditionDate(value: string) { this.editionDate$.next(value) @@ -176,22 +143,10 @@ export class IgnApiDlComponent implements OnInit { } resetUrl() { - // this.offset$.next(DEFAULT_PARAMS.OFFSET) this.zone$.next(this.choicesZone$[0]) this.format$.next(this.choicesFormat$[0]) } - // getProduit(response){ - - // console.log('produit dans le html',response) - // } - - // rechercheProduit(){ - // console.log('bouton apuyer'); - // //this.zone$.next(this.zoneFiltree) - // this.format$.next(this.formatFiltree) - // } - url = 'https://data.geopf.fr/telechargement/capabilities' getFields(produit: string, param: string): Observable { @@ -205,13 +160,14 @@ export class IgnApiDlComponent implements OnInit { ), tap((el) => console.log(el)), switchMap((buckets: FormatProduit) => { - if (param != 'editionDate' && param != 'spatialDatasetIdentifierCode' ) { - console.log(typeof(buckets[param])); - const bucketPromises = buckets[param].map((bucket) => ({ - value: bucket.label, - label: bucket.term || param, - })) - return Promise.all(bucketPromises)} + if (param != 'editionDate' && param != 'spatialDatasetIdentifierCode' ) { + console.log(typeof(buckets[param])); + const bucketPromises = buckets[param].map((bucket) => ({ + value: bucket.label, + label: bucket.term || param, + })) + return Promise.all(bucketPromises); + } else{ console.log(typeof(buckets[param])); const bucketPromises = [{ @@ -224,25 +180,4 @@ export class IgnApiDlComponent implements OnInit { }) ) } - - // getFieldsUnique(produit: string, param: string): Observable { - // return this.http.get(this.url).pipe( - // map((response) => - // (response as Field).entry.filter( - // (element) => - // element['id'] == - // 'https://data.geopf.fr/telechargement/resource/'.concat(produit) - // ) - // ), - // tap((el) => console.log(el)), - // switchMap((buckets: Array) => { - // const bucketPromises = [{ - // value: buckets[0][param], - // label: buckets[0][param] || param, - // }] - // //console.log('bucket', bucketPromises) - // return Promise.all(bucketPromises) - // }) - // ) - // } } diff --git a/libs/ui/elements/src/lib/api-card/api-card.component.ts b/libs/ui/elements/src/lib/api-card/api-card.component.ts index 3b47fc48a5..f1b9ecc591 100644 --- a/libs/ui/elements/src/lib/api-card/api-card.component.ts +++ b/libs/ui/elements/src/lib/api-card/api-card.component.ts @@ -27,6 +27,7 @@ export class ApiCardComponent implements OnInit, OnChanges { ngOnInit() { this.displayApiFormButton = this.link.accessServiceProtocol === 'ogcFeatures' ? true : false + console.log("je suis le link", this.link) } ngOnChanges(changes: SimpleChanges) { diff --git a/libs/ui/elements/src/lib/link-card/link-card.component.ts b/libs/ui/elements/src/lib/link-card/link-card.component.ts index 8cea45b83e..2de23a52f6 100644 --- a/libs/ui/elements/src/lib/link-card/link-card.component.ts +++ b/libs/ui/elements/src/lib/link-card/link-card.component.ts @@ -9,4 +9,8 @@ import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record' }) export class LinkCardComponent { @Input() link: DatasetDistribution + + ngOnInit() { + console.log("je suis le link de lien", this.link) + } } diff --git a/libs/util/shared/src/lib/links/link-classifier.service.ts b/libs/util/shared/src/lib/links/link-classifier.service.ts index a900e0400e..0a6d30318f 100644 --- a/libs/util/shared/src/lib/links/link-classifier.service.ts +++ b/libs/util/shared/src/lib/links/link-classifier.service.ts @@ -25,8 +25,11 @@ export class LinkClassifierService { case 'wms': case 'wmts': return [LinkUsage.API, LinkUsage.MAP_API] + case 'ogcFeatures': return [LinkUsage.API] + case 'ignDl': + return [LinkUsage.API, LinkUsage.DOWNLOAD] default: return [LinkUsage.UNKNOWN] }