From 4a8ecce1b9f4e4d43465404c33b017a2d8f935dd Mon Sep 17 00:00:00 2001 From: Charly <maeder@cines.fr> Date: Thu, 22 Jul 2021 17:25:54 +0200 Subject: [PATCH] Add process when showing catalog list to clean not found catalog in fdp-api --- src/app/publishapi/publishapi.component.ts | 11 +++++++++-- src/app/services/catalog.service.ts | 23 ++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/app/publishapi/publishapi.component.ts b/src/app/publishapi/publishapi.component.ts index 32d3a2b00..19c5c2714 100644 --- a/src/app/publishapi/publishapi.component.ts +++ b/src/app/publishapi/publishapi.component.ts @@ -36,7 +36,7 @@ export class PublishApiComponent implements OnInit { httpStatusCodes: string[]; catalogList: { title: string, catId: string, server: string }[] = []; canNext = false; - initLabelThree: boolean = false; + initLabelThree = false; ngOnInit(): void { this.openApi = new OpenApi(null, null); @@ -66,7 +66,14 @@ export class PublishApiComponent implements OnInit { server: this.getServerFromFdpApi(response2) }); }).catch( - () => this.catalogList.push({ catId: catalog.catId, title: catalog.catId, server: null })) + (error) => { + if (error.status === 404) { + this.catalogService.deleteCatalog(catalog.catId); + } else { + this.catalogList.push({ catId: catalog.catId, title: catalog.catId, server: null }); + } + } + ) ); }); Promise.all(titlePromises).finally(() => { diff --git a/src/app/services/catalog.service.ts b/src/app/services/catalog.service.ts index f839c4026..729d79ef2 100644 --- a/src/app/services/catalog.service.ts +++ b/src/app/services/catalog.service.ts @@ -1,6 +1,5 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { AppConfiguration } from '../AppConfiguration'; import { environment } from 'src/environments/environment'; import { TokenStorageService } from '../authentication/services/token-storage.service'; @@ -8,13 +7,13 @@ export interface FdpApiResponseItem { subject: { namespace: string, localName: string - }, + }; predicate: { namespace: string, localName: string - }, - object: any, - context: string + }; + object: any; + context: string; } const FDP_URL = environment.fdpUrl; @@ -26,31 +25,35 @@ export class CatalogService { httpOptionsSmartHarvester = { headers: new HttpHeaders({ - 'Authorization': 'Bearer '+ this.tokenService.getToken() + Authorization: 'Bearer ' + this.tokenService.getToken() }) }; httpOptionsFDP = { headers: new HttpHeaders({ - 'Authorization': 'Bearer '+ this.tokenService.getFDPToken() + Authorization: 'Bearer ' + this.tokenService.getFDPToken() }) }; constructor( - private appConfig: AppConfiguration, private tokenService: TokenStorageService, private http: HttpClient ) { } get smartApiUrl(): string { - return environment.smartharvesterUrl + '/harvester/api' + return environment.smartharvesterUrl + '/harvester/api'; } getAllCatalogId() { const user = this.tokenService.getUser(); - return this.http.get<{ catId: string, uuid: string }[]>(this.smartApiUrl + '/user/' + user.email + '/catalogs', this.httpOptionsSmartHarvester); + return this.http.get<{ catId: string, uuid: string }[]>(this.smartApiUrl + '/user/' + user.email + '/catalogs', + this.httpOptionsSmartHarvester); } getCatalogContentById(catId: string) { return this.http.get<FdpApiResponseItem[]>(FDP_URL + '/catalog/' + catId, this.httpOptionsFDP); } + + deleteCatalog(catId: string) { + return this.http.delete(this.smartApiUrl + '/catalog/' + catId, this.httpOptionsSmartHarvester); + } } -- GitLab