import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {OrganizationInfo} from '../utils/entities/organizationInfo'; import {OpenaireProperties} from '../utils/properties/openaireProperties'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/share'; import { } from '../shared/cache.service'; @Injectable() export class OrganizationService { constructor(private http: Http ) {} organizationInfo: OrganizationInfo; getOrganizationInfo (id: string):any { console.info("getOrganizationInfo in service"); //let url = OpenaireProperties. getSearchAPIURLLast()+'organizations/'+id+"?format=json"; let url = /*OpenaireProperties.getSearchAPIURLLast()+*/'https://beta.services.openaire.eu/search/v2/api/'+'resources?format=json&query=( (oaftype exact organization) and (reldatasourcecompatibilityid=driver or reldatasourcecompatibilityid=driver-openaire2.0 or reldatasourcecompatibilityid=openaire2.0 or reldatasourcecompatibilityid=openaire3.0 or reldatasourcecompatibilityid=openaire2.0_data or reldatasourcecompatibilityid=hostedBy or relprojectid=*)) and ( objIdentifier ='+id+')'; //let url = "http://beta.services.openaire.eu:8480/search/rest/v2/api/resources?format=json&query=(%20(oaftype%20exact%20organization)%20and%20(reldatasourcecompatibilityid=driver%20or%20reldatasourcecompatibilityid=driver-openaire2.0%20or%20reldatasourcecompatibilityid=openaire2.0%20or%20reldatasourcecompatibilityid=openaire3.0%20or%20reldatasourcecompatibilityid=openaire2.0_data%20or%20reldatasourcecompatibilityid=hostedBy%20or%20relprojectid=*))%20and%20(%20objIdentifier%20=dedup_wf_001%3A%3Af1e63493def7cedfa5b497cdbea26faa)"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => res['results'][0]) //.map(res => res[0]['result']['metadata']['oaf:entity']['oaf:organization']) //.map(res => [res, res['rels']['rel']]) .map(res => this.parseOrganizationInfo(res)); } /* getMetrics (id: string):any { console.info("getOrganizationMetrics in service"); //let url = OpenaireProperties. getSearchAPIURLLast() + 'publications/' +id+"?format=json"; let url = OpenaireProperties.getMetricsAPIURL()+"organizations/"+id+"/clicks"; return this.http.get((OpenaireProperties.isCacheEnabled())? (OpenaireProperties.getCacheUrl()+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => res['views']); } */ 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.log(error); return Observable.throw(error || 'Server error'); } parseOrganizationInfo (data: any):any { console.info("parseOrganizationInfo"); this.organizationInfo = new OrganizationInfo(); let organization; let relations; if(data != null) { organization = data['result']['metadata']['oaf:entity']['oaf:organization']; relations = data['result']['metadata']['oaf:entity']['oaf:organization']['rels']['rel']; } else { return null; } if(organization != null) { if(organization.hasOwnProperty("websiteurl")) { this.organizationInfo.title = {"name": organization.legalshortname, "url": organization.websiteurl}; } else { this.organizationInfo.title = {"name": organization.legalshortname, "url": ''}; } this.organizationInfo.name = organization.legalname; if(this.organizationInfo.title.name == '') { this.organizationInfo.title.name = this.organizationInfo.name; } if(organization.hasOwnProperty("country")) { this.organizationInfo.country = organization['country'].classname; } } //Comment Parsing Projects info /* if(data[1] != null) { let counter; let length = relations.length!=undefined ? relations.length : 1; for(let i=0; i(); } if(!this.organizationInfo.projects.has(relation['funding']['funder'].name)) { this.organizationInfo.projects.set(relation['funding']['funder'].name, new Array<{ "name": string, "id": string, "code": string, "acronym": string, "funder": string, "funderId": string, "fundingStream": string, "fundingLevel1": string, "fundingLevel2": string, "sc39": string, "startDate": string, "endDate": string }>()); } counter = this.organizationInfo.projects.get(relation['funding']['funder'].name).length; this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter] = { "name": "", "id": "", "code": "", "acronym": "", "funder": "", "funderId": "", "fundingStream": "", "fundingLevel1": "", "fundingLevel2": "", "sc39": "", "startDate": "", "endDate": "" }; //let url = ""; if(relation['to'].content != null && relation['to'].content != "") { this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['id'] = relation['to'].content; //url = OpenaireProperties.getsearchLinkToProject()+relation['to'].content; } this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['name'] = relation.title; //this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['url'] = url; this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['code'] = relation.code; this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['acronym'] = relation.acronym; this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['funder'] = relation['funding']['funder'].shortname; this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['funderId'] = relation['funding']['funder'].id; if(relation['funding'].hasOwnProperty("funding_level_0")) { this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['fundingStream'] = relation['funding']['funding_level_0'].name; } if(relation['funding'].hasOwnProperty("funding_level_1")) { this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['fundingLevel1'] = relation['funding']['funding_level_1'].name; } if(relation['funding'].hasOwnProperty("funding_level_2")) { this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['fundingLevel2'] = relation['funding']['funding_level_2'].name; } //this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['sc39'] = //this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['startDate'] = //this.organizationInfo.projects.get(relation['funding']['funder'].name)[counter]['endDate'] = } } } } /*else if(relation['to'].class == "isProvidedBy") { if(this.organizationInfo.dataProviders == undefined) { this.organizationInfo.dataProviders = new Array<{ "name": string, "url": string, "type": string, "websiteUrl": string , "organizations": {"name": string, "url": string}[]}>(); } counter = this.organizationInfo.dataProviders.length; this.organizationInfo.dataProviders[counter] = { "name": "", "url": "", "type": "", "websiteUrl": "", "organizations": [] } let url=""; if(relation['to'].content != null && relation['to'].content != "") { url = OpenaireProperties.getsearchLinkToDataProvider()+relation['to'].content; } this.organizationInfo.dataProviders[counter]['name'] = relation.officialname; this.organizationInfo.dataProviders[counter]['url'] = url; if(relation.hasOwnProperty("datasourcetype")) { this.organizationInfo.dataProviders[counter]['type'] = relation['datasourcetype'].classname; } this.organizationInfo.dataProviders[counter]['websiteUrl'] = relation.websiteurl; }*/ /* -----> } } } */ return this.organizationInfo; } }