1 |
50169
|
argiro.kok
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {Http, Response} from '@angular/http';
|
3 |
55964
|
argiro.kok
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
4 |
|
|
import {Observable, throwError} from 'rxjs';
|
5 |
50169
|
argiro.kok
|
import {ProjectInfo} from '../../utils/entities/projectInfo';
|
6 |
55964
|
argiro.kok
|
|
7 |
|
|
|
8 |
|
|
|
9 |
50586
|
argiro.kok
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
10 |
50169
|
argiro.kok
|
|
11 |
|
|
import { ParsingFunctions } from '../landing-utils/parsingFunctions.class';
|
12 |
55964
|
argiro.kok
|
import {map} from "rxjs/operators";
|
13 |
50169
|
argiro.kok
|
|
14 |
|
|
@Injectable()
|
15 |
|
|
export class ProjectService {
|
16 |
|
|
|
17 |
55964
|
argiro.kok
|
constructor(private http: HttpClient ) {
|
18 |
50169
|
argiro.kok
|
this.parsingFunctions = new ParsingFunctions();
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
public parsingFunctions: ParsingFunctions;
|
22 |
|
|
projectInfo: ProjectInfo;
|
23 |
|
|
|
24 |
50586
|
argiro.kok
|
getProjectInfo (id: string, properties:EnvProperties):any {
|
25 |
50169
|
argiro.kok
|
|
26 |
50586
|
argiro.kok
|
let url = properties.searchAPIURLLAst + 'projects/'+id+"?format=json";
|
27 |
50169
|
argiro.kok
|
let key = url;
|
28 |
|
|
|
29 |
50586
|
argiro.kok
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
30 |
55964
|
argiro.kok
|
//.map(res => <any> res.json())
|
31 |
|
|
.pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project']))
|
32 |
|
|
.pipe(map(res => [res,
|
33 |
50169
|
argiro.kok
|
res['fundingtree'],
|
34 |
55964
|
argiro.kok
|
res['rels']['rel']]))
|
35 |
|
|
.pipe(map(res => this.parseProjectInfo(res, properties)));
|
36 |
50169
|
argiro.kok
|
|
37 |
|
|
}
|
38 |
54903
|
k.triantaf
|
|
39 |
51318
|
argiro.kok
|
getProjectInfoByGrantId (grant: string, funder:string, properties:EnvProperties):any {
|
40 |
50169
|
argiro.kok
|
|
41 |
51318
|
argiro.kok
|
let url =properties.searchAPIURLLAst+ 'resources?query=(oaftype exact project)'+
|
42 |
|
|
'and (projectcode_nt exact "'+grant+'" ) and (fundershortname exact '+'"'+funder+ '"'+')'+"&format=json&size=1";
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
let key = url;
|
46 |
|
|
|
47 |
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
48 |
55964
|
argiro.kok
|
//.map(res => <any> res.json())
|
49 |
|
|
.pipe(map(res => res['results'][0]))
|
50 |
|
|
.pipe(map(res => [res['result']['metadata']['oaf:entity']['oaf:project'],res['result']['header']['dri:objIdentifier']]))
|
51 |
|
|
.pipe(map(res => [res[0],
|
52 |
51318
|
argiro.kok
|
res[0]['fundingtree'],
|
53 |
55964
|
argiro.kok
|
res[0]['rels']['rel'],res[1]]))
|
54 |
|
|
.pipe(map(res => this.parseProjectInfo(res, properties)));
|
55 |
51318
|
argiro.kok
|
|
56 |
|
|
}
|
57 |
50169
|
argiro.kok
|
/*
|
58 |
|
|
get project strtDate and endDate
|
59 |
|
|
*/
|
60 |
50586
|
argiro.kok
|
getProjectDates (id: string, properties:EnvProperties):any {
|
61 |
50169
|
argiro.kok
|
|
62 |
50586
|
argiro.kok
|
let url = properties.searchAPIURLLAst+'projects/'+id+"?format=json";
|
63 |
50169
|
argiro.kok
|
let key = url+'_projectDates';
|
64 |
|
|
|
65 |
50586
|
argiro.kok
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
66 |
55964
|
argiro.kok
|
//.map(res => <any> res.json())
|
67 |
|
|
.pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project']))
|
68 |
|
|
.pipe(map(res => [res,
|
69 |
50169
|
argiro.kok
|
res['fundingtree'],
|
70 |
55964
|
argiro.kok
|
res['rels']['rel']]))
|
71 |
|
|
.pipe(map(res => this.parseProjectDates(id,res)))
|
72 |
50169
|
argiro.kok
|
|
73 |
|
|
}
|
74 |
|
|
|
75 |
50586
|
argiro.kok
|
getHTMLInfo(id: string, properties:EnvProperties): any {
|
76 |
|
|
let url = properties.searchAPIURLLAst + 'projects/'+id+"?format=json";
|
77 |
50169
|
argiro.kok
|
let key = url;
|
78 |
|
|
|
79 |
50586
|
argiro.kok
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
80 |
55964
|
argiro.kok
|
//.map(res => <any> res.json())
|
81 |
|
|
.pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project']))
|
82 |
|
|
.pipe(map(res => this.parseHTMLInfo(res)));
|
83 |
50169
|
argiro.kok
|
}
|
84 |
|
|
|
85 |
55964
|
argiro.kok
|
private handleError (error: HttpErrorResponse) {
|
86 |
50169
|
argiro.kok
|
console.log(error);
|
87 |
55964
|
argiro.kok
|
return throwError(error || 'Server error');
|
88 |
50169
|
argiro.kok
|
}
|
89 |
|
|
|
90 |
|
|
parseHTMLInfo (data: any):any {
|
91 |
|
|
let htmlInfo: {"title": string, "acronym": string, "callIdentifier": string};
|
92 |
|
|
|
93 |
|
|
if(data != null) {
|
94 |
|
|
htmlInfo = {"title": data.title, "acronym": data.acronym, "callIdentifier": data.callidentifier};
|
95 |
|
|
}
|
96 |
|
|
return htmlInfo;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
50586
|
argiro.kok
|
parseProjectInfo (data: any, properties:EnvProperties):any {
|
100 |
50169
|
argiro.kok
|
this.projectInfo = new ProjectInfo();
|
101 |
58202
|
konstantin
|
this.projectInfo.funding = {funderName: "", funderShortName: "", code: "", fundingStream: "",
|
102 |
|
|
budget: "", contribution: "", currency: ""};
|
103 |
58161
|
konstantin
|
|
104 |
|
|
// ['result']['header']['dri:objIdentifier']
|
105 |
51318
|
argiro.kok
|
if(data[3] != null) {
|
106 |
54903
|
k.triantaf
|
this.projectInfo.id = data[3];
|
107 |
51318
|
argiro.kok
|
}
|
108 |
58161
|
konstantin
|
|
109 |
|
|
// ['result']['metadata']['oaf:entity']['oaf:project']['fundingtree']
|
110 |
|
|
if(data[1] != null) {
|
111 |
50169
|
argiro.kok
|
let funding: {"funderName": string, "funderShortname": string, "stream": string};
|
112 |
|
|
funding = this.parsingFunctions.parseFundingTrees(data[1]);
|
113 |
58161
|
konstantin
|
if(funding.funderName) {
|
114 |
|
|
this.projectInfo.funding.funderName = funding.funderName;
|
115 |
|
|
}
|
116 |
50169
|
argiro.kok
|
if(funding.funderShortname) {
|
117 |
58161
|
konstantin
|
this.projectInfo.funding.funderShortName = funding.funderShortname;
|
118 |
50169
|
argiro.kok
|
}
|
119 |
|
|
if(funding.stream) {
|
120 |
58161
|
konstantin
|
this.projectInfo.funding.fundingStream = funding.stream;
|
121 |
50169
|
argiro.kok
|
}
|
122 |
58172
|
konstantin
|
}
|
123 |
|
|
|
124 |
|
|
// ['result']['metadata']['oaf:entity']['oaf:project']
|
125 |
|
|
if(data[0] != null) {
|
126 |
|
|
this.projectInfo.acronym = data[0].acronym;
|
127 |
|
|
this.projectInfo.title = Array.isArray(data[0]['title']) ? data[0].title[0] : data[0].title;
|
128 |
|
|
this.projectInfo.funding.code = data[0].code;
|
129 |
|
|
if(data[0].startdate) {
|
130 |
|
|
let date: number = Date.parse(data[0].startdate);
|
131 |
|
|
this.projectInfo.startDate = (date ? date : null);
|
132 |
50169
|
argiro.kok
|
}
|
133 |
58172
|
konstantin
|
if(data[0].enddate) {
|
134 |
|
|
let date: number = Date.parse(data[0].enddate);
|
135 |
|
|
this.projectInfo.endDate = (date ? date : null);
|
136 |
|
|
}
|
137 |
|
|
if(this.projectInfo.endDate || this.projectInfo.startDate) {
|
138 |
|
|
let todayDate = Date.parse(new Date().toString());
|
139 |
|
|
this.projectInfo.currentDate = todayDate;
|
140 |
|
|
if(this.projectInfo.startDate) {
|
141 |
|
|
let startDate = +(this.projectInfo.startDate);
|
142 |
|
|
if (todayDate < startDate) {
|
143 |
|
|
this.projectInfo.status = "Not started";
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
if(this.projectInfo.endDate && !this.projectInfo.status) {
|
147 |
|
|
let endDate = +(this.projectInfo.endDate);
|
148 |
|
|
if (todayDate <= endDate) {
|
149 |
|
|
this.projectInfo.status = "On going";
|
150 |
|
|
} else {
|
151 |
|
|
this.projectInfo.status = "Closed";
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
58202
|
konstantin
|
if(this.projectInfo.funding) {
|
156 |
|
|
if(this.projectInfo.funding.funderShortName == "EC") {
|
157 |
|
|
this.projectInfo.openAccessMandatePublications = data[0].oamandatepublications;
|
158 |
|
|
this.projectInfo.specialClause39 = data[0].ecsc39;
|
159 |
|
|
this.projectInfo.openAccessMandateDatasets = data[0].ecarticle29_3;
|
160 |
|
|
}
|
161 |
|
|
this.projectInfo.funding.budget = data[0].totalcost;//"10000";
|
162 |
|
|
this.projectInfo.funding.contribution = data[0].fundedamount;//"200100";
|
163 |
|
|
this.projectInfo.funding.currency = data[0].currency;//"EUR";
|
164 |
58172
|
konstantin
|
}
|
165 |
58202
|
konstantin
|
if(!Array.isArray(data[0]['summary'])) {
|
166 |
|
|
this.projectInfo.description = String(data[0]['summary']);
|
167 |
|
|
} else {
|
168 |
|
|
this.projectInfo.description = String(data[0]['summary'][0]);
|
169 |
|
|
}
|
170 |
58172
|
konstantin
|
}
|
171 |
50169
|
argiro.kok
|
|
172 |
58161
|
konstantin
|
// ['result']['metadata']['oaf:entity']['oaf:project']['rels']['rel']
|
173 |
|
|
if(data[2] != null) {
|
174 |
50169
|
argiro.kok
|
this.projectInfo.organizations = [];//new Map<string, string>();
|
175 |
|
|
|
176 |
|
|
let acronym: string = "";
|
177 |
|
|
let name: string = "";
|
178 |
|
|
let id: string = "";
|
179 |
|
|
|
180 |
|
|
if(!Array.isArray(data[2])) {
|
181 |
|
|
if(data[2].hasOwnProperty("legalshortname")) {
|
182 |
|
|
acronym = data[2].legalshortname;
|
183 |
|
|
}
|
184 |
|
|
if(data[2].hasOwnProperty("legalname")) {
|
185 |
|
|
name = data[2].legalname;
|
186 |
|
|
}
|
187 |
|
|
if(!acronym && !name){
|
188 |
|
|
// acronym is displayed with link and name only in tooltip
|
189 |
|
|
acronym = "[no title available]";
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
if(data[2].hasOwnProperty("to")) {
|
193 |
|
|
id = data[2]['to'].content;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
this.projectInfo.organizations.push({"acronym": acronym, "name": name, "id": id});
|
197 |
|
|
} else {
|
198 |
|
|
for(let i=0; i<data[2].length; i++) {
|
199 |
|
|
if(data[2][i].hasOwnProperty("to") && data[2][i]['to'].class == "hasParticipant") {
|
200 |
|
|
if(data[2][i].hasOwnProperty("legalshortname")) {
|
201 |
|
|
acronym = data[2][i].legalshortname;
|
202 |
|
|
}
|
203 |
|
|
if(data[2][i].hasOwnProperty("legalname")) {
|
204 |
|
|
name = data[2][i].legalname;
|
205 |
|
|
}
|
206 |
|
|
if(!acronym && !name){
|
207 |
|
|
acronym = "[no title available]";
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
if(data[2][i].hasOwnProperty("to")) {
|
211 |
|
|
id = data[2][i]['to'].content;
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
this.projectInfo.organizations.push({"acronym": acronym, "name": name, "id": id});
|
215 |
|
|
}
|
216 |
|
|
}
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
|
220 |
58161
|
konstantin
|
if(this.projectInfo.funding && this.projectInfo.funding.funderShortName == "EC") {
|
221 |
|
|
this.projectInfo.url = properties.cordisURL+this.projectInfo.funding.code;
|
222 |
50169
|
argiro.kok
|
this.projectInfo.urlInfo = "Detailed project information (CORDIS)";
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
return this.projectInfo;
|
226 |
|
|
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
parseProjectDates (id: string, data: any):any {
|
230 |
54903
|
k.triantaf
|
let project = { id: id, startDate: "", endDate: ""};
|
231 |
50169
|
argiro.kok
|
if(data[0] != null) {
|
232 |
|
|
project.startDate = data[0].startdate;
|
233 |
|
|
project.endDate = data[0].enddate;
|
234 |
|
|
}
|
235 |
|
|
return project;
|
236 |
|
|
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
}
|