1
|
/*
|
2
|
* Created by myrto on 1/24/2018
|
3
|
*/
|
4
|
|
5
|
/*
|
6
|
* !!! USING TEMPORARY API ADDRESS AND USER
|
7
|
*/
|
8
|
|
9
|
import { HttpHeaders } from '@angular/common/http';
|
10
|
import { Injectable } from '@angular/core';
|
11
|
import { Http } from '@angular/http';
|
12
|
import { Observable } from 'rxjs/Observable';
|
13
|
|
14
|
const httpOptions = {
|
15
|
headers: new HttpHeaders().set('Content-Type', 'application/json')
|
16
|
};
|
17
|
|
18
|
@Injectable ()
|
19
|
export class ValidatorService {
|
20
|
|
21
|
/* private apiUrl = 'http://195.134.66.230:8380/uoa-repository-manager-service';*/
|
22
|
private apiUrl = 'http://194.177.192.121:8380/uoa-repository-manager-service';
|
23
|
|
24
|
constructor(private http: Http) { }
|
25
|
|
26
|
/* returns true if there is a repository containing the identifier */
|
27
|
identifyRepository(identifier: string): Observable<boolean> {
|
28
|
let url = `${this.apiUrl}/validator/identifyRepository/{url}?url=${identifier}`;
|
29
|
console.log(`knocking on: ${url}`);
|
30
|
return this.http.get(url)
|
31
|
.map(res => <boolean>res.json())
|
32
|
.catch(this.handleError);
|
33
|
}
|
34
|
|
35
|
/* from omtd project */
|
36
|
private handleError(error: Response | any) {
|
37
|
// In a real world app, we might use a remote logging infrastructure
|
38
|
// We'd also dig deeper into the error to get a better message
|
39
|
let errMsg = "";
|
40
|
console.log(error);
|
41
|
if (error instanceof Response) {
|
42
|
const body = error.text() || '';
|
43
|
//const err = body.error || JSON.stringify(body);
|
44
|
errMsg = `${error.status} - ${error.statusText || ''} ${body}`;
|
45
|
} else {
|
46
|
errMsg = (error.message) ? error.message :
|
47
|
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
|
48
|
console.error(errMsg); // log to console instead
|
49
|
}
|
50
|
return Observable.throw(errMsg);
|
51
|
}
|
52
|
}
|