1 |
43769
|
argiro.kok
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {Http, Response} from '@angular/http';
|
3 |
|
|
import {Observable} from 'rxjs/Observable';
|
4 |
43785
|
argiro.kok
|
import {ProjectInfo} from '../utils/entities/projectInfo';
|
5 |
|
|
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
6 |
44638
|
argiro.kok
|
import 'rxjs/add/observable/of';
|
7 |
|
|
import 'rxjs/add/operator/do';
|
8 |
|
|
import 'rxjs/add/operator/share';
|
9 |
|
|
import { CacheService } from '../shared/cache.service';
|
10 |
43769
|
argiro.kok
|
@Injectable()
|
11 |
|
|
export class ProjectService {
|
12 |
|
|
|
13 |
44638
|
argiro.kok
|
constructor(private http: Http, public _cache: CacheService) {}
|
14 |
43769
|
argiro.kok
|
|
15 |
|
|
projectInfo: ProjectInfo;
|
16 |
|
|
|
17 |
|
|
getProjectInfo (id: string):any {
|
18 |
|
|
console.info("getProjectInfo in service");
|
19 |
|
|
|
20 |
|
|
let url = OpenaireProperties.getSearchAPIURL() + 'projects/'+id;
|
21 |
44638
|
argiro.kok
|
let key = url;
|
22 |
|
|
if (this._cache.has(key)) {
|
23 |
|
|
return Observable.of(this._cache.get(key));
|
24 |
|
|
}
|
25 |
43769
|
argiro.kok
|
return this.http.get(url)
|
26 |
|
|
.map(res => <any> res.json())
|
27 |
|
|
.map(res => res['result']['metadata']['oaf:entity']['oaf:project'])
|
28 |
|
|
.map(res => [res,
|
29 |
|
|
res['fundingtree'],
|
30 |
|
|
res['rels']['rel']])
|
31 |
44638
|
argiro.kok
|
.map(res => this.parseProjectInfo(res))
|
32 |
|
|
.do(res => {
|
33 |
|
|
this._cache.set(key, res);
|
34 |
|
|
});
|
35 |
43769
|
argiro.kok
|
|
36 |
|
|
}
|
37 |
|
|
/*
|
38 |
|
|
get project strtDate and endDate
|
39 |
|
|
*/
|
40 |
|
|
getProjectDates (id: string):any {
|
41 |
|
|
|
42 |
|
|
let url = OpenaireProperties.getSearchAPIURL()+'projects/'+id;
|
43 |
44638
|
argiro.kok
|
let key = url+'_projectDates';
|
44 |
|
|
if (this._cache.has(key)) {
|
45 |
|
|
return Observable.of(this._cache.get(key));
|
46 |
|
|
}
|
47 |
43769
|
argiro.kok
|
return this.http.get(url)
|
48 |
|
|
.map(res => <any> res.json())
|
49 |
|
|
.map(res => [res['result']['metadata']['oaf:entity']['oaf:project'],
|
50 |
|
|
res['result']['metadata']['oaf:entity']['oaf:project']['fundingtree'],
|
51 |
|
|
res['result']['metadata']['oaf:entity']['oaf:project']['rels']['rel']])
|
52 |
44638
|
argiro.kok
|
.map(res => this.parseProjectDates(id,res))
|
53 |
|
|
.do(res => {
|
54 |
|
|
this._cache.set(key, res);
|
55 |
|
|
});
|
56 |
43769
|
argiro.kok
|
|
57 |
|
|
}
|
58 |
|
|
private handleError (error: Response) {
|
59 |
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
60 |
|
|
// instead of just logging it to the console
|
61 |
|
|
console.error(error);
|
62 |
|
|
return Observable.throw(error || 'Server error');
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
parseProjectInfo (data: any):any {
|
66 |
|
|
this.projectInfo = new ProjectInfo();
|
67 |
|
|
|
68 |
|
|
if(data[0] != null) {
|
69 |
|
|
this.projectInfo.acronym = data[0].acronym;
|
70 |
|
|
this.projectInfo.title = data[0].title;
|
71 |
|
|
this.projectInfo.callIdentifier = data[0].callidentifier;
|
72 |
|
|
this.projectInfo.contractNum = data[0].code;
|
73 |
|
|
this.projectInfo.startDate = data[0].startdate;
|
74 |
|
|
this.projectInfo.endDate = data[0].enddate;
|
75 |
|
|
this.projectInfo.openAccessMandate = data[0].oamandatepublications;
|
76 |
|
|
this.projectInfo.specialClause39 = data[0].ecsc39;
|
77 |
|
|
}
|
78 |
|
|
if(data[1] != null) {
|
79 |
|
|
if(data[1]['funder'] != null) {
|
80 |
|
|
this.projectInfo.funder = data[1]['funder'].shortname;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
let funding;
|
84 |
|
|
this.projectInfo.funding = "";
|
85 |
|
|
|
86 |
|
|
if(data[1]['funding_level_2'] != null) {
|
87 |
|
|
funding = data[1]['funding_level_2'].id;
|
88 |
|
|
} else if(data[1]['funding_level_1'] != null) {
|
89 |
|
|
funding = data[1]['funding_level_1'].id;
|
90 |
|
|
} else if(data[1]['funding_level_0'] != null) {
|
91 |
|
|
funding = data[1]['funding_level_0'].id;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
if(funding != undefined) {
|
95 |
|
|
funding = funding.split("::");
|
96 |
|
|
for(let i=1; i<funding.length; i++) {
|
97 |
|
|
if(this.projectInfo.funding != "") {
|
98 |
|
|
this.projectInfo.funding += " | ";
|
99 |
|
|
}
|
100 |
|
|
this.projectInfo.funding += funding[i];
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
if(data[2] != null) {
|
106 |
|
|
this.projectInfo.organizations = new Map<string, string>();
|
107 |
|
|
|
108 |
|
|
let name = "";
|
109 |
|
|
let url = "";
|
110 |
|
|
|
111 |
|
|
if(!Array.isArray(data[2])) {
|
112 |
|
|
if(data[2].hasOwnProperty("legalshortname")) {
|
113 |
|
|
name = data[2].legalshortname;
|
114 |
|
|
} else if(data[2].hasOwnProperty("legalname")) {
|
115 |
|
|
name = data[2].legalname;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
44338
|
konstantin
|
if(data[2].hasOwnProperty("to") && name != "") {
|
119 |
43769
|
argiro.kok
|
url = OpenaireProperties.getsearchLinkToOrganization()+data[2]['to'].content;
|
120 |
|
|
}
|
121 |
44338
|
konstantin
|
if(name != "") {
|
122 |
|
|
this.projectInfo.organizations.set(name, url);
|
123 |
|
|
}
|
124 |
43769
|
argiro.kok
|
} else {
|
125 |
|
|
for(let i=0; i<data[2].length; i++) {
|
126 |
|
|
if(data[2][i].hasOwnProperty("legalshortname")) {
|
127 |
|
|
name = data[2][i].legalshortname;
|
128 |
|
|
} else if(data[2][i].hasOwnProperty("legalname")) {
|
129 |
|
|
name = data[2][i].legalname;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
44338
|
konstantin
|
if(data[2][i].hasOwnProperty("to") && name!="") {
|
133 |
43926
|
konstantin
|
url = OpenaireProperties.getsearchLinkToOrganization()+data[2][i]['to'].content;
|
134 |
43769
|
argiro.kok
|
}
|
135 |
44338
|
konstantin
|
|
136 |
|
|
if(name != "") {
|
137 |
|
|
this.projectInfo.organizations.set(name, url);
|
138 |
|
|
}
|
139 |
43769
|
argiro.kok
|
}
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
if(this.projectInfo.funder == "EC") {
|
144 |
|
|
this.projectInfo.url = OpenaireProperties.getCordisURL()+this.projectInfo.contractNum;
|
145 |
|
|
this.projectInfo.urlInfo = "Detailed project information (CORDIS)";
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
return this.projectInfo;
|
149 |
|
|
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
parseProjectDates (id: string, data: any):any {
|
153 |
|
|
var project = { id: id, startDate: "", endDate: ""};
|
154 |
|
|
if(data[0] != null) {
|
155 |
|
|
project.startDate = data[0].startdate;
|
156 |
|
|
project.endDate = data[0].enddate;
|
157 |
|
|
}
|
158 |
|
|
return project;
|
159 |
|
|
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
}
|