99 lines
3.2 KiB
TypeScript
99 lines
3.2 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {Http, Response} from '@angular/http';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import 'rxjs/add/observable/of';
|
|
import 'rxjs/add/operator/do';
|
|
import 'rxjs/add/operator/share';
|
|
import { ClaimResult} from '../claimEntities.class';
|
|
@Injectable()
|
|
export class SearchCrossrefService {
|
|
constructor( private http: Http ) {}
|
|
|
|
|
|
searchCrossrefResults (term: string, size : number, page : number, apiUrl:string, parse:boolean = false):any {
|
|
let url = apiUrl+'?query='+term+'&rows='+size+'&offset='+(size*(page-1));
|
|
let key = url;
|
|
|
|
return this.http.get(url)
|
|
.map(request => <any> request.json().message)
|
|
.map(request => (parse?this.parse(request.items):request))
|
|
//.catch(this.handleError);
|
|
|
|
}
|
|
searchCrossrefByDOIs(DOIs: string[], apiUrl:string, parse:boolean = false):any {
|
|
|
|
var doisParams = "";
|
|
for(var i =0 ;i < DOIs.length; i++){
|
|
doisParams+=(doisParams.length > 0?",":"")+'doi:'+DOIs[i];
|
|
}
|
|
let url = apiUrl+'?filter='+doisParams;
|
|
let key = url;
|
|
|
|
|
|
return this.http.get(url)
|
|
.map(request => <any> request.json().message)
|
|
.map(request => (parse?this.parse(request.items):request))
|
|
//.catch(this.handleError);
|
|
|
|
}
|
|
searchCrossrefByMultipleDOIs(dois: string[], apiUrl:string, parse:boolean = false):any {
|
|
let url = apiUrl+'?filter=doi:';
|
|
for(var i=0; i<dois.length; i++){
|
|
url=url+(url.length==0?'':',')+'doi:'+dois[i];
|
|
}
|
|
url = apiUrl+'?filter='+url;
|
|
let key = url;
|
|
|
|
|
|
return this.http.get(url)
|
|
.map(request => <any> request.json().message)
|
|
.map(request => (parse?this.parse(request.items):request))
|
|
//.catch(this.handleError);
|
|
|
|
}
|
|
|
|
private handleError (error: Response) {
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
|
// instead of just logging it to the console
|
|
console.log(error);
|
|
return Observable.throw(error || 'Server error');
|
|
}
|
|
parse(response):ClaimResult[]{
|
|
var results:ClaimResult[] = [];
|
|
for(var i=0; i<response.length; i++){
|
|
var item=response[i];
|
|
var result:ClaimResult = new ClaimResult();
|
|
result.publisher = null;
|
|
result.journal = null;
|
|
result.DOI = item.DOI;
|
|
result.id = item.DOI;
|
|
result.title = item.title;
|
|
result.url = item.URL;
|
|
result.source = 'crossref';
|
|
result.type = 'publication';
|
|
if(item['published-print']){
|
|
result.date = item['published-print']['date-parts'][0];
|
|
}
|
|
result.accessRights = "OPEN";
|
|
result.publisher = item.publisher;
|
|
result.journal = null;
|
|
result.result = item;
|
|
if(item.author){
|
|
for(var j=0; j<item.author.length; j++){
|
|
result.authors.push(item.author[j].family+", "+item.author[j].given);
|
|
}
|
|
}
|
|
if(item.editor){
|
|
for(var j=0; j<item.editor.length; j++){
|
|
result.editors.push(item.editor[j].family+", "+item.editor[j].given);
|
|
}
|
|
}
|
|
results.push(result);
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
}
|