Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
dataset.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 | 2 |
import {Http, Response} from '@angular/http'; |
3 |
import {Observable} from 'rxjs/Observable'; |
|
3 |
import {HttpClient, HttpErrorResponse} from "@angular/common/http"; |
|
4 |
import {Observable, throwError} from 'rxjs'; |
|
4 | 5 |
import {DatasetInfo} from '../../utils/entities/datasetInfo'; |
5 |
import 'rxjs/add/observable/of'; |
|
6 |
import 'rxjs/add/operator/do'; |
|
7 |
import 'rxjs/add/operator/share'; |
|
6 |
|
|
7 |
|
|
8 |
|
|
8 | 9 |
import{EnvProperties} from '../../utils/properties/env-properties'; |
9 | 10 |
|
10 | 11 |
import { ParsingFunctions } from '../landing-utils/parsingFunctions.class'; |
12 |
import {map} from "rxjs/operators"; |
|
11 | 13 |
|
12 | 14 |
@Injectable() |
13 | 15 |
export class DatasetService { |
14 | 16 |
|
15 |
constructor(private http: Http ) { |
|
17 |
constructor(private http: HttpClient ) {
|
|
16 | 18 |
this.parsingFunctions = new ParsingFunctions(); |
17 | 19 |
} |
18 | 20 |
|
... | ... | |
26 | 28 |
|
27 | 29 |
|
28 | 30 |
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) |
29 |
.map(res => <any> res.json()) |
|
30 |
.map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'],res])
|
|
31 |
.map(res => [res[1], //0 |
|
31 |
//.map(res => <any> res.json())
|
|
32 |
.pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity']['oaf:result'],res]))
|
|
33 |
.pipe(map(res => [res[1], //0
|
|
32 | 34 |
res[1]['title'], //1 |
33 | 35 |
res[1]['rels']['rel'], //2 |
34 | 36 |
res[1]['children'], //3 |
... | ... | |
45 | 47 |
res[2], //13 |
46 | 48 |
(res[1]['extraInfo']!= undefined && res[1]['extraInfo']['citations']!= undefined)? res[1]['extraInfo']['citations']['citation']:null, //14 |
47 | 49 |
res[1]['journal'] //15 |
48 |
]).map(res => this.parseDatasetInfo(res, properties)); |
|
50 |
])) |
|
51 |
.pipe(map(res => this.parseDatasetInfo(res, properties))); |
|
49 | 52 |
} |
50 | 53 |
|
51 |
private handleError (error: Response) { |
|
54 |
private handleError (error: HttpErrorResponse) {
|
|
52 | 55 |
// in a real world app, we may send the error to some remote logging infrastructure |
53 | 56 |
// instead of just logging it to the console |
54 | 57 |
console.log(error); |
55 |
return Observable.throw(error || 'Server error');
|
|
58 |
return throwError(error || 'Server error');
|
|
56 | 59 |
} |
57 | 60 |
|
58 | 61 |
parseDatasetInfo (data: any, properties: EnvProperties):any { |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729