2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {URLSearchParams} from '@angular/http';
|
|
|
|
import {Http, Response} from '@angular/http';
|
|
|
|
import { Headers, RequestOptions } from '@angular/http';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
|
|
|
import {Observable} from 'rxjs';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../../utils/properties/env-properties';
|
2019-06-03 15:20:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-03 11:58:30 +02:00
|
|
|
import { ClaimResult} from '../claimEntities.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {map} from "rxjs/operators";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class SearchOrcidService {
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor( private http: HttpClient ) {}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
2018-05-02 14:26:54 +02:00
|
|
|
searchOrcidAuthor (term: string, authorIds: string[], authors, properties:EnvProperties, addId):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
//var headers = new Headers();
|
|
|
|
//headers.append('Accept', 'application/orcid+json');
|
|
|
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-05-02 14:26:54 +02:00
|
|
|
let url = properties.searchOrcidURL + term+'/record';
|
2017-12-19 13:53:46 +01:00
|
|
|
let key = url;
|
|
|
|
|
|
|
|
return this.http.get(url, { headers: headers })
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json()['person'])
|
|
|
|
.pipe(map(res => res['person']))
|
|
|
|
.pipe(map(res => [res['name']['given-names'],
|
2018-05-02 14:26:54 +02:00
|
|
|
res['name']['family-name'],
|
2019-06-03 15:20:36 +02:00
|
|
|
res['name']]))
|
|
|
|
.pipe(map(res => this.parseOrcidAuthor(res, authorIds, authors, addId)));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
searchOrcidAuthors (term: string, authorIds: string[],
|
2018-05-02 14:26:54 +02:00
|
|
|
properties:EnvProperties):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
//var headers = new Headers();
|
|
|
|
//headers.append('Accept', 'application/orcid+json');
|
|
|
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-05-02 14:26:54 +02:00
|
|
|
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';
|
2017-12-19 13:53:46 +01:00
|
|
|
let key = url;
|
|
|
|
|
|
|
|
return this.http.get(url, { headers: headers })
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json()['result'])
|
|
|
|
.pipe(map(res => res['result']))
|
|
|
|
.pipe(map(res => this.parseOrcidAuthors(res, authorIds)));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-03 11:58:30 +02:00
|
|
|
searchOrcidPublications (id: string, properties:EnvProperties, parse:boolean = false):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
//var headers = new Headers();
|
|
|
|
//headers.append('Accept', 'application/orcid+json');
|
|
|
|
let headers = new HttpHeaders({'Accept': 'application/orcid+json'});
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-05-02 14:26:54 +02:00
|
|
|
let url =properties.searchOrcidURL+id+'/works';
|
2017-12-19 13:53:46 +01:00
|
|
|
let key = url;
|
|
|
|
|
|
|
|
return this.http.get(url, { headers: headers })
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json()['group'])
|
|
|
|
.pipe(map(res => res['group']))
|
|
|
|
.pipe(map(request => (parse?this.parse(id, request):request)));
|
2017-12-19 13:53:46 +01:00
|
|
|
//.map(res => res['orcid-work']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-02 14:26:54 +02:00
|
|
|
parseOrcidAuthor (data: any, authorIds: string[],authors, addId):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
if(data[2] != null) {
|
2018-05-02 14:26:54 +02:00
|
|
|
if(addId){
|
|
|
|
authorIds.push(data[2].path);
|
|
|
|
}
|
|
|
|
var author ={};
|
|
|
|
author['id']=data[2].path;
|
2017-12-19 13:53:46 +01:00
|
|
|
if(data[0] != null) {
|
2018-05-02 14:26:54 +02:00
|
|
|
author['authorGivenName']=data[0].value;
|
|
|
|
} else {
|
|
|
|
author['authorGivenName']="";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
if(data[1] != null) {
|
2018-05-02 14:26:54 +02:00
|
|
|
author['authorFamilyName']=data[1].value;
|
2017-12-19 13:53:46 +01:00
|
|
|
} else {
|
2018-05-02 14:26:54 +02:00
|
|
|
author['authorFamilyName']="";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-05-02 14:26:54 +02:00
|
|
|
authors.push(author);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-02 14:26:54 +02:00
|
|
|
parseOrcidAuthors (data: any, authorIds: string[]):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
let ret: boolean = false;
|
|
|
|
let mydata: any;
|
|
|
|
let length: number;
|
|
|
|
|
|
|
|
if(data != null) {
|
|
|
|
length = data.length!=undefined ? data.length : 1;
|
|
|
|
|
|
|
|
for(let i=0; i<length; i++) {
|
|
|
|
mydata = data.length!=undefined ? data[i] : data;
|
|
|
|
|
2018-05-02 14:26:54 +02:00
|
|
|
if(mydata.hasOwnProperty("orcid-identifier")) {
|
|
|
|
authorIds.push(mydata['orcid-identifier'].path);
|
|
|
|
|
|
|
|
// if(mydata.hasOwnProperty("orcid-bio")) {
|
|
|
|
// if(mydata['orcid-bio'].hasOwnProperty("personal-details")) {
|
|
|
|
// if(mydata['orcid-bio']['personal-details'].hasOwnProperty("given-names")) {
|
|
|
|
// authorGivenNames.push(mydata['orcid-bio']['personal-details']['given-names'].value);
|
|
|
|
// } else {
|
|
|
|
// authorGivenNames.push("");
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if(mydata['orcid-bio']['personal-details'].hasOwnProperty("family-name")) {
|
|
|
|
// authorFamilyNames.push(mydata['orcid-bio']['personal-details']['family-name'].value);
|
|
|
|
// } else {
|
|
|
|
// authorFamilyNames.push("");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
ret = true;
|
|
|
|
}
|
2018-05-02 14:26:54 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2019-02-13 12:39:41 +01:00
|
|
|
parse(authorId, response):ClaimResult[]{
|
2018-05-03 11:58:30 +02:00
|
|
|
var results:ClaimResult[] = [];
|
|
|
|
for(var i=0; i<response.length; i++){
|
|
|
|
var item=response[i];
|
|
|
|
var result:ClaimResult = new ClaimResult();
|
|
|
|
result.DOI = null;
|
|
|
|
result.url = null;
|
|
|
|
result.publisher = null;
|
|
|
|
result.journal = null;
|
|
|
|
if(item['work-summary'] && item['work-summary'].length > 0){
|
|
|
|
item = item['work-summary'][0];
|
|
|
|
}else{
|
|
|
|
item['work-summary'];
|
|
|
|
}
|
|
|
|
if(item['external-ids'] && item['external-ids']['external-id']){
|
|
|
|
for(var j =0; j< item['external-ids']['external-id'].length; j++){
|
|
|
|
var id = item['external-ids']['external-id'][j];
|
|
|
|
if(id['external-id-type'] == "doi"){
|
|
|
|
result.DOI = id['external-id-value'];
|
|
|
|
result.url = "http://dx.doi.org/" + result.DOI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 12:39:41 +01:00
|
|
|
result.id = authorId+"-"+item['put-code'];
|
2018-05-03 11:58:30 +02:00
|
|
|
if(item.title && item.title.title){
|
|
|
|
result.title = item['title']['title'].value;
|
|
|
|
}
|
2019-02-13 12:39:41 +01:00
|
|
|
result.journal = item['journal-title'];
|
2018-05-03 11:58:30 +02:00
|
|
|
result.source = 'orcid';
|
|
|
|
result.type = 'publication';
|
|
|
|
if(item['publication-date'] && item['publication-date']['year']){
|
|
|
|
result.date = item['publication-date']['year'].value
|
|
|
|
}
|
|
|
|
|
|
|
|
result.accessRights = "OPEN";
|
|
|
|
if(item.publisher){
|
|
|
|
result.publisher = item.publisher;
|
|
|
|
}
|
|
|
|
result.result = item;
|
|
|
|
|
|
|
|
results.push(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|