Skip to content

Commit

Permalink
Add ORCID refine service
Browse files Browse the repository at this point in the history
The request for ORCID service goes through Alma servlet.
  • Loading branch information
NurielsExl committed May 21, 2023
1 parent 22a0fb2 commit b4e2d57
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
23 changes: 19 additions & 4 deletions cloudapp/src/app/main/main.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -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);
}

Expand Down
26 changes: 25 additions & 1 deletion cloudapp/src/app/models/refine-service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { RefineService } from "../services/refine.service";

export const ORCID_URL: string = "view/orcidForAlmaRefineCloudApp";

export interface RefineServiceDef {
name: string,
url: string,
Expand Down Expand Up @@ -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,
// }
}
16 changes: 15 additions & 1 deletion cloudapp/src/app/services/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,14 +24,22 @@ export class HttpProxyService {

get<T = any>(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<T>(`${environment.proxy}${url.pathname}`, options)),
switchMap(() => this.http.get<T>(`${host}${url.pathname}`, options)),
)
}

Expand Down
8 changes: 6 additions & 2 deletions cloudapp/src/app/services/refine.service.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,4 +59,8 @@ export class RefineService {
return {uri: uri, previewUrl: previewUrl};
}

checkOrcidPermissions() : Observable<boolean>{
return this.http.get<object>(ORCID_URL, { params: new HttpParams().set('query', 'hasOrcidCredentials') })
.pipe(map(res => res['hasOrcidCredentials']))
}
}

0 comments on commit b4e2d57

Please sign in to comment.