1
|
import {Injectable} from '@angular/core';
|
2
|
import {Jsonp, URLSearchParams} from '@angular/http';
|
3
|
import {Http, Response} from '@angular/http';
|
4
|
import { Headers, RequestOptions } from '@angular/http';
|
5
|
import {Observable} from 'rxjs/Observable';
|
6
|
import {OpenaireProperties} from '../openaireProperties';
|
7
|
|
8
|
@Injectable()
|
9
|
export class SearchOrcidService {
|
10
|
constructor(private jsonp: Jsonp, private http: Http) {}
|
11
|
|
12
|
searchOrcidAuthor (term: string, authorIds: string[],
|
13
|
authorGivenNames: string[], authorFamilyNames: string[]):any {
|
14
|
console.info("In searchOrcidAuthor: "+term);
|
15
|
|
16
|
var headers = new Headers();
|
17
|
headers.append('Accept', 'application/orcid+json');
|
18
|
|
19
|
let url = OpenaireProperties.getSearchOrcidURL()+term+'/orcid-bio';
|
20
|
|
21
|
return this.http.get(url, { headers: headers })
|
22
|
.map(res => res.json()['orcid-profile'])
|
23
|
.map(res => [res['orcid-bio']['personal-details']['given-names'],
|
24
|
res['orcid-bio']['personal-details']['family-name'],
|
25
|
res['orcid-identifier']])
|
26
|
.map(res => this.parseOrcidAuthor(res, authorIds, authorGivenNames, authorFamilyNames));
|
27
|
}
|
28
|
|
29
|
searchOrcidAuthors (term: string, authorIds: string[],
|
30
|
authorGivenNames: string[], authorFamilyNames: string[]):any {
|
31
|
console.info("In search Orcid authors for keyword: "+term);
|
32
|
|
33
|
var headers = new Headers();
|
34
|
headers.append('Accept', 'application/orcid+json');
|
35
|
|
36
|
let url = OpenaireProperties.getSearchOrcidURL()+'search/orcid-bio?defType=edismax&q='+term+'&qf=given-name^1.0+family-name^2.0+other-names^1.0+credit-name^1.0&start=0&rows=10';
|
37
|
|
38
|
return this.http.get(url, { headers: headers })
|
39
|
.map(res => res.json()['orcid-search-results']['orcid-search-result'])
|
40
|
.map(res => this.parseOrcidAuthors(res, authorIds, authorGivenNames, authorFamilyNames));
|
41
|
/*
|
42
|
.flatMap(res => res['orcid-search-result'])
|
43
|
.map(res => res['orcid-profile'])
|
44
|
.map(res => [res['orcid-bio']['personal-details']['given-names'],
|
45
|
res['orcid-bio']['personal-details']['family-name'],
|
46
|
res['orcid-identifier']]);
|
47
|
*/
|
48
|
}
|
49
|
|
50
|
searchOrcidPublications (id: string):any {
|
51
|
console.info("In search Orcid publications for author: "+id);
|
52
|
|
53
|
var headers = new Headers();
|
54
|
headers.append('Accept', 'application/orcid+json');
|
55
|
|
56
|
let url = OpenaireProperties.getSearchOrcidURL()+id+'/orcid-works';
|
57
|
|
58
|
return this.http.get(url, { headers: headers })
|
59
|
.map(res => res.json()['orcid-profile']['orcid-activities']['orcid-works']);
|
60
|
//.map(res => res['orcid-work']);
|
61
|
}
|
62
|
|
63
|
|
64
|
parseOrcidAuthor (data: any, authorIds: string[],
|
65
|
authorGivenNames: string[], authorFamilyNames: string[]):any {
|
66
|
|
67
|
if(data[2] != null) {
|
68
|
authorIds.push(data[2].path);
|
69
|
|
70
|
if(data[0] != null) {
|
71
|
authorGivenNames.push(data[0].value);
|
72
|
} else {
|
73
|
authorGivenNames.push("");
|
74
|
}
|
75
|
if(data[1] != null) {
|
76
|
authorFamilyNames.push(data[1].value);
|
77
|
} else {
|
78
|
authorFamilyNames.push("");
|
79
|
}
|
80
|
|
81
|
return true;
|
82
|
}
|
83
|
|
84
|
return false;
|
85
|
}
|
86
|
|
87
|
parseOrcidAuthors (data: any, authorIds: string[],
|
88
|
authorGivenNames: string[], authorFamilyNames: string[]):any {
|
89
|
let ret: boolean = false;
|
90
|
let mydata: any;
|
91
|
let length: number;
|
92
|
|
93
|
if(data != null) {
|
94
|
length = data.length!=undefined ? data.length : 1;
|
95
|
|
96
|
for(let i=0; i<length; i++) {
|
97
|
mydata = length > 1 ? data[i] : data;
|
98
|
|
99
|
if(mydata.hasOwnProperty("orcid-profile")) {
|
100
|
if(mydata['orcid-profile'].hasOwnProperty("orcid-identifier")) {
|
101
|
authorIds.push(mydata['orcid-profile']['orcid-identifier'].path);
|
102
|
|
103
|
if(mydata['orcid-profile'].hasOwnProperty("orcid-bio")) {
|
104
|
if(mydata['orcid-profile']['orcid-bio'].hasOwnProperty("personal-details")) {
|
105
|
if(mydata['orcid-profile']['orcid-bio']['personal-details'].hasOwnProperty("given-names")) {
|
106
|
authorGivenNames.push(mydata['orcid-profile']['orcid-bio']['personal-details']['given-names'].value);
|
107
|
} else {
|
108
|
authorGivenNames.push("");
|
109
|
}
|
110
|
|
111
|
if(mydata['orcid-profile']['orcid-bio']['personal-details'].hasOwnProperty("family-name")) {
|
112
|
authorFamilyNames.push(mydata['orcid-profile']['orcid-bio']['personal-details']['family-name'].value);
|
113
|
} else {
|
114
|
authorFamilyNames.push("");
|
115
|
}
|
116
|
}
|
117
|
}
|
118
|
ret = true;
|
119
|
}
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
return ret;
|
124
|
}
|
125
|
}
|