Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
organization.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 {OrganizationInfo} from '../utils/entities/organizationInfo'; |
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'; |
10 |
import {map} from "rxjs/operators"; |
|
9 | 11 |
|
10 | 12 |
@Injectable() |
11 | 13 |
export class OrganizationService { |
12 | 14 |
|
13 |
constructor(private http: Http ) {} |
|
15 |
constructor(private http: HttpClient ) {}
|
|
14 | 16 |
|
15 | 17 |
organizationInfo: OrganizationInfo; |
16 | 18 |
|
... | ... | |
18 | 20 |
let url = properties.searchAPIURLLAst+'resources?format=json&query=( (oaftype exact organization) and (reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=* or reldatasourcecompatibilityid = native)) and ( objIdentifier ='+id+')'; |
19 | 21 |
|
20 | 22 |
return this.http.get((properties.useCache)? (properties.cacheUrl +encodeURIComponent(url)): url) |
21 |
.map(res => <any> res.json()) |
|
22 |
.map(res => res['results'][0])
|
|
23 |
//.map(res => <any> res.json())
|
|
24 |
.pipe(map(res => res['results'][0]))
|
|
23 | 25 |
//.map(res => res[0]['result']['metadata']['oaf:entity']['oaf:organization']) |
24 | 26 |
//.map(res => [res, res['rels']['rel']]) |
25 |
.map(res => this.parseOrganizationInfo(res));
|
|
27 |
.pipe(map(res => this.parseOrganizationInfo(res)));
|
|
26 | 28 |
|
27 | 29 |
|
28 | 30 |
} |
... | ... | |
31 | 33 |
let url = properties.searchAPIURLLAst+"organizations/"+id+"?format=json"; |
32 | 34 |
|
33 | 35 |
return this.http.get((properties.useCache) ? (properties.cacheUrl+encodeURIComponent(url)): url) |
34 |
.map(res => <any> res.json()) |
|
35 |
.map(res => res['result']['metadata']['oaf:entity']['oaf:organization'])
|
|
36 |
.map(res => this.parseOrganizationNameAndUrl(res));
|
|
36 |
//.map(res => <any> res.json())
|
|
37 |
.pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:organization']))
|
|
38 |
.pipe(map(res => this.parseOrganizationNameAndUrl(res)));
|
|
37 | 39 |
} |
38 | 40 |
|
39 |
private handleError (error: Response) { |
|
41 |
private handleError (error: HttpErrorResponse) {
|
|
40 | 42 |
// in a real world app, we may send the error to some remote logging infrastructure |
41 | 43 |
// instead of just logging it to the console |
42 | 44 |
console.log(error); |
43 |
return Observable.throw(error || 'Server error');
|
|
45 |
return throwError(error || 'Server error');
|
|
44 | 46 |
} |
45 | 47 |
|
46 | 48 |
parseOrganizationInfo (data: any):any { |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729