import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import { PublicationInfo } from '../../publicationInfo'; @Injectable() export class CommunityService { constructor(private http:Http) { } getNumberOfPublications() { return this.http.get('http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/publications/count?format=json&fq=communityid=egi') .map(res => res.json()).do(res => {console.log(res)}); } // Most recent publications getPublicationsInfo(){ return this.http.get('http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/publications?fq=communityid exact "egi"&sortBy=resultdateofacceptance,descending&format=json&size=5') .map(res => res.json()).map(res => this.parse(res)).do(res => {console.log(res)}); } getDatasetsInfo(){ return this.http.get('http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/datasets?fq=communityid exact "egi"&sortBy=resultdateofacceptance,descending&format=json&size=5') .map(res => res.json()).map(res => this.parse(res)).do(res => {console.log(res)}); } getNumberOfResearchData() { return this.http.get('http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/datasets/count?format=json&fq=communityid=egi') .map(res => res.json()).do(res => {console.log(res)}); } getResearchDataInfo() { return this.http.get('http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/datasets?fq=communityid exact "egi"&sortBy=resultdateofacceptance,descending&format=json&size=5') .map(res => res.json()).map(res => res.results).do(res => {console.log(res)}); } getNumberOfSoftware() { return this.http.get('http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/software/count?format=json&fq=communityid=egi') .map(res => res.json()).do(res => {console.log(res)}); } getSoftwareInfo() { return this.http.get('http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/software?fq=communityid exact "egi"&sortBy=resultdateofacceptance,descending&format=json') .map(res => res.json()).map(res => this.parse(res)).do(res => {console.log(res)}); } parse(res){ var results =[]; for(let item of res.results){ var result= {}; result["id"] = item.result["header"]["dri:objIdentifier"]; result["title"] = item.result["metadata"]["oaf:entity"]["oaf:result"]["title"]["content"]; result["bestaccessright"] = item.result["metadata"]["oaf:entity"]["oaf:result"]["bestaccessright"]["classid"]; result["date"]=item.result["metadata"]["oaf:entity"]["oaf:result"]["dateofacceptance"]; result["description"]= item.result["metadata"]["oaf:entity"]["oaf:result"]["description"]; result["authors"] = []; if(Array.isArray(item.result["metadata"]["oaf:entity"]["oaf:result"]["creator"])){ result["authors"] = item.result["metadata"]["oaf:entity"]["oaf:result"]["creator"]; }else{ result["authors"].push(item.result["metadata"]["oaf:entity"]["oaf:result"]["creator"]); } result["authors"] = result["authors"].slice(0,10); results.push(result); } return results; } // getPublicationInfo(url: string) { // return this.http.get(url).map(res => res.json()).map(res => res.results).do(res => {console.log(res)}); // } }