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{EnvProperties} from '../../../utils/properties/env-properties'; import { ClaimResult} from '../claimEntities.class'; @Injectable() export class SearchDataciteService { constructor(private http: Http ) {} searchDataciteResults (term: string, size : number, page : number, properties:EnvProperties, parse:boolean = false):any { console.info("In search datacite results "+term+ " "+properties.searchDataciteAPIURL); let url = properties.searchDataciteAPIURL+'?query='+term+'&rows='+size+'&start='+(size*(page-1)); let key = url; return this.http.get( ( properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(request => request.json()) .map(request => (parse?this.parse(request.data):request)) .do(items => console.info(items)) //.catch(this.handleError); } getDataciteResultByDOI (doi: string, properties:EnvProperties, parse:boolean = false):any { console.info("Fetch datacite resultt by DOI: "+doi); let url = properties.searchDataciteAPIURL+'/'+doi; let key = url; return this.http.get( (properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(request => request.json()) .map(request => (parse?this.parse(request.data):request)) .do(items => console.info(items)); // .do(items => console.log("Datacite Results: total results = "+items.meta.total+" doi = "+doi)) //.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'); } private extractData(res: Response) { if (res.status < 200 || res.status >= 300) { throw new Error('Bad response status: ' + res.status); } let body = res.json(); return body.data || { }; } parse(response):ClaimResult[]{ var results:ClaimResult[] = []; for(var i=0; i