diff --git a/cloudapp/src/app/main/main.component.ts b/cloudapp/src/app/main/main.component.ts index f9d7efa..f86a3f4 100644 --- a/cloudapp/src/app/main/main.component.ts +++ b/cloudapp/src/app/main/main.component.ts @@ -1,4 +1,4 @@ -import { Subscription } from 'rxjs'; +import { Subscription, forkJoin } from 'rxjs'; import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { CloudAppEventsService, Entity, PageInfo, EntityType } from '@exlibris/exl-cloudapp-angular-lib'; import { RefineServiceDef } from '../models/refine-service'; @@ -9,6 +9,9 @@ import { SelectSetComponent } from '../select-set/select-set.component'; import { MatSelectChange } from '@angular/material/select'; import { Router } from '@angular/router'; import { SelectEntitiesComponent } from '../select-entities/select-entities.component'; +import { RefineService } from '../services/refine.service'; +import { HttpProxyService } from '../services/http.service'; +import { mergeMap, tap } from 'rxjs/operators'; @Component({ selector: 'app-main', @@ -29,13 +32,25 @@ export class MainComponent implements OnInit, OnDestroy { constructor( private eventsService: CloudAppEventsService, - public configService: ConfigService, - private router: Router + public configService: ConfigService, private refineService: RefineService, + private httpService: HttpProxyService, private router: Router ) { } ngOnInit() { this.serviceSelect = new FormControl(this.configService.selectedRefineService); - this.configService.getSettings().subscribe(settings=>this.refineServices=Object.values(settings.refineServices)); + this.eventsService.getInitData().pipe( + tap(res => this.httpService.setAlmaHostName(res.urls.alma) ), + mergeMap(_ => forkJoin([this.refineService.checkOrcidPermissions(), this.configService.getSettings()]))) + .subscribe(res=> { + const hasOrcidPermission = res[0]; + const settings = res[1]; + this.refineServices=Object.entries(settings.refineServices).filter(([key, value]) => { + // check permissions + if (key === `orcid`) { + return hasOrcidPermission + } + return true; + }).map(([key, value]) => value)}); this.pageLoad$ = this.eventsService.onPageLoad(this.onPageLoad); } diff --git a/cloudapp/src/app/models/refine-service.ts b/cloudapp/src/app/models/refine-service.ts index 8b82b6b..dffda7b 100644 --- a/cloudapp/src/app/models/refine-service.ts +++ b/cloudapp/src/app/models/refine-service.ts @@ -1,3 +1,7 @@ +import { RefineService } from "../services/refine.service"; + +export const ORCID_URL: string = "view/orcidForAlmaRefineCloudApp"; + export interface RefineServiceDef { name: string, url: string, @@ -118,5 +122,25 @@ export const defaultRefineServices: RefineServices = { ], "uriSubfield": "1", "correctTerm": false, - } + }, + "orcid": { + "name": "ORCID", + "url": ORCID_URL,//ORCID hostname is added as a prefix, while using this value. + "prefix": "https://orcid.org/", + "fields": [ + { "tag": "100", "subfield": "a", "indexes": ["/people/person"], "subfield2": [], "hints": [] } + ], + "uriSubfield": "1", + "correctTerm": false, + }, +// "homosaurus": { +// "name": "HOMOSAURUS", +// "url": "https://homosaurus-reconcile-csv.glitch.me/reconcile", +// "prefix": "https://homosaurus.org/v3/", +// "fields": [ +// { "tag": "100", "subfield": "a", "indexes": ["/people/person"], "subfield2": [], "hints": [] } +// ], +// "uriSubfield": "1", +// "correctTerm": false, +// } } diff --git a/cloudapp/src/app/services/http.service.ts b/cloudapp/src/app/services/http.service.ts index ce4cde1..1347f76 100644 --- a/cloudapp/src/app/services/http.service.ts +++ b/cloudapp/src/app/services/http.service.ts @@ -4,12 +4,18 @@ import { CloudAppEventsService } from "@exlibris/exl-cloudapp-angular-lib"; import { of } from "rxjs"; import { map, switchMap, tap } from "rxjs/operators"; import { environment } from '../../environments/environment'; +import { ORCID_URL } from "../models/refine-service"; @Injectable({ providedIn: 'root' }) export class HttpProxyService { private _token: string; + private almaHostName: string; + + setAlmaHostName(name) { + this.almaHostName = name; + } constructor( private events: CloudAppEventsService, @@ -18,14 +24,22 @@ export class HttpProxyService { get(uri: string, options: { params?: HttpParams, headers?: HttpHeaders } = { params: null, headers: null }) { if (!options.headers) options.headers = new HttpHeaders(); + let isOrcid = uri === ORCID_URL; + let host = environment.proxy; + if (isOrcid) { + uri = this.almaHostName + uri; + } const url = new URL(uri); + if (isOrcid) { + host = ""; + } return this.getToken().pipe( tap(token => { options.headers = options.headers .set('Authorization', `Bearer ${token}`) .set('X-Proxy-Host', url.hostname); }), - switchMap(() => this.http.get(`${environment.proxy}${url.pathname}`, options)), + switchMap(() => this.http.get(`${host}${url.pathname}`, options)), ) } diff --git a/cloudapp/src/app/services/refine.service.ts b/cloudapp/src/app/services/refine.service.ts index ef07c44..1d2d513 100644 --- a/cloudapp/src/app/services/refine.service.ts +++ b/cloudapp/src/app/services/refine.service.ts @@ -1,11 +1,11 @@ import { Injectable } from '@angular/core'; import { HttpParams } from '@angular/common/http'; import { HttpProxyService } from './http.service'; -import { RefineServiceDef, RefineQueries, RefineResponse } from '../models/refine-service'; +import { RefineServiceDef, RefineQueries, RefineResponse, ORCID_URL} from '../models/refine-service'; import { Refinements } from '../models/bib'; import { Utils } from '../utilities/utilities'; import * as crc from 'js-crc'; -import { from } from 'rxjs'; +import { Observable, from } from 'rxjs'; import { mergeMap, toArray, map } from 'rxjs/operators'; const BATCH_SIZE = 10; @@ -59,4 +59,8 @@ export class RefineService { return {uri: uri, previewUrl: previewUrl}; } + checkOrcidPermissions() : Observable{ + return this.http.get(ORCID_URL, { params: new HttpParams().set('query', 'hasOrcidCredentials') }) + .pipe(map(res => res['hasOrcidCredentials'])) + } }