1
|
import {Injectable} from '@angular/core';
|
2
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
3
|
import {EnvProperties} from '../../../utils/properties/env-properties';
|
4
|
import {ClaimEntity, ClaimResult} from '../claimHelper.class';
|
5
|
import {map} from "rxjs/operators";
|
6
|
import {StringUtils} from "../../../utils/string-utils.class";
|
7
|
|
8
|
|
9
|
@Injectable()
|
10
|
export class SearchOrcidService {
|
11
|
constructor( private http: HttpClient ) {}
|
12
|
|
13
|
|
14
|
searchOrcidAuthor(term: string, authorIds: string[], authors, properties: EnvProperties, addId): any {
|
15
|
|
16
|
//var headers = new Headers();
|
17
|
//headers.append('Accept', 'application/orcid+json');
|
18
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
19
|
|
20
|
let url = properties.searchOrcidURL + term + '/record';
|
21
|
|
22
|
return this.http.get(url, { headers: headers })
|
23
|
//.map(res => res.json()['person'])
|
24
|
.pipe(map(res => res['person']))
|
25
|
.pipe(map(res => [res['name']['given-names'],
|
26
|
res['name']['family-name'],
|
27
|
res['name']]))
|
28
|
.pipe(map(res => SearchOrcidService.parseOrcidAuthor(res, authorIds, authors, addId)));
|
29
|
}
|
30
|
|
31
|
searchOrcidAuthors(term: string,
|
32
|
properties: EnvProperties): any {
|
33
|
|
34
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
35
|
|
36
|
// 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';
|
37
|
let url = properties.searchOrcidURL+'search?q='+StringUtils.URIEncode('{!edismax qf="given-and-family-names^50.0 family-name^10.0 given-names^5.0 credit-name^10.0 other-names^5.0 text^1.0" pf="given-and-family-names^50.0" mm=1}')+term+'&start=0&rows=10';
|
38
|
|
39
|
//q={!edismax qf="given-and-family-names^50.0 family-name^10.0 given-names^5.0 credit-name^10.0 other-names^5.0 text^1.0" pf="given-and-family-names^50.0" mm=1}alessia bardi&start=0&rows=10
|
40
|
let key = url;
|
41
|
return this.http.get(url, {headers: headers})
|
42
|
.pipe(map(res => res['result']))
|
43
|
.pipe(map(res => SearchOrcidService.parseOrcidAuthors(res)));
|
44
|
|
45
|
}
|
46
|
|
47
|
|
48
|
searchOrcidPublications(id: string, properties: EnvProperties, parse: boolean = false): any {
|
49
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
50
|
let url = properties.searchOrcidURL + id + '/works';
|
51
|
return this.http.get(url, { headers: headers })
|
52
|
.pipe(map(res => res['group']))
|
53
|
.pipe(map(request => (parse ? SearchOrcidService.parse(id, request) : request)));
|
54
|
}
|
55
|
|
56
|
|
57
|
static parseOrcidAuthor(data: any, authorIds: string[], authors, addId): any {
|
58
|
if (data[2] != null) {
|
59
|
if (addId) {
|
60
|
authorIds.push(data[2].path);
|
61
|
}
|
62
|
const author = {};
|
63
|
author['id'] = data[2].path;
|
64
|
if (data[0] != null) {
|
65
|
author['authorGivenName'] = data[0].value;
|
66
|
} else {
|
67
|
author['authorGivenName'] = "";
|
68
|
}
|
69
|
if (data[1] != null) {
|
70
|
author['authorFamilyName'] = data[1].value;
|
71
|
} else {
|
72
|
author['authorFamilyName'] = "";
|
73
|
}
|
74
|
authors.push(author);
|
75
|
return true;
|
76
|
}
|
77
|
return false;
|
78
|
}
|
79
|
|
80
|
static parseOrcidAuthors(data: any): any {
|
81
|
let mydata: any;
|
82
|
let length: number;
|
83
|
let authorIds: string[] = [];
|
84
|
if (data != null) {
|
85
|
length = data.length != undefined ? data.length : 1;
|
86
|
for (let i = 0; i < length; i++) {
|
87
|
mydata = data.length != undefined ? data[i] : data;
|
88
|
if (mydata.hasOwnProperty("orcid-identifier")) {
|
89
|
authorIds.push(mydata['orcid-identifier'].path);
|
90
|
}
|
91
|
}
|
92
|
}
|
93
|
return authorIds;
|
94
|
}
|
95
|
|
96
|
static parse(authorId, response): ClaimEntity[] {
|
97
|
const results: ClaimEntity[] = [];
|
98
|
for (let i = 0; i < response.length; i++) {
|
99
|
let item = response[i];
|
100
|
const entity: ClaimEntity = new ClaimEntity();
|
101
|
entity.result = new ClaimResult();
|
102
|
entity.result.DOI = null;
|
103
|
entity.result.url = null;
|
104
|
entity.result.publisher = null;
|
105
|
entity.result.journal = null;
|
106
|
if (item['work-summary'] && item['work-summary'].length > 0) {
|
107
|
item = item['work-summary'][0];
|
108
|
} else {
|
109
|
item = item['work-summary'];
|
110
|
}
|
111
|
let handleId = null;
|
112
|
if (item['external-ids'] && item['external-ids']['external-id']) {
|
113
|
for (let j = 0; j < item['external-ids']['external-id'].length; j++) {
|
114
|
const id = item['external-ids']['external-id'][j];
|
115
|
if (id['external-id-type'] == "doi") {
|
116
|
entity.result.DOI = id['external-id-value'];
|
117
|
entity.result.url = "http://dx.doi.org/" + entity.result.DOI;
|
118
|
break;
|
119
|
}else if (id['external-id-type'] == "handle" && !handleId) {
|
120
|
handleId= id['external-id-value'];
|
121
|
break;
|
122
|
}
|
123
|
}
|
124
|
}
|
125
|
if(!entity.result.url && handleId){
|
126
|
entity.result.url = handleId;
|
127
|
|
128
|
}
|
129
|
entity.id = authorId + "-" + item['put-code'];
|
130
|
if (item.title && item.title.title) {
|
131
|
entity.title = item['title']['title'].value;
|
132
|
}
|
133
|
entity.result.journal = item['journal-title'];
|
134
|
entity.result.source = 'orcid';
|
135
|
entity.type = 'publication';
|
136
|
if (item['publication-date'] && item['publication-date']['year']) {
|
137
|
entity.result.date = item['publication-date']['year'].value
|
138
|
}
|
139
|
entity.result.accessRights = "OPEN";
|
140
|
if (item.publisher) {
|
141
|
entity.result.publisher = item.publisher;
|
142
|
}
|
143
|
entity.result.authors = [];
|
144
|
entity.result.record = item;
|
145
|
results.push(entity);
|
146
|
}
|
147
|
return results;
|
148
|
}
|
149
|
}
|