import {throwError as observableThrowError, Observable} from 'rxjs'; import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import { HttpClient } from '@angular/common/http'; import { ClaimResult} from '../claimEntities.class'; import {map} from "rxjs/operators"; @Injectable() export class SearchCrossrefService { constructor( private http: HttpClient ) {} 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 => request.json().message) .pipe(map(request => request['message'])) .pipe(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 => request.json().message) .pipe(map(request => request['message'])) .pipe(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 request.json().message) .pipe(map(request => request['message'])) .pipe(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 observableThrowError(error || 'Server error'); } parse(response):ClaimResult[]{ var results:ClaimResult[] = []; for(var i=0; i