1
|
/*
|
2
|
* Created by myrto on 12/05/2017
|
3
|
*/
|
4
|
|
5
|
|
6
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
7
|
import { Injectable } from '@angular/core';
|
8
|
import { environment } from '../../environments/environment';
|
9
|
import { AdvQueryObject, BrowseEntry, EventsPage, OpenaireSubscription, SimpleSubscriptionDesc,
|
10
|
Subscription, Term } from '../domain/typeScriptClasses';
|
11
|
import { Observable } from 'rxjs';
|
12
|
|
13
|
const headerOptions = {
|
14
|
headers : new HttpHeaders().set('Content-Type', 'application/json')
|
15
|
.set('Accept', 'application/json'),
|
16
|
withCredentials: true
|
17
|
};
|
18
|
|
19
|
@Injectable ()
|
20
|
export class BrokerService {
|
21
|
private apiUrl = environment.API_ENDPOINT + '/broker/';
|
22
|
|
23
|
constructor(private httpClient: HttpClient) { }
|
24
|
|
25
|
advancedShowEvents(page: number, size: number, searchParams: AdvQueryObject): Observable<EventsPage>{
|
26
|
const url = `${this.apiUrl}advancedShowEvents/${page}/${size}`;
|
27
|
console.log(`knocking on: ${url}`);
|
28
|
const body = searchParams;
|
29
|
console.log(`sending ${JSON.stringify(body)}`);
|
30
|
|
31
|
return this.httpClient.post<EventsPage>(url, body, headerOptions);
|
32
|
}
|
33
|
|
34
|
getDatasourcesOfUser() {
|
35
|
const url = `${this.apiUrl}getDatasourcesOfUser?includeShared=false&includeByOthers=false`;
|
36
|
console.log(`knocking on: ${url}`);
|
37
|
|
38
|
return this.httpClient.get(url, headerOptions);
|
39
|
}
|
40
|
|
41
|
getDnetTopics(): Observable<Map<string, Term>> {
|
42
|
const url = `${this.apiUrl}getDnetTopics`;
|
43
|
console.log(`knocking on: ${url}`);
|
44
|
|
45
|
return this.httpClient.get<Map< string, Term>>(url, headerOptions);
|
46
|
}
|
47
|
|
48
|
getNotificationsBySubscriptionId(subId: string, page: number, size: number): Observable<EventsPage> {
|
49
|
const url = `${this.apiUrl}getNotificationsBySubscriptionId/${subId}/${page}/${size}`;
|
50
|
console.log(`knocking on: ${url}`);
|
51
|
|
52
|
return this.httpClient.get<EventsPage>(url, headerOptions);
|
53
|
}
|
54
|
|
55
|
getSimpleSubscriptionsOfUser(): Observable<Map<string, SimpleSubscriptionDesc[]>> {
|
56
|
const url = `${this.apiUrl}getSimpleSubscriptionsOfUser/`;
|
57
|
console.log(`knocking on: ${url}`);
|
58
|
|
59
|
return this.httpClient.get<Map<string, SimpleSubscriptionDesc[]>>(url, headerOptions);
|
60
|
}
|
61
|
|
62
|
getSubscription(subId: string): Observable<Subscription> {
|
63
|
const url = `${this.apiUrl}getSubscription/${subId}`;
|
64
|
console.log(`knocking on: ${url}`);
|
65
|
|
66
|
return this.httpClient.get<Subscription>(url, headerOptions);
|
67
|
}
|
68
|
|
69
|
getSubscriptionsOfUser(userEmail: string): Observable<Map<string, Subscription>> {
|
70
|
const url = `${this.apiUrl}getSubscriptionsOfUser/${userEmail}/`;
|
71
|
console.log(`knocking on: ${url}`);
|
72
|
|
73
|
return this.httpClient.get<Map<string, Subscription>>(url, headerOptions);
|
74
|
}
|
75
|
|
76
|
getTopicsForDataSource(name: string): Observable<BrowseEntry[]> {
|
77
|
const url = `${this.apiUrl}getTopicsForDatasource/${encodeURIComponent(name)}`;
|
78
|
console.log(`knocking on: ${url}`);
|
79
|
|
80
|
return this.httpClient.get<BrowseEntry[]>(url, headerOptions);
|
81
|
}
|
82
|
|
83
|
/*CHECK IF sub is sent as body*/
|
84
|
subscribeToEvent(sub: OpenaireSubscription): Observable<Subscription>{
|
85
|
const url = `${this.apiUrl}subscribe`;
|
86
|
console.log(`knocking on: ${url}`);
|
87
|
|
88
|
return this.httpClient.post<Subscription>(url, sub, headerOptions);
|
89
|
}
|
90
|
|
91
|
unsubscribe(subscriptionId: string) {
|
92
|
const url = `${this.apiUrl}unsubscribe/${subscriptionId}`;
|
93
|
console.log(`knocking on: ${url}`);
|
94
|
const body = {};
|
95
|
|
96
|
return this.httpClient.post(url, body, {withCredentials: true, responseType: 'text'});
|
97
|
}
|
98
|
|
99
|
}
|