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+"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+"put-codes";
22
    return this.http.post<string[][]>(url, JSON.stringify(pids), CustomOptions.registryOptions());
23
  }
24

    
25
  getToken(code: string) {
26
    // let url: string = "https://sandbox.orcid.org/oauth/token";
27
    // let clientId: string = "APP-A5M3KTX6NCN67L91";
28
    // let clientSecret: string = "96b20d71-ae06-4286-bb00-9172536c1ad4";
29

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

    
41
  getRecord() {
42
    let url: string = properties.orcidAPIURL+"record";
43
    return this.http.get(url, CustomOptions.registryOptions());
44
  }
45

    
46
  saveWork(resultLandingInfo: ResultLandingInfo, pids: string) {
47
    let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, null);
48
    let result = {
49
      "pids": pids.split(","),
50
      "work": work
51
    };
52
    let url: string = properties.orcidAPIURL+"work/save";
53
    return this.http.post<any>(url, JSON.stringify(result), CustomOptions.registryOptions())
54
                    .pipe(map(res => {
55
                      console.debug(res);
56
                      if(!res) {
57
                        return null;
58
                      }
59
                      work['put-code'] = +res;
60
                      return work;
61
                    }));
62
  }
63

    
64
  updateWork(resultLandingInfo: ResultLandingInfo, /*orcid: string,*/ putCode: string) {
65
    let work = WorkV3_0.resultLandingInfoConvert(resultLandingInfo, putCode);
66
    // let url: string = "http://duffy.di.uoa.gr:8080/uoa-orcid-service/orcid/"+orcid+"work/"+putCode;
67
    let url: string = properties.orcidAPIURL+"work/update/"+putCode;
68
    return this.http.post(url, JSON.stringify(work), CustomOptions.registryOptions())
69
                    .pipe(map(res => work));
70
  }
71

    
72
  // getWorks() {
73
  //   let url: string = "http://duffy.di.uoa.gr:8080/uoa-orcid-service/orcid/works?orcid=0000-0001-9541-4617";
74
  //   return this.http.get(url, CustomOptions.registryOptions());
75
  // }
76

    
77
  getWorks(pids: string) {
78
    let url: string = "http://duffy.di.uoa.gr:8080/uoa-orcid-service/orcid/work?orcid=0000-0001-9541-4617&pids="+pids;
79
    return this.http.get<any[]>(url, CustomOptions.registryOptions());
80
  }
81

    
82
  deleteWork(putCode: string) {
83
    let url: string = properties.orcidAPIURL+"work/"+putCode+"/delete";
84
    return this.http.delete(url, CustomOptions.registryOptions());
85
  }
86

    
87
  deleteWorks(putCodes: string[]) {
88
    let url: string = properties.orcidAPIURL+"works/delete";
89
    return this.http.post<string[]>(url, JSON.stringify(putCodes), CustomOptions.registryOptions());
90
  }
91

    
92
  getLocalWorks() {
93
    let url: string = properties.orcidAPIURL+"works/local";
94
    return this.http.get<any[]>(url, CustomOptions.registryOptions());
95
  }
96
}
(4-4/5)