Project

General

Profile

« Previous | Next » 

Revision 55964

[Library|Trunk]

Merge into trunk branch angular7 rev 55729

View differences:

publication.service.ts
1

  
2 1
import {Injectable} from '@angular/core';
3
import {Http, Response} from '@angular/http';
4
import {Observable}     from 'rxjs/Observable';
2
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
3
import {throwError} from 'rxjs';
5 4
import {PublicationInfo} from '../../utils/entities/publicationInfo';
6
import {DeletedByInferenceResult} from '../../utils/entities/deletedByInferenceResult';
7
import 'rxjs/add/observable/of';
8
import 'rxjs/add/operator/do';
9
import 'rxjs/add/operator/share';
10
import 'rxjs/add/operator/map';
11
import{EnvProperties} from '../../utils/properties/env-properties';
5
import {EnvProperties} from '../../utils/properties/env-properties';
6
import {ParsingFunctions} from '../landing-utils/parsingFunctions.class';
7
import {map} from "rxjs/operators";
12 8

  
13

  
14
import { ParsingFunctions } from '../landing-utils/parsingFunctions.class';
15

  
16 9
@Injectable()
17 10
export class PublicationService {
18 11

  
19
  constructor(private http: Http ) {
12
  constructor(private http: HttpClient ) {
20 13
    this.parsingFunctions = new ParsingFunctions();
21 14
  }
22 15

  
......
28 21
    let key = url;
29 22

  
30 23
    return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
31
                .map(res => <any> res.json())
32
                .map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res])
33
                .map(res => [ res[1]['oaf:result'], //0
24
                //.map(res => <any> res.json())
25
                .pipe(map(res => [res['result']['header']['dri:status'], res['result']['metadata']['oaf:entity'], res]))
26
                .pipe(map(res => [ res[1]['oaf:result'], //0
34 27
                              res[1]['oaf:result']['title'],  //1
35 28
                              res[1]['oaf:result']['rels']['rel'],  //2
36 29
                              res[1]['oaf:result']['children'], //3
......
46 39
                              res[1]['oaf:result']['creator'],  //13
47 40
                              res[2], //14
48 41
                              res[1]['oaf:result']['country']  //15
49
                ])
50
                .map(res => this.parsePublicationInfo(res, properties));
42
                ]))
43
                .pipe(map(res => this.parsePublicationInfo(res, properties)));
51 44
  }
52 45

  
53
  private handleError (error: Response) {
46
  private handleError (error: HttpErrorResponse) {
54 47
  // in a real world app, we may send the error to some remote logging infrastructure
55 48
  // instead of just logging it to the console
56 49
    console.log(error);
57
    return Observable.throw(error  || 'Server error');
50
    return throwError(error  || 'Server error');
58 51
  }
59 52

  
60 53
  parsePublicationInfo (data: any, properties: EnvProperties):any {
......
378 371

  
379 372
    //return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
380 373
    return this.http.get(url)
381
                .map(res => <any> res.json())
382
                .map(res => [res['total'], this.parseOpenCitations(res['results'])]);
374
                //.map(res => <any> res.json())
375
                .pipe(map(res => [res['total'], this.parseOpenCitations(res['results'])]));
383 376
  }
384 377

  
385 378
  parseOpenCitations(openCitations: any): {"url": string, "title": string, "year": string, "doi": string, "authors": string[]}[] {

Also available in: Unified diff