52 lines
2.1 KiB
TypeScript
52 lines
2.1 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{EnvProperties} from '../../../utils/properties/env-properties';
|
|
|
|
@Injectable()
|
|
export class SearchDataciteService {
|
|
constructor(private http: Http ) {}
|
|
|
|
searchDataciteResults (term: string, size : number, page : number, properties:EnvProperties):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 => <any> request.json())
|
|
.do(items => console.info(items))
|
|
.do(items => console.log("Datacite Results: total results = "+items.meta.total+" keyword = "+term));
|
|
//.catch(this.handleError);
|
|
}
|
|
getDataciteResultByDOI (doi: string, properties:EnvProperties):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 => <any> request.json())
|
|
.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 || { };
|
|
}
|
|
}
|