1 |
61381
|
k.triantaf
|
import {Injectable} from "@angular/core";
|
2 |
|
|
import {HttpClient} from "@angular/common/http";
|
3 |
|
|
import {map} from "rxjs/operators";
|
4 |
|
|
import {ResultLandingInfo} from "../utils/entities/resultLandingInfo";
|
5 |
|
|
import {CustomOptions} from "../services/servicesUtils/customOptions.class";
|
6 |
|
|
import {WorkV3_0} from "./orcidWork";
|
7 |
|
|
import {encode, toUnicode} from "punycode";
|
8 |
|
|
import {Observable} from "rxjs";
|
9 |
|
|
import {properties} from "../../../environments/environment";
|
10 |
|
|
import {ConnectHelper} from "../connect/connectHelper";
|
11 |
|
|
|
12 |
|
|
@Injectable()
|
13 |
|
|
export class OrcidService {
|
14 |
|
|
constructor(private http: HttpClient) {}
|
15 |
|
|
|
16 |
|
|
getPutCode(pids: string) {
|
17 |
|
|
let url: string = properties.orcidAPIURL+"local/put-code?pids="+pids;
|
18 |
|
|
return this.http.get<string[]>(url, CustomOptions.registryOptions());
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
getPutCodes(pids: string[][]) {
|
22 |
|
|
let url: string = properties.orcidAPIURL+"local/put-codes";
|
23 |
|
|
return this.http.post<string[][]>(url, JSON.stringify(pids), CustomOptions.registryOptions());
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
getLocalWorksByPids(pids: string[][]) {
|
27 |
|
|
let url: string = properties.orcidAPIURL+"local/works";
|
28 |
|
|
return this.http.post<string[][]>(url, JSON.stringify(pids), CustomOptions.registryOptions());
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
getToken(code: string) {
|
32 |
|
|
// let url: string = "https://sandbox.orcid.org/oauth/token";
|
33 |
|
|
// let clientId: string = "APP-A5M3KTX6NCN67L91";
|
34 |
|
|
// let clientSecret: string = "96b20d71-ae06-4286-bb00-9172536c1ad4";
|
35 |
|
|
|
36 |
|
|
// let body: string = "client_id="+clientId+"&client_secret="+clientSecret+"&grant_type=authorization_code&code="+code+"&redirect_uri=http://duffy.di.uoa.gr:4300";
|
37 |
|
|
//let body: string = "client_id="+clientId+"&client_secret="+clientSecret+"&grant_type=authorization_code&code="+code;
|
38 |
|
|
// console.debug(JSON.stringify(body));
|
39 |
|
|
// console.debug(url);
|
40 |
|
|
// return this.http.post(url, JSON.stringify(body));
|
41 |
|
|
//.pipe(catchError(this.handleError));
|
42 |
|
|
// console.debug(code);
|
43 |
|
|
let url: string = properties.orcidAPIURL+"orcid/token/save?code="+code;
|
44 |
|
|
return this.http.get(url, CustomOptions.registryOptions());
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
getRecord() {
|
48 |
|
|
let url: string = properties.orcidAPIURL+"orcid/record";
|
49 |
|
|
return this.http.get(url, CustomOptions.registryOptions());
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
saveWork(resultLandingInfo: ResultLandingInfo, pids: string) {
|
53 |
|
|
let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, null);
|
54 |
|
|
let portalId: string = ConnectHelper.getCommunityFromDomain(properties.domain);
|
55 |
|
|
let dashboard: string = properties.environment + "_" + properties.dashboard + (portalId? "_" + portalId : "");
|
56 |
|
|
let result = {
|
57 |
|
|
"dashboard": dashboard,
|
58 |
|
|
"pids": pids.split(","),
|
59 |
|
|
"work": work
|
60 |
|
|
};
|
61 |
|
|
let url: string = properties.orcidAPIURL+"orcid/work/save";
|
62 |
|
|
return this.http.post<any>(url, JSON.stringify(result), CustomOptions.registryOptions())
|
63 |
|
|
// .pipe(map(res => {
|
64 |
|
|
// console.debug(res);
|
65 |
|
|
// if(!res) {
|
66 |
|
|
// return null;
|
67 |
|
|
// }
|
68 |
|
|
// work['put-code'] = +res;
|
69 |
|
|
// return work;
|
70 |
|
|
// }));
|
71 |
|
|
.pipe(map(res => {
|
72 |
|
|
// console.debug(res);
|
73 |
|
|
if(!res || !res['putCode']) {
|
74 |
|
|
return null;
|
75 |
|
|
}
|
76 |
|
|
work['put-code'] = +res['putCode'];
|
77 |
|
|
work['created-date'] = {};
|
78 |
|
|
work['created-date']['value'] = res['creationDate'];
|
79 |
|
|
work['last-modified-date'] = {};
|
80 |
|
|
work['last-modified-date']['value'] = res['updateDate'];
|
81 |
|
|
return work;
|
82 |
|
|
}));
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
// updateWork(resultLandingInfo: ResultLandingInfo, pids: string, putCode: string) {
|
86 |
|
|
// let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
|
87 |
|
|
// let url: string = properties.orcidAPIURL+"orcid/work/update/"+putCode;
|
88 |
|
|
//
|
89 |
|
|
// let result = {
|
90 |
|
|
// "pids": pids.split(","),
|
91 |
|
|
// "work": work
|
92 |
|
|
// };
|
93 |
|
|
// console.log(result);
|
94 |
|
|
// return this.http.post(url, JSON.stringify(work), CustomOptions.registryOptions())
|
95 |
|
|
// .pipe(map(res => work));
|
96 |
|
|
// }
|
97 |
|
|
updateWork(resultLandingInfo: ResultLandingInfo, pids: string, putCode: string) {
|
98 |
|
|
let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
|
99 |
|
|
let result = {
|
100 |
|
|
"pids": pids.split(","),
|
101 |
|
|
"work": work
|
102 |
|
|
};
|
103 |
|
|
|
104 |
|
|
let url: string = properties.orcidAPIURL+"orcid/work/update/"+putCode;
|
105 |
|
|
return this.http.post(url, JSON.stringify(result), CustomOptions.registryOptions())
|
106 |
|
|
.pipe(map(res => {
|
107 |
|
|
if(!res || !res['putCode']) {
|
108 |
|
|
return null;
|
109 |
|
|
}
|
110 |
|
|
work['last-modified-date'] = {};
|
111 |
|
|
work['last-modified-date']['value'] = res['updateDate'];
|
112 |
|
|
return work;
|
113 |
|
|
}));
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
getOrcidWorks(putCodes: string[]) {
|
117 |
|
|
let url: string = properties.orcidAPIURL + "orcid/works?put_codes="+putCodes.join(",");
|
118 |
|
|
return this.http.get<any[]>(url, CustomOptions.registryOptions());
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
deleteWork(putCode: string) {
|
123 |
|
|
let url: string = properties.orcidAPIURL+"orcid/work/"+putCode+"/delete";
|
124 |
|
|
return this.http.delete(url, CustomOptions.registryOptions());
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
deleteWorks(putCodes: string[]) {
|
128 |
|
|
let url: string = properties.orcidAPIURL+"orcid/works/delete";
|
129 |
|
|
return this.http.post<string[]>(url, JSON.stringify(putCodes), CustomOptions.registryOptions());
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
getLocalWorks() {
|
133 |
|
|
let url: string = properties.orcidAPIURL+"local/works";
|
134 |
|
|
return this.http.get<any[]>(url, CustomOptions.registryOptions());
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
getUserOrcid() {
|
138 |
|
|
let url: string = properties.orcidAPIURL+"local/orcidId";
|
139 |
|
|
return this.http.get(url, CustomOptions.registryOptions()).pipe(map(res => res['value']));
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
getPersonalDetails() {
|
143 |
|
|
let url: string = properties.orcidAPIURL+"orcid/personal-details";
|
144 |
|
|
return this.http.get(url, CustomOptions.registryOptions());
|
145 |
|
|
}
|
146 |
|
|
}
|