1
|
import {Injectable} from '@angular/core';
|
2
|
import {URLSearchParams} from '@angular/http';
|
3
|
import {Http, Response} from '@angular/http';
|
4
|
import { Headers, RequestOptions } from '@angular/http';
|
5
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
6
|
import {Observable} from 'rxjs';
|
7
|
import{EnvProperties} from '../../../utils/properties/env-properties';
|
8
|
|
9
|
|
10
|
|
11
|
import { ClaimResult} from '../claimEntities.class';
|
12
|
import {map} from "rxjs/operators";
|
13
|
|
14
|
@Injectable()
|
15
|
export class SearchOrcidService {
|
16
|
constructor( private http: HttpClient ) {}
|
17
|
|
18
|
|
19
|
searchOrcidAuthor (term: string, authorIds: string[], authors, properties:EnvProperties, addId):any {
|
20
|
|
21
|
//var headers = new Headers();
|
22
|
//headers.append('Accept', 'application/orcid+json');
|
23
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
24
|
|
25
|
let url = properties.searchOrcidURL + term+'/record';
|
26
|
let key = url;
|
27
|
|
28
|
return this.http.get(url, { headers: headers })
|
29
|
//.map(res => res.json()['person'])
|
30
|
.pipe(map(res => res['person']))
|
31
|
.pipe(map(res => [res['name']['given-names'],
|
32
|
res['name']['family-name'],
|
33
|
res['name']]))
|
34
|
.pipe(map(res => this.parseOrcidAuthor(res, authorIds, authors, addId)));
|
35
|
}
|
36
|
|
37
|
searchOrcidAuthors (term: string, authorIds: string[],
|
38
|
properties:EnvProperties):any {
|
39
|
|
40
|
//var headers = new Headers();
|
41
|
//headers.append('Accept', 'application/orcid+json');
|
42
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
43
|
|
44
|
let url = properties.searchOrcidURL+'search?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';
|
45
|
let key = url;
|
46
|
|
47
|
return this.http.get(url, { headers: headers })
|
48
|
//.map(res => res.json()['result'])
|
49
|
.pipe(map(res => res['result']))
|
50
|
.pipe(map(res => this.parseOrcidAuthors(res, authorIds)));
|
51
|
|
52
|
}
|
53
|
|
54
|
searchOrcidPublications (id: string, properties:EnvProperties, parse:boolean = false):any {
|
55
|
|
56
|
//var headers = new Headers();
|
57
|
//headers.append('Accept', 'application/orcid+json');
|
58
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
59
|
|
60
|
let url =properties.searchOrcidURL+id+'/works';
|
61
|
let key = url;
|
62
|
|
63
|
return this.http.get(url, { headers: headers })
|
64
|
//.map(res => res.json()['group'])
|
65
|
.pipe(map(res => res['group']))
|
66
|
.pipe(map(request => (parse?this.parse(id, request):request)));
|
67
|
//.map(res => res['orcid-work']);
|
68
|
}
|
69
|
|
70
|
|
71
|
parseOrcidAuthor (data: any, authorIds: string[],authors, addId):any {
|
72
|
|
73
|
if(data[2] != null) {
|
74
|
if(addId){
|
75
|
authorIds.push(data[2].path);
|
76
|
}
|
77
|
var author ={};
|
78
|
author['id']=data[2].path;
|
79
|
if(data[0] != null) {
|
80
|
author['authorGivenName']=data[0].value;
|
81
|
} else {
|
82
|
author['authorGivenName']="";
|
83
|
}
|
84
|
if(data[1] != null) {
|
85
|
author['authorFamilyName']=data[1].value;
|
86
|
} else {
|
87
|
author['authorFamilyName']="";
|
88
|
}
|
89
|
authors.push(author);
|
90
|
|
91
|
return true;
|
92
|
}
|
93
|
|
94
|
return false;
|
95
|
}
|
96
|
|
97
|
parseOrcidAuthors (data: any, authorIds: string[]):any {
|
98
|
let ret: boolean = false;
|
99
|
let mydata: any;
|
100
|
let length: number;
|
101
|
|
102
|
if(data != null) {
|
103
|
length = data.length!=undefined ? data.length : 1;
|
104
|
|
105
|
for(let i=0; i<length; i++) {
|
106
|
mydata = data.length!=undefined ? data[i] : data;
|
107
|
|
108
|
if(mydata.hasOwnProperty("orcid-identifier")) {
|
109
|
authorIds.push(mydata['orcid-identifier'].path);
|
110
|
|
111
|
// if(mydata.hasOwnProperty("orcid-bio")) {
|
112
|
// if(mydata['orcid-bio'].hasOwnProperty("personal-details")) {
|
113
|
// if(mydata['orcid-bio']['personal-details'].hasOwnProperty("given-names")) {
|
114
|
// authorGivenNames.push(mydata['orcid-bio']['personal-details']['given-names'].value);
|
115
|
// } else {
|
116
|
// authorGivenNames.push("");
|
117
|
// }
|
118
|
//
|
119
|
// if(mydata['orcid-bio']['personal-details'].hasOwnProperty("family-name")) {
|
120
|
// authorFamilyNames.push(mydata['orcid-bio']['personal-details']['family-name'].value);
|
121
|
// } else {
|
122
|
// authorFamilyNames.push("");
|
123
|
// }
|
124
|
// }
|
125
|
// }
|
126
|
ret = true;
|
127
|
}
|
128
|
|
129
|
}
|
130
|
}
|
131
|
return ret;
|
132
|
}
|
133
|
parse(authorId, response):ClaimResult[]{
|
134
|
var results:ClaimResult[] = [];
|
135
|
for(var i=0; i<response.length; i++){
|
136
|
var item=response[i];
|
137
|
var result:ClaimResult = new ClaimResult();
|
138
|
result.DOI = null;
|
139
|
result.url = null;
|
140
|
result.publisher = null;
|
141
|
result.journal = null;
|
142
|
if(item['work-summary'] && item['work-summary'].length > 0){
|
143
|
item = item['work-summary'][0];
|
144
|
}else{
|
145
|
item['work-summary'];
|
146
|
}
|
147
|
if(item['external-ids'] && item['external-ids']['external-id']){
|
148
|
for(var j =0; j< item['external-ids']['external-id'].length; j++){
|
149
|
var id = item['external-ids']['external-id'][j];
|
150
|
if(id['external-id-type'] == "doi"){
|
151
|
result.DOI = id['external-id-value'];
|
152
|
result.url = "http://dx.doi.org/" + result.DOI;
|
153
|
break;
|
154
|
}
|
155
|
}
|
156
|
}
|
157
|
result.id = authorId+"-"+item['put-code'];
|
158
|
if(item.title && item.title.title){
|
159
|
result.title = item['title']['title'].value;
|
160
|
}
|
161
|
result.journal = item['journal-title'];
|
162
|
result.source = 'orcid';
|
163
|
result.type = 'publication';
|
164
|
if(item['publication-date'] && item['publication-date']['year']){
|
165
|
result.date = item['publication-date']['year'].value
|
166
|
}
|
167
|
|
168
|
result.accessRights = "OPEN";
|
169
|
if(item.publisher){
|
170
|
result.publisher = item.publisher;
|
171
|
}
|
172
|
result.result = item;
|
173
|
|
174
|
results.push(result);
|
175
|
}
|
176
|
|
177
|
return results;
|
178
|
|
179
|
}
|
180
|
|
181
|
|
182
|
|
183
|
}
|