2018-11-21 10:34:39 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Http, Response} from '@angular/http';
|
|
|
|
import {Headers, RequestOptions} from '@angular/http';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient} from "@angular/common/http";
|
|
|
|
import {Observable} from 'rxjs';
|
2018-11-21 10:34:39 +01:00
|
|
|
|
|
|
|
import {ZenodoCommunityInfo} from './zenodoCommunityInfo';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {map} from "rxjs/operators";
|
2018-11-21 10:34:39 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ZenodoCommunitiesService {
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http:HttpClient) {
|
2018-11-21 10:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getZenodoCommunities(properties:EnvProperties, url: string) {
|
|
|
|
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 => [this.parseZenodoCommunities(res['hits'].hits),res['hits'].total]));
|
2018-11-21 10:34:39 +01:00
|
|
|
}
|
|
|
|
getZenodoCommunityById(properties:EnvProperties, url: string, openaireId:string) {
|
|
|
|
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 => {
|
2018-11-21 10:34:39 +01:00
|
|
|
var community = this.parseZenodoCommunity(res);
|
|
|
|
community["openaireId"]=openaireId;
|
|
|
|
return community;
|
2019-06-03 15:20:36 +02:00
|
|
|
}));
|
2018-11-21 10:34:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
parseZenodoCommunities(data: any): ZenodoCommunityInfo[] {
|
|
|
|
let zenodoCommunities: ZenodoCommunityInfo[] = [];
|
|
|
|
|
|
|
|
for (let i=0; i<data.length; i++) {
|
|
|
|
let resData = data[i];
|
|
|
|
|
|
|
|
|
|
|
|
zenodoCommunities.push(this.parseZenodoCommunity(resData));
|
|
|
|
}
|
|
|
|
return zenodoCommunities;
|
|
|
|
}
|
|
|
|
|
|
|
|
parseZenodoCommunity(resData:any):ZenodoCommunityInfo {
|
|
|
|
var result: ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
|
|
|
|
|
|
|
result['title'] = resData.title;
|
|
|
|
result['id'] = resData.id;
|
|
|
|
result['description'] = resData.description;
|
|
|
|
result['link'] = resData.links.html;
|
|
|
|
result['logoUrl'] = resData.logo_url;
|
|
|
|
result['date'] = resData.updated;
|
|
|
|
result['page'] = resData.page;
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
getTotalZenodoCommunities(properties:EnvProperties, url: string) {
|
|
|
|
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['hits'].total));
|
2018-11-21 10:34:39 +01:00
|
|
|
}
|
|
|
|
}
|