1
|
import {Injectable} from '@angular/core';
|
2
|
import {Http, Response} from '@angular/http';
|
3
|
import {Headers, RequestOptions} from '@angular/http';
|
4
|
import {HttpClient} from "@angular/common/http";
|
5
|
import {Observable} from 'rxjs';
|
6
|
|
7
|
import {ZenodoCommunityInfo} from './zenodoCommunityInfo';
|
8
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
9
|
import {map} from "rxjs/operators";
|
10
|
|
11
|
@Injectable()
|
12
|
export class ZenodoCommunitiesService {
|
13
|
|
14
|
constructor(private http:HttpClient) {
|
15
|
}
|
16
|
|
17
|
getZenodoCommunities(properties:EnvProperties, url: string) {
|
18
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
19
|
//.map(res => <any> res.json())
|
20
|
.pipe(map(res => [this.parseZenodoCommunities(res['hits'].hits),res['hits'].total]));
|
21
|
}
|
22
|
getZenodoCommunityById(properties:EnvProperties, url: string, openaireId:string) {
|
23
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
24
|
//.map(res => <any> res.json())
|
25
|
.pipe(map(res => {
|
26
|
var community = this.parseZenodoCommunity(res);
|
27
|
community["openaireId"]=openaireId;
|
28
|
return community;
|
29
|
}));
|
30
|
}
|
31
|
|
32
|
parseZenodoCommunities(data: any): ZenodoCommunityInfo[] {
|
33
|
let zenodoCommunities: ZenodoCommunityInfo[] = [];
|
34
|
|
35
|
for (let i=0; i<data.length; i++) {
|
36
|
let resData = data[i];
|
37
|
|
38
|
|
39
|
zenodoCommunities.push(this.parseZenodoCommunity(resData));
|
40
|
}
|
41
|
return zenodoCommunities;
|
42
|
}
|
43
|
|
44
|
parseZenodoCommunity(resData:any):ZenodoCommunityInfo {
|
45
|
var result: ZenodoCommunityInfo = new ZenodoCommunityInfo();
|
46
|
|
47
|
result['title'] = resData.title;
|
48
|
result['id'] = resData.id;
|
49
|
result['description'] = resData.description;
|
50
|
result['link'] = resData.links.html;
|
51
|
result['logoUrl'] = resData.logo_url;
|
52
|
result['date'] = resData.updated;
|
53
|
result['page'] = resData.page;
|
54
|
return result;
|
55
|
|
56
|
}
|
57
|
|
58
|
getTotalZenodoCommunities(properties:EnvProperties, url: string) {
|
59
|
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
60
|
//.map(res => <any> res.json())
|
61
|
.pipe(map(res => res['hits'].total));
|
62
|
}
|
63
|
}
|