1 |
50086
|
myrto.kouk
|
/*
|
2 |
|
|
* Created by myrto on 12/05/2017
|
3 |
|
|
*/
|
4 |
50069
|
myrto.kouk
|
|
5 |
50086
|
myrto.kouk
|
/*
|
6 |
|
|
* !!! USING TEMPORARY API ADDRESS AND USER
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
import { Injectable } from '@angular/core';
|
10 |
|
|
import { Observable } from 'rxjs/Observable';
|
11 |
50094
|
myrto.kouk
|
import 'rxjs/add/operator/map';
|
12 |
50534
|
myrto.kouk
|
import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
13 |
50086
|
myrto.kouk
|
|
14 |
50706
|
myrto.kouk
|
import { Country, MetricsInfo, Repository, RepositoryInterface, Timezone } from '../domain/typeScriptClasses';
|
15 |
|
|
import { apiUrl } from '../domain/tempAPI';
|
16 |
|
|
|
17 |
50534
|
myrto.kouk
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
18 |
|
|
let httpOptions = new RequestOptions({ headers: headers });
|
19 |
50069
|
myrto.kouk
|
|
20 |
|
|
@Injectable ()
|
21 |
|
|
export class RepositoryService {
|
22 |
50706
|
myrto.kouk
|
private apiUrl = apiUrl;
|
23 |
50069
|
myrto.kouk
|
|
24 |
50110
|
myrto.kouk
|
constructor(private http: Http) { }
|
25 |
50069
|
myrto.kouk
|
|
26 |
50239
|
myrto.kouk
|
getRepositoriesOfCountry(country: string, mode: string): Observable<Repository[]> {
|
27 |
50139
|
myrto.kouk
|
let url = `${this.apiUrl}/repository/getRepositoriesByCountry/${country}/${mode}`;
|
28 |
|
|
console.log(`knocking on: ${url}`);
|
29 |
|
|
return this.http.get(url)
|
30 |
|
|
.map( res => <Repository[]>res.json())
|
31 |
|
|
.catch(this.handleError);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
50239
|
myrto.kouk
|
getRepositoriesOfUser(userEmail: string): Observable<Repository[]> {
|
35 |
|
|
let url = `${this.apiUrl}/repository/getRepositoriesOfUser/${userEmail}/0/100`;
|
36 |
50094
|
myrto.kouk
|
console.log(`knocking on: ${url}`);
|
37 |
|
|
return this.http.get(url)
|
38 |
|
|
.map( res => <Repository[]>res.json())
|
39 |
50186
|
myrto.kouk
|
.do(res => console.log(`counted ${res.length} repositories`))
|
40 |
50094
|
myrto.kouk
|
.catch(this.handleError);
|
41 |
50069
|
myrto.kouk
|
}
|
42 |
50086
|
myrto.kouk
|
|
43 |
50337
|
myrto.kouk
|
|
44 |
|
|
getRepositoryById(id: string): Observable<Repository> {
|
45 |
|
|
let url = `${this.apiUrl}/repository/getRepositoryById/${id}`;
|
46 |
|
|
console.log(`knocking on: ${url}`);
|
47 |
|
|
return this.http.get(url)
|
48 |
|
|
.map( res => <Repository>res.json())
|
49 |
|
|
.do(res => console.log(`got repository with name: ${res.officialName}`))
|
50 |
|
|
.catch(this.handleError);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
50303
|
myrto.kouk
|
getRepositoryInterface(id: string): Observable<RepositoryInterface[]>{
|
54 |
|
|
let url = `${this.apiUrl}/repository/getRepositoryInterface/${id}`;
|
55 |
|
|
console.log(`knocking on: ${url}`);
|
56 |
|
|
return this.http.get(url)
|
57 |
|
|
.map( res => <RepositoryInterface[]>res.json())
|
58 |
|
|
.catch(this.handleError);
|
59 |
|
|
}
|
60 |
|
|
|
61 |
50376
|
myrto.kouk
|
getUrlsOfUserRepos(userEmail: string): Observable<string[]>{
|
62 |
|
|
let url = `${this.apiUrl}/repository/getUrlsOfUserRepos/${userEmail}/0/100/`;
|
63 |
|
|
console.log(`knocking on: ${url}`);
|
64 |
|
|
return this.http.get(url)
|
65 |
|
|
.map( res => <string[]>res.json())
|
66 |
|
|
.catch(this.handleError);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
getTimezones(): Observable<Timezone[]>{
|
70 |
|
|
let url = `${this.apiUrl}/repository/getTimezones`;
|
71 |
|
|
console.log(`knocking on: ${url}`);
|
72 |
|
|
return this.http.get(url)
|
73 |
|
|
.map( res => <Timezone[]>res.json())
|
74 |
|
|
.catch(this.handleError);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
50239
|
myrto.kouk
|
getCountries(): Observable<Country[]> {
|
78 |
50216
|
myrto.kouk
|
let url = `${this.apiUrl}/repository/getCountries`;
|
79 |
|
|
console.log(`knocking on: ${url}`);
|
80 |
|
|
return this.http.get(url)
|
81 |
|
|
.map( res => <Country[]>res.json())
|
82 |
|
|
.catch(this.handleError);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
50534
|
myrto.kouk
|
|
86 |
|
|
getCompatibilityClasses (mode: string): Observable<Map<string,string>> {
|
87 |
|
|
let url = `${this.apiUrl}/repository/getCompatibilityClasses/${mode}`;
|
88 |
|
|
console.log(`knocking on: ${url}`);
|
89 |
|
|
return this.http.get(url)
|
90 |
|
|
.map( res => <Map<string,string>>res.json())
|
91 |
|
|
.catch(this.handleError);
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
getDatasourceClasses(mode: string): Observable<Map<string,string>>{
|
95 |
|
|
let url = `${this.apiUrl}/repository/getDatasourceClasses/${mode}`;
|
96 |
|
|
console.log(`knocking on: ${url}`);
|
97 |
|
|
return this.http.get(url)
|
98 |
|
|
.map( res => <Map<string,string>>res.json())
|
99 |
|
|
.catch(this.handleError);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
|
103 |
50632
|
myrto.kouk
|
getMetricsInfoForRepository (repoId: string): Observable<MetricsInfo> {
|
104 |
|
|
let url = `${this.apiUrl}/repository/getMetricsInfoForRepository/${repoId}`;
|
105 |
|
|
console.log(`knocking on: ${url}`);
|
106 |
|
|
return this.http.get(url)
|
107 |
|
|
.map( res => <MetricsInfo>res.json())
|
108 |
|
|
.catch(this.handleError);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
50706
|
myrto.kouk
|
updateEnglishName(id: string, englishname: string): Observable<string>{
|
112 |
50592
|
myrto.kouk
|
let url = `${this.apiUrl}/repository/updateEnglishName?id=${id}&officialName=DSpace&englishname=${englishname}`;
|
113 |
50534
|
myrto.kouk
|
console.log(`knocking on: ${url}`);
|
114 |
50600
|
myrto.kouk
|
httpOptions.withCredentials = true;
|
115 |
50592
|
myrto.kouk
|
return this.http.post(url,httpOptions)
|
116 |
|
|
.map( res => {
|
117 |
|
|
console.log(`responded ${res.statusText}`);
|
118 |
50600
|
myrto.kouk
|
return res.status.toString();
|
119 |
50592
|
myrto.kouk
|
})
|
120 |
50534
|
myrto.kouk
|
.catch(this.handleError).share();
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
updateLongtitude(id: string, longtitude: string): Observable<string>{
|
124 |
|
|
let url = `${this.apiUrl}/repository/updateLongtitude`;
|
125 |
|
|
console.log(`knocking on: ${url}`);
|
126 |
|
|
let body = JSON.stringify({
|
127 |
|
|
id : id,
|
128 |
|
|
logntitude: longtitude
|
129 |
|
|
});
|
130 |
|
|
console.log(`sending ${body}`);
|
131 |
|
|
httpOptions.withCredentials = true;
|
132 |
|
|
|
133 |
|
|
return this.http.post(url,body,httpOptions)
|
134 |
|
|
.map( res => <string>res.json())
|
135 |
|
|
.catch(this.handleError).share();
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
updateLatitude(id: string, latitude: string): Observable<string>{
|
139 |
|
|
let url = `${this.apiUrl}/repository/updateLatitude`;
|
140 |
|
|
console.log(`knocking on: ${url}`);
|
141 |
|
|
let body = JSON.stringify({
|
142 |
|
|
id : id,
|
143 |
|
|
latitude: latitude
|
144 |
|
|
});
|
145 |
|
|
console.log(`sending ${body}`);
|
146 |
|
|
httpOptions.withCredentials = true;
|
147 |
|
|
|
148 |
|
|
return this.http.post(url,body,httpOptions)
|
149 |
|
|
.map( res => <string>res.json())
|
150 |
|
|
.catch(this.handleError).share();
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
updateLogoUrl(id: string, logoUrl: string): Observable<string>{
|
154 |
|
|
let url = `${this.apiUrl}/repository/updateLogoUrl`;
|
155 |
|
|
console.log(`knocking on: ${url}`);
|
156 |
|
|
let body = JSON.stringify({
|
157 |
|
|
id : id,
|
158 |
|
|
logoUrl: logoUrl
|
159 |
|
|
});
|
160 |
|
|
console.log(`sending ${body}`);
|
161 |
|
|
httpOptions.withCredentials = true;
|
162 |
|
|
|
163 |
|
|
return this.http.post(url, body, httpOptions)
|
164 |
|
|
.map( res => <string>res.json())
|
165 |
|
|
.catch(this.handleError).share();
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
updateTimezone(id: string, timezone: string): Observable<string>{
|
169 |
|
|
let url = `${this.apiUrl}/repository/updateTimezone`;
|
170 |
|
|
console.log(`knocking on: ${url}`);
|
171 |
|
|
let body = JSON.stringify({
|
172 |
|
|
id : id,
|
173 |
|
|
timezone: timezone
|
174 |
|
|
});
|
175 |
|
|
console.log(`sending ${body}`);
|
176 |
|
|
httpOptions.withCredentials = true;
|
177 |
|
|
|
178 |
|
|
return this.http.post(url, body, httpOptions)
|
179 |
|
|
.map( res => <string>res.json())
|
180 |
|
|
.catch(this.handleError).share();
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
|
184 |
50094
|
myrto.kouk
|
private handleError(error: Response | any) {
|
185 |
|
|
// In a real world app, we might use a remote logging infrastructure
|
186 |
|
|
// We'd also dig deeper into the error to get a better message
|
187 |
|
|
let errMsg = "";
|
188 |
50592
|
myrto.kouk
|
console.log('E R R O R !!');
|
189 |
50094
|
myrto.kouk
|
console.log(error);
|
190 |
|
|
if (error instanceof Response) {
|
191 |
|
|
const body = error.text() || '';
|
192 |
|
|
//const err = body.error || JSON.stringify(body);
|
193 |
|
|
errMsg = `${error.status} - ${error.statusText || ''} ${body}`;
|
194 |
50534
|
myrto.kouk
|
console.log(errMsg);
|
195 |
50094
|
myrto.kouk
|
} else {
|
196 |
|
|
errMsg = (error.message) ? error.message :
|
197 |
|
|
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
|
198 |
|
|
console.error(errMsg); // log to console instead
|
199 |
|
|
}
|
200 |
|
|
return Observable.throw(errMsg);
|
201 |
50086
|
myrto.kouk
|
}
|
202 |
50534
|
myrto.kouk
|
|
203 |
50069
|
myrto.kouk
|
}
|