2021-01-13 19:23:31 +01:00
|
|
|
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) {
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"local/put-code?pids="+pids;
|
2021-01-13 19:23:31 +01:00
|
|
|
return this.http.get<string[]>(url, CustomOptions.registryOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
getPutCodes(pids: string[][]) {
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"local/put-codes";
|
|
|
|
return this.http.post<string[][]>(url, JSON.stringify(pids), CustomOptions.registryOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
getLocalWorksByPids(pids: string[][]) {
|
|
|
|
let url: string = properties.orcidAPIURL+"local/works";
|
2021-01-13 19:23:31 +01:00
|
|
|
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));
|
2021-02-10 10:01:55 +01:00
|
|
|
// console.debug(code);
|
|
|
|
let url: string = properties.orcidAPIURL+"orcid/token/save?code="+code;
|
|
|
|
return this.http.get(url, CustomOptions.registryOptions());
|
2021-01-13 19:23:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getRecord() {
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"orcid/record";
|
2021-01-13 19:23:31 +01:00
|
|
|
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
|
|
|
|
};
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"orcid/work/save";
|
2021-01-13 19:23:31 +01:00
|
|
|
return this.http.post<any>(url, JSON.stringify(result), CustomOptions.registryOptions())
|
2021-02-10 10:01:55 +01:00
|
|
|
// .pipe(map(res => {
|
|
|
|
// console.debug(res);
|
|
|
|
// if(!res) {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
// work['put-code'] = +res;
|
|
|
|
// return work;
|
|
|
|
// }));
|
|
|
|
.pipe(map(res => {
|
|
|
|
// console.debug(res);
|
|
|
|
if(!res || !res['putCode']) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
work['put-code'] = +res['putCode'];
|
|
|
|
work['created-date'] = {};
|
|
|
|
work['created-date']['value'] = res['creationDate'];
|
|
|
|
work['last-modified-date'] = {};
|
|
|
|
work['last-modified-date']['value'] = res['updateDate'];
|
|
|
|
return work;
|
|
|
|
}));
|
2021-01-13 19:23:31 +01:00
|
|
|
}
|
|
|
|
|
2021-02-10 10:01:55 +01:00
|
|
|
// updateWork(resultLandingInfo: ResultLandingInfo, pids: string, putCode: string) {
|
|
|
|
// let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
|
|
|
|
// let url: string = properties.orcidAPIURL+"orcid/work/update/"+putCode;
|
|
|
|
//
|
|
|
|
// let result = {
|
|
|
|
// "pids": pids.split(","),
|
|
|
|
// "work": work
|
|
|
|
// };
|
|
|
|
// console.log(result);
|
|
|
|
// return this.http.post(url, JSON.stringify(work), CustomOptions.registryOptions())
|
|
|
|
// .pipe(map(res => work));
|
|
|
|
// }
|
|
|
|
updateWork(resultLandingInfo: ResultLandingInfo, pids: string, putCode: string) {
|
2021-01-13 19:23:31 +01:00
|
|
|
let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
|
2021-02-10 10:01:55 +01:00
|
|
|
let result = {
|
|
|
|
"pids": pids.split(","),
|
|
|
|
"work": work
|
|
|
|
};
|
2021-01-13 19:23:31 +01:00
|
|
|
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"orcid/work/update/"+putCode;
|
|
|
|
return this.http.post(url, JSON.stringify(result), CustomOptions.registryOptions())
|
|
|
|
.pipe(map(res => {
|
|
|
|
if(!res || !res['putCode']) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
work['last-modified-date'] = {};
|
|
|
|
work['last-modified-date']['value'] = res['updateDate'];
|
|
|
|
return work;
|
|
|
|
}));
|
|
|
|
}
|
2021-01-13 19:23:31 +01:00
|
|
|
|
2021-02-10 10:01:55 +01:00
|
|
|
getOrcidWorks(putCodes: string[]) {
|
|
|
|
let url: string = properties.orcidAPIURL + "orcid/works?put_codes="+putCodes.join(",");
|
2021-01-13 19:23:31 +01:00
|
|
|
return this.http.get<any[]>(url, CustomOptions.registryOptions());
|
|
|
|
}
|
|
|
|
|
2021-02-10 10:01:55 +01:00
|
|
|
|
2021-01-13 19:23:31 +01:00
|
|
|
deleteWork(putCode: string) {
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"orcid/work/"+putCode+"/delete";
|
2021-01-13 19:23:31 +01:00
|
|
|
return this.http.delete(url, CustomOptions.registryOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteWorks(putCodes: string[]) {
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"orcid/works/delete";
|
2021-01-13 19:23:31 +01:00
|
|
|
return this.http.post<string[]>(url, JSON.stringify(putCodes), CustomOptions.registryOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
getLocalWorks() {
|
2021-02-10 10:01:55 +01:00
|
|
|
let url: string = properties.orcidAPIURL+"local/works";
|
2021-01-13 19:23:31 +01:00
|
|
|
return this.http.get<any[]>(url, CustomOptions.registryOptions());
|
|
|
|
}
|
2021-02-10 10:01:55 +01:00
|
|
|
|
|
|
|
getUserOrcid() {
|
|
|
|
let url: string = properties.orcidAPIURL+"local/orcidId";
|
|
|
|
return this.http.get(url, CustomOptions.registryOptions()).pipe(map(res => res['value']));
|
|
|
|
}
|
|
|
|
|
|
|
|
getPersonalDetails() {
|
|
|
|
let url: string = properties.orcidAPIURL+"orcid/personal-details";
|
|
|
|
return this.http.get(url, CustomOptions.registryOptions());
|
|
|
|
}
|
2021-01-13 19:23:31 +01:00
|
|
|
}
|