explore-services/portal/src/app/services/project.service.ts

121 lines
4.6 KiB
TypeScript

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {ProjectInfo} from '../entities/projectInfo';
@Injectable()
export class ProjectService {
constructor(private http: Http) {}
projectInfo: ProjectInfo;
getProjectInfo (id: string):any {
console.info("getProjectInfo in service");
//let url = 'http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2.0/api/projects/'+id;
//let url = 'http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2.0/api/projects/'+id;
let url = 'http://astero.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2.0/api/projects/'+id;
return this.http.get(url)
.map(res => <any> res.json())
.map(res => res['result']['metadata']['oaf:entity']['oaf:project'])
.do(res => console.info(res))
.map(res => [res,
res['fundingtree'],
res['rels']['rel']])
.map(res => this.parseProjectInfo(res));
}
private handleError (error: Response) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Observable.throw(error || 'Server error');
}
parseProjectInfo (data: any):any {
this.projectInfo = new ProjectInfo();
if(data[0] != null) {
this.projectInfo.acronym = data[0].acronym;
this.projectInfo.title = data[0].title;
this.projectInfo.callIdentifier = data[0].callidentifier;
this.projectInfo.contractNum = data[0].code;
this.projectInfo.startDate = data[0].startdate;
this.projectInfo.endDate = data[0].enddate;
this.projectInfo.openAccessMandate = data[0].oamandatepublications;
this.projectInfo.specialClause39 = data[0].ecsc39;
}
if(data[1] != null) {
if(data[1]['funder'] != null) {
this.projectInfo.funder = data[1]['funder'].shortname;
}
let funding;
this.projectInfo.funding = "";
if(data[1]['funding_level_2'] != null) {
funding = data[1]['funding_level_2'].id;
} else if(data[1]['funding_level_1'] != null) {
funding = data[1]['funding_level_1'].id;
} else if(data[1]['funding_level_0'] != null) {
funding = data[1]['funding_level_0'].id;
}
if(funding != undefined) {
funding = funding.split("::");
for(let i=1; i<funding.length; i++) {
if(this.projectInfo.funding != "") {
this.projectInfo.funding += " | ";
}
this.projectInfo.funding += funding[i];
}
}
}
if(data[2] != null) {
this.projectInfo.organizations = new Map<string, string>();
let name = "";
let url = "";
if(!Array.isArray(data[2])) {
if(data[2].hasOwnProperty("legalshortname")) {
name = data[2].legalshortname;
} else if(data[2].hasOwnProperty("legalname")) {
name = data[2].legalname;
}
if(data[2].hasOwnProperty("to")) {
url = "https://beta.openaire.eu/search/organization?organizationId="+data[2]['to'].content;
}
this.projectInfo.organizations.set(name, url);
} else {
for(let i=0; i<data[2].length; i++) {
if(data[2][i].hasOwnProperty("legalshortname")) {
name = data[2][i].legalshortname;
} else if(data[2][i].hasOwnProperty("legalname")) {
name = data[2][i].legalname;
}
if(data[2][i].hasOwnProperty("to")) {
url = "https://beta.openaire.eu/search/organization?organizationId="+data[2][i]['to'].content;
}
this.projectInfo.organizations.set(name, url);
}
}
}
if(this.projectInfo.funder == "EC") {
this.projectInfo.url = "http://cordis.europa.eu/projects/"+this.projectInfo.contractNum;
this.projectInfo.urlInfo = "Detailed project information (CORDIS)";
}
return this.projectInfo;
}
}