Project

General

Profile

1
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

    
11
@Injectable()
12
export class OrcidService {
13
  constructor(private http: HttpClient) {}
14

    
15
  getPutCode(pids: string) {
16
    let url: string = properties.orcidAPIURL+"local/put-code?pids="+pids;
17
    return this.http.get<string[]>(url, CustomOptions.registryOptions());
18
  }
19

    
20
  getPutCodes(pids: string[][]) {
21
    let url: string = properties.orcidAPIURL+"local/put-codes";
22
    return this.http.post<string[][]>(url, JSON.stringify(pids), CustomOptions.registryOptions());
23
  }
24

    
25
  getLocalWorksByPids(pids: string[][]) {
26
    let url: string = properties.orcidAPIURL+"local/works";
27
    return this.http.post<string[][]>(url, JSON.stringify(pids), CustomOptions.registryOptions());
28
  }
29

    
30
  getToken(code: string) {
31
    // let url: string = "https://sandbox.orcid.org/oauth/token";
32
    // let clientId: string = "APP-A5M3KTX6NCN67L91";
33
    // let clientSecret: string = "96b20d71-ae06-4286-bb00-9172536c1ad4";
34

    
35
    // let body: string = "client_id="+clientId+"&client_secret="+clientSecret+"&grant_type=authorization_code&code="+code+"&redirect_uri=http://duffy.di.uoa.gr:4300";
36
    //let body: string = "client_id="+clientId+"&client_secret="+clientSecret+"&grant_type=authorization_code&code="+code;
37
    // console.debug(JSON.stringify(body));
38
    // console.debug(url);
39
    // return this.http.post(url, JSON.stringify(body));
40
      //.pipe(catchError(this.handleError));
41
    // console.debug(code);
42
    let url: string = properties.orcidAPIURL+"orcid/token/save?code="+code;
43
    return this.http.get(url, CustomOptions.registryOptions());
44
  }
45

    
46
  getRecord() {
47
    let url: string = properties.orcidAPIURL+"orcid/record";
48
    return this.http.get(url, CustomOptions.registryOptions());
49
  }
50

    
51
  saveWork(resultLandingInfo: ResultLandingInfo, pids: string) {
52
    let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, null);
53
    let result = {
54
      "pids": pids.split(","),
55
      "work": work
56
    };
57
    let url: string = properties.orcidAPIURL+"orcid/work/save";
58
    return this.http.post<any>(url, JSON.stringify(result), CustomOptions.registryOptions())
59
                    // .pipe(map(res => {
60
                    //   console.debug(res);
61
                    //   if(!res) {
62
                    //     return null;
63
                    //   }
64
                    //   work['put-code'] = +res;
65
                    //   return work;
66
                    // }));
67
  .pipe(map(res => {
68
      // console.debug(res);
69
      if(!res || !res['putCode']) {
70
        return null;
71
      }
72
      work['put-code'] = +res['putCode'];
73
      work['created-date'] = {};
74
      work['created-date']['value'] = res['creationDate'];
75
      work['last-modified-date'] = {};
76
      work['last-modified-date']['value'] = res['updateDate'];
77
      return work;
78
    }));
79
  }
80

    
81
  // updateWork(resultLandingInfo: ResultLandingInfo, pids: string, putCode: string) {
82
  //   let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
83
  //   let url: string = properties.orcidAPIURL+"orcid/work/update/"+putCode;
84
  //
85
  //     let result = {
86
  //       "pids": pids.split(","),
87
  //       "work": work
88
  //     };
89
  //     console.log(result);
90
  //   return this.http.post(url, JSON.stringify(work), CustomOptions.registryOptions())
91
  //                   .pipe(map(res => work));
92
  // }
93
  updateWork(resultLandingInfo: ResultLandingInfo, pids: string, putCode: string) {
94
    let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
95
    let result = {
96
      "pids": pids.split(","),
97
      "work": work
98
    };
99

    
100
    let url: string = properties.orcidAPIURL+"orcid/work/update/"+putCode;
101
    return this.http.post(url, JSON.stringify(result), CustomOptions.registryOptions())
102
      .pipe(map(res => {
103
        if(!res || !res['putCode']) {
104
          return null;
105
        }
106
        work['last-modified-date'] = {};
107
        work['last-modified-date']['value'] = res['updateDate'];
108
        return work;
109
      }));
110
  }
111

    
112
  getOrcidWorks(putCodes: string[]) {
113
    let url: string = properties.orcidAPIURL + "orcid/works?put_codes="+putCodes.join(",");
114
    return this.http.get<any[]>(url, CustomOptions.registryOptions());
115
  }
116

    
117

    
118
  deleteWork(putCode: string) {
119
    let url: string = properties.orcidAPIURL+"orcid/work/"+putCode+"/delete";
120
    return this.http.delete(url, CustomOptions.registryOptions());
121
  }
122

    
123
  deleteWorks(putCodes: string[]) {
124
    let url: string = properties.orcidAPIURL+"orcid/works/delete";
125
    return this.http.post<string[]>(url, JSON.stringify(putCodes), CustomOptions.registryOptions());
126
  }
127

    
128
  getLocalWorks() {
129
    let url: string = properties.orcidAPIURL+"local/works";
130
    return this.http.get<any[]>(url, CustomOptions.registryOptions());
131
  }
132

    
133
  getUserOrcid() {
134
    let url: string = properties.orcidAPIURL+"local/orcidId";
135
    return this.http.get(url, CustomOptions.registryOptions()).pipe(map(res => res['value']));
136
  }
137

    
138
  getPersonalDetails() {
139
    let url: string = properties.orcidAPIURL+"orcid/personal-details";
140
    return this.http.get(url, CustomOptions.registryOptions());
141
  }
142
}
(4-4/5)