Skip to content

Commit

Permalink
feat(metadata): mapping protocole ignDl #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Naminoshin committed May 17, 2024
1 parent 688d789 commit 05f183e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
11 changes: 9 additions & 2 deletions libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -316,6 +317,8 @@ export class Gn4FieldMapper {
}

getLinkType(url: string, protocol?: string): DatasetDistributionType {

console.log("hello proto",protocol);
if (!protocol) {
return 'link'
}
Expand All @@ -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'
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions libs/common/domain/src/lib/model/record/metadata.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export type ServiceProtocol =
| 'wmts'
| 'esriRest'
| 'ogcFeatures'
| 'ignDl'
| 'other'

export type DatasetDistributionType = 'service' | 'download' | 'link'
Expand Down
105 changes: 20 additions & 85 deletions libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
)
Expand All @@ -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<string>
// 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)
Expand All @@ -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<FieldAvailableValue[]> {
Expand All @@ -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 = [{
Expand All @@ -224,25 +180,4 @@ export class IgnApiDlComponent implements OnInit {
})
)
}

// getFieldsUnique(produit: string, param: string): Observable<FieldAvailableValue[]> {
// 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<FormatProduit>) => {
// const bucketPromises = [{
// value: buckets[0][param],
// label: buckets[0][param] || param,
// }]
// //console.log('bucket', bucketPromises)
// return Promise.all(bucketPromises)
// })
// )
// }
}
1 change: 1 addition & 0 deletions libs/ui/elements/src/lib/api-card/api-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions libs/ui/elements/src/lib/link-card/link-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
3 changes: 3 additions & 0 deletions libs/util/shared/src/lib/links/link-classifier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down

0 comments on commit 05f183e

Please sign in to comment.