openaire-library/orcid/orcid.service.ts

96 lines
3.9 KiB
TypeScript
Raw Normal View History

import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {map} from "rxjs/operators";
import {ResultLandingInfo} from "../utils/entities/resultLandingInfo";
import {CustomOptions} from "../services/servicesUtils/customOptions.class";
import {WorkV3_0} from "./orcidWork";
import {encode, toUnicode} from "punycode";
import {Observable} from "rxjs";
import {properties} from "../../../environments/environment";
@Injectable()
export class OrcidService {
constructor(private http: HttpClient) {}
getPutCode(pids: string) {
let url: string = properties.orcidAPIURL+"put-code?pids="+pids;
return this.http.get<string[]>(url, CustomOptions.registryOptions());
}
getPutCodes(pids: string[][]) {
let url: string = properties.orcidAPIURL+"put-codes";
return this.http.post<string[][]>(url, JSON.stringify(pids), CustomOptions.registryOptions());
}
getToken(code: string) {
// let url: string = "https://sandbox.orcid.org/oauth/token";
// let clientId: string = "APP-A5M3KTX6NCN67L91";
// let clientSecret: string = "96b20d71-ae06-4286-bb00-9172536c1ad4";
// let body: string = "client_id="+clientId+"&client_secret="+clientSecret+"&grant_type=authorization_code&code="+code+"&redirect_uri=http://duffy.di.uoa.gr:4300";
//let body: string = "client_id="+clientId+"&client_secret="+clientSecret+"&grant_type=authorization_code&code="+code;
// console.debug(JSON.stringify(body));
// console.debug(url);
// return this.http.post(url, JSON.stringify(body));
//.pipe(catchError(this.handleError));
console.debug(code);
let url: string = properties.orcidAPIURL+"token/save?code="+code;
return this.http.get<string>(url, CustomOptions.registryOptions());
}
getRecord() {
let url: string = properties.orcidAPIURL+"record";
return this.http.get(url, CustomOptions.registryOptions());
}
saveWork(resultLandingInfo: ResultLandingInfo, pids: string) {
let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, null);
let result = {
"pids": pids.split(","),
"work": work
};
let url: string = properties.orcidAPIURL+"work/save";
return this.http.post<any>(url, JSON.stringify(result), CustomOptions.registryOptions())
.pipe(map(res => {
console.debug(res);
if(!res) {
return null;
}
work['put-code'] = +res;
return work;
}));
}
updateWork(resultLandingInfo: ResultLandingInfo, /*orcid: string,*/ putCode: string) {
let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
// let url: string = "http://duffy.di.uoa.gr:8080/uoa-orcid-service/orcid/"+orcid+"work/"+putCode;
let url: string = properties.orcidAPIURL+"work/update/"+putCode;
return this.http.post(url, JSON.stringify(work), CustomOptions.registryOptions())
.pipe(map(res => work));
}
// getWorks() {
// let url: string = "http://duffy.di.uoa.gr:8080/uoa-orcid-service/orcid/works?orcid=0000-0001-9541-4617";
// return this.http.get(url, CustomOptions.registryOptions());
// }
getWorks(pids: string) {
let url: string = "http://duffy.di.uoa.gr:8080/uoa-orcid-service/orcid/work?orcid=0000-0001-9541-4617&pids="+pids;
return this.http.get<any[]>(url, CustomOptions.registryOptions());
}
deleteWork(putCode: string) {
let url: string = properties.orcidAPIURL+"work/"+putCode+"/delete";
return this.http.delete(url, CustomOptions.registryOptions());
}
deleteWorks(putCodes: string[]) {
let url: string = properties.orcidAPIURL+"works/delete";
return this.http.post<string[]>(url, JSON.stringify(putCodes), CustomOptions.registryOptions());
}
getLocalWorks() {
let url: string = properties.orcidAPIURL+"works/local";
return this.http.get<any[]>(url, CustomOptions.registryOptions());
}
}