Project

General

Profile

« Previous | Next » 

Revision 44907

in services use function console.log instead of console.error | re-enable cache for project & organization service | in services add result in cache before custom parsing

View differences:

project.service.ts
19 19

  
20 20
        let url = OpenaireProperties. getSearchAPIURLLast() + 'projects/'+id+"?format=json";
21 21
        let key = url;
22
        // if (this._cache.has(key)) {
23
        //   return Observable.of(this._cache.get(key));
24
        // }
22
        if (this._cache.has(key)) {
23
          return Observable.of(this._cache.get(key))
24
                  .map(res => this.parseProjectInfo(res));
25
        }
25 26
        return this.http.get(url)
26 27
                    .map(res => <any> res.json())
27 28
                    .map(res => res['result']['metadata']['oaf:entity']['oaf:project'])
28 29
                    .map(res => [res,
29 30
                                 res['fundingtree'],
30 31
                                 res['rels']['rel']])
31
                    .map(res => this.parseProjectInfo(res))
32 32
                    .do(res => {
33
                      this._cache.set(key, res);
34
                    });
33
                       this._cache.set(key, res);
34
                    })
35
                    .map(res => this.parseProjectInfo(res));
35 36

  
36 37
    }
37 38

  
......
59 60
        let url = OpenaireProperties. getSearchAPIURLLast()+'projects/'+id+"?format=json";
60 61
        let key = url+'_projectDates';
61 62
        if (this._cache.has(key)) {
62
          return Observable.of(this._cache.get(key));
63
          return Observable.of(this._cache.get(key)).map(res => this.parseProjectDates(id,res))
63 64
        }
64 65
        return this.http.get(url)
65 66
                    .map(res => <any> res.json())
66 67
                    .map(res => [res['result']['metadata']['oaf:entity']['oaf:project'],
67 68
                                 res['result']['metadata']['oaf:entity']['oaf:project']['fundingtree'],
68 69
                                 res['result']['metadata']['oaf:entity']['oaf:project']['rels']['rel']])
70
                                 .do(res => {
71
                                   this._cache.set(key, res);
72
                                 })
69 73
                    .map(res => this.parseProjectDates(id,res))
70
                    .do(res => {
71
                      this._cache.set(key, res);
72
                    });
73 74

  
74 75
    }
75 76
    private handleError (error: Response) {
76 77
    // in a real world app, we may send the error to some remote logging infrastructure
77 78
    // instead of just logging it to the console
78
        console.error(error);
79
        console.log(error);
79 80
        return Observable.throw(error  || 'Server error');
80 81
    }
81 82

  

Also available in: Unified diff