2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {throwError} from 'rxjs';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {ProjectInfo} from '../../utils/entities/projectInfo';
|
2019-06-03 15:20:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
import { ParsingFunctions } from '../landing-utils/parsingFunctions.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {map} from "rxjs/operators";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ProjectService {
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient ) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.parsingFunctions = new ParsingFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
public parsingFunctions: ParsingFunctions;
|
|
|
|
projectInfo: ProjectInfo;
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
getProjectInfo (id: string, properties:EnvProperties):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = properties.searchAPIURLLAst + 'projects/'+id+"?format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
let key = url;
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project']))
|
|
|
|
.pipe(map(res => [res,
|
2017-12-19 13:53:46 +01:00
|
|
|
res['fundingtree'],
|
2019-06-03 15:20:36 +02:00
|
|
|
res['rels']['rel']]))
|
|
|
|
.pipe(map(res => this.parseProjectInfo(res, properties)));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2019-02-25 16:28:14 +01:00
|
|
|
|
2018-03-16 16:56:35 +01:00
|
|
|
getProjectInfoByGrantId (grant: string, funder:string, properties:EnvProperties):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-03-16 16:56:35 +01:00
|
|
|
let url =properties.searchAPIURLLAst+ 'resources?query=(oaftype exact project)'+
|
|
|
|
'and (projectcode_nt exact "'+grant+'" ) and (fundershortname exact '+'"'+funder+ '"'+')'+"&format=json&size=1";
|
|
|
|
|
|
|
|
|
|
|
|
let key = url;
|
|
|
|
|
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => res['results'][0]))
|
|
|
|
.pipe(map(res => [res['result']['metadata']['oaf:entity']['oaf:project'],res['result']['header']['dri:objIdentifier']]))
|
|
|
|
.pipe(map(res => [res[0],
|
2018-03-16 16:56:35 +01:00
|
|
|
res[0]['fundingtree'],
|
2019-06-03 15:20:36 +02:00
|
|
|
res[0]['rels']['rel'],res[1]]))
|
|
|
|
.pipe(map(res => this.parseProjectInfo(res, properties)));
|
2018-03-16 16:56:35 +01:00
|
|
|
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
/*
|
|
|
|
get project strtDate and endDate
|
|
|
|
*/
|
2018-02-05 14:14:59 +01:00
|
|
|
getProjectDates (id: string, properties:EnvProperties):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = properties.searchAPIURLLAst+'projects/'+id+"?format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
let key = url+'_projectDates';
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project']))
|
|
|
|
.pipe(map(res => [res,
|
2017-12-19 13:53:46 +01:00
|
|
|
res['fundingtree'],
|
2019-06-03 15:20:36 +02:00
|
|
|
res['rels']['rel']]))
|
|
|
|
.pipe(map(res => this.parseProjectDates(id,res)))
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
getHTMLInfo(id: string, properties:EnvProperties): any {
|
|
|
|
let url = properties.searchAPIURLLAst + 'projects/'+id+"?format=json";
|
2017-12-19 13:53:46 +01:00
|
|
|
let key = url;
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url)
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => <any> res.json())
|
|
|
|
.pipe(map(res => res['result']['metadata']['oaf:entity']['oaf:project']))
|
|
|
|
.pipe(map(res => this.parseHTMLInfo(res)));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
private handleError (error: HttpErrorResponse) {
|
2017-12-19 13:53:46 +01:00
|
|
|
console.log(error);
|
2019-06-03 15:20:36 +02:00
|
|
|
return throwError(error || 'Server error');
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
parseHTMLInfo (data: any):any {
|
|
|
|
let htmlInfo: {"title": string, "acronym": string, "callIdentifier": string};
|
|
|
|
|
|
|
|
if(data != null) {
|
|
|
|
htmlInfo = {"title": data.title, "acronym": data.acronym, "callIdentifier": data.callidentifier};
|
|
|
|
}
|
|
|
|
return htmlInfo;
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
parseProjectInfo (data: any, properties:EnvProperties):any {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.projectInfo = new ProjectInfo();
|
2020-03-17 16:19:25 +01:00
|
|
|
this.projectInfo.funding = {funderName: "", funderShortName: "", code: "", callIdentifier: "",
|
|
|
|
fundingStream: "", budget: "", contribution: "", currency: ""};
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
// ['result']['header']['dri:objIdentifier']
|
2018-03-16 16:56:35 +01:00
|
|
|
if(data[3] != null) {
|
2019-02-25 16:28:14 +01:00
|
|
|
this.projectInfo.id = data[3];
|
2018-03-16 16:56:35 +01:00
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
|
|
|
// ['result']['metadata']['oaf:entity']['oaf:project']['fundingtree']
|
|
|
|
if(data[1] != null) {
|
2017-12-19 13:53:46 +01:00
|
|
|
let funding: {"funderName": string, "funderShortname": string, "stream": string};
|
|
|
|
funding = this.parsingFunctions.parseFundingTrees(data[1]);
|
2020-03-16 14:09:46 +01:00
|
|
|
if(funding.funderName) {
|
|
|
|
this.projectInfo.funding.funderName = funding.funderName;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
if(funding.funderShortname) {
|
2020-03-16 14:09:46 +01:00
|
|
|
this.projectInfo.funding.funderShortName = funding.funderShortname;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
if(funding.stream) {
|
2020-03-16 14:09:46 +01:00
|
|
|
this.projectInfo.funding.fundingStream = funding.stream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ['result']['metadata']['oaf:entity']['oaf:project']
|
|
|
|
if(data[0] != null) {
|
|
|
|
this.projectInfo.acronym = data[0].acronym;
|
|
|
|
this.projectInfo.title = Array.isArray(data[0]['title']) ? data[0].title[0] : data[0].title;
|
|
|
|
this.projectInfo.funding.code = data[0].code;
|
|
|
|
if(data[0].startdate) {
|
|
|
|
let date: number = Date.parse(data[0].startdate);
|
|
|
|
this.projectInfo.startDate = (date ? date : null);
|
|
|
|
}
|
|
|
|
if(data[0].enddate) {
|
|
|
|
let date: number = Date.parse(data[0].enddate);
|
|
|
|
this.projectInfo.endDate = (date ? date : null);
|
|
|
|
}
|
|
|
|
if(this.projectInfo.endDate || this.projectInfo.startDate) {
|
|
|
|
let todayDate = Date.parse(new Date().toString());
|
|
|
|
this.projectInfo.currentDate = todayDate;
|
|
|
|
if(this.projectInfo.startDate) {
|
|
|
|
let startDate = +(this.projectInfo.startDate);
|
|
|
|
if (todayDate < startDate) {
|
|
|
|
this.projectInfo.status = "Not started";
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
|
|
|
if(this.projectInfo.endDate && !this.projectInfo.status) {
|
|
|
|
let endDate = +(this.projectInfo.endDate);
|
|
|
|
if (todayDate <= endDate) {
|
|
|
|
this.projectInfo.status = "On going";
|
|
|
|
} else {
|
|
|
|
this.projectInfo.status = "Closed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(this.projectInfo.funding) {
|
|
|
|
if(this.projectInfo.funding.funderShortName == "EC") {
|
|
|
|
this.projectInfo.openAccessMandatePublications = data[0].oamandatepublications;
|
|
|
|
this.projectInfo.specialClause39 = data[0].ecsc39;
|
|
|
|
this.projectInfo.openAccessMandateDatasets = data[0].ecarticle29_3;
|
2020-03-17 16:19:25 +01:00
|
|
|
this.projectInfo.funding.callIdentifier = data[0].callidentifier;
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
|
|
|
this.projectInfo.funding.budget = data[0].totalcost;//"10000";
|
|
|
|
this.projectInfo.funding.contribution = data[0].fundedamount;//"200100";
|
|
|
|
this.projectInfo.funding.currency = data[0].currency;//"EUR";
|
|
|
|
}
|
2022-04-28 11:13:06 +02:00
|
|
|
// if(!Array.isArray(data[0]['summary'])) {
|
|
|
|
// this.projectInfo.description = (data[0]['summary']) ? String(data[0]['summary']) : "";
|
|
|
|
// } else {
|
|
|
|
// this.projectInfo.description = (data[0]['summary'][0]) ? String(data[0]['summary'][0]) : "";
|
|
|
|
// }
|
|
|
|
this.projectInfo.description = this.parsingFunctions.parseDescription(data[0] && data[0].summary?data[0].summary:[]);
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
// ['result']['metadata']['oaf:entity']['oaf:project']['rels']['rel']
|
|
|
|
if(data[2] != null) {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.projectInfo.organizations = [];//new Map<string, string>();
|
|
|
|
|
|
|
|
if(!Array.isArray(data[2])) {
|
2021-09-27 11:19:24 +02:00
|
|
|
if(data[2].hasOwnProperty("to") && data[2]['to'].class && data[2]['to'].class.toLowerCase() == "hasparticipant") {
|
2020-06-18 13:48:46 +02:00
|
|
|
let acronym: string = "";
|
|
|
|
let name: string = "";
|
|
|
|
let id: string = "";
|
2020-06-10 13:05:59 +02:00
|
|
|
if (data[2].hasOwnProperty("legalshortname")) {
|
2017-12-19 13:53:46 +01:00
|
|
|
acronym = data[2].legalshortname;
|
|
|
|
}
|
2020-06-10 13:05:59 +02:00
|
|
|
if (data[2].hasOwnProperty("legalname")) {
|
2017-12-19 13:53:46 +01:00
|
|
|
name = data[2].legalname;
|
|
|
|
}
|
2020-06-10 13:05:59 +02:00
|
|
|
if (!acronym && !name) {
|
2017-12-19 13:53:46 +01:00
|
|
|
// acronym is displayed with link and name only in tooltip
|
|
|
|
acronym = "[no title available]";
|
|
|
|
}
|
|
|
|
|
2020-06-10 13:05:59 +02:00
|
|
|
if (data[2].hasOwnProperty("to")) {
|
|
|
|
id = data[2]['to'].content;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.projectInfo.organizations.push({"acronym": acronym, "name": name, "id": id});
|
2020-06-10 13:05:59 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
} else {
|
|
|
|
for(let i=0; i<data[2].length; i++) {
|
2020-06-18 13:48:46 +02:00
|
|
|
let acronym: string = "";
|
|
|
|
let name: string = "";
|
|
|
|
let id: string = "";
|
2021-09-27 11:19:24 +02:00
|
|
|
if(data[2][i].hasOwnProperty("to") && data[2][i]['to'].class && data[2][i]['to'].class.toLowerCase() == "hasparticipant") {
|
2017-12-19 13:53:46 +01:00
|
|
|
if(data[2][i].hasOwnProperty("legalshortname")) {
|
|
|
|
acronym = data[2][i].legalshortname;
|
|
|
|
}
|
|
|
|
if(data[2][i].hasOwnProperty("legalname")) {
|
|
|
|
name = data[2][i].legalname;
|
|
|
|
}
|
|
|
|
if(!acronym && !name){
|
|
|
|
acronym = "[no title available]";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data[2][i].hasOwnProperty("to")) {
|
|
|
|
id = data[2][i]['to'].content;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.projectInfo.organizations.push({"acronym": acronym, "name": name, "id": id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 14:09:46 +01:00
|
|
|
if(this.projectInfo.funding && this.projectInfo.funding.funderShortName == "EC") {
|
|
|
|
this.projectInfo.url = properties.cordisURL+this.projectInfo.funding.code;
|
2017-12-19 13:53:46 +01:00
|
|
|
this.projectInfo.urlInfo = "Detailed project information (CORDIS)";
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.projectInfo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
parseProjectDates (id: string, data: any):any {
|
2019-02-25 16:28:14 +01:00
|
|
|
let project = { id: id, startDate: "", endDate: ""};
|
2017-12-19 13:53:46 +01:00
|
|
|
if(data[0] != null) {
|
|
|
|
project.startDate = data[0].startdate;
|
|
|
|
project.endDate = data[0].enddate;
|
|
|
|
}
|
|
|
|
return project;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|