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