1
|
/*
|
2
|
* Created by myrto on 1/24/2018
|
3
|
*/
|
4
|
|
5
|
/*
|
6
|
* !!! USING TEMPORARY API ADDRESS AND USER
|
7
|
*/
|
8
|
|
9
|
import { Injectable } from '@angular/core';
|
10
|
import { Http, Headers, RequestOptions } from '@angular/http';
|
11
|
import { Observable } from 'rxjs/Observable';
|
12
|
import { InterfaceInformation, JobForValidation, RuleSet, StoredJob } from '../domain/typeScriptClasses';
|
13
|
import { apiUrl } from '../domain/tempAPI';
|
14
|
|
15
|
|
16
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
17
|
let httpOptions = new RequestOptions({ headers: headers });
|
18
|
|
19
|
@Injectable ()
|
20
|
export class ValidatorService {
|
21
|
|
22
|
private apiUrl = apiUrl + '/validator/';
|
23
|
|
24
|
constructor(private http: Http) { }
|
25
|
|
26
|
/* returns array of sets of rules according to mode (literature, data, cris) */
|
27
|
getRuleSets(mode: string): Observable<RuleSet[]> {
|
28
|
let url = `${this.apiUrl}getRuleSets/${mode}`;
|
29
|
console.log(`knocking on: ${url}`);
|
30
|
return this.http.get(url,httpOptions)
|
31
|
.map(res => <RuleSet[]>res.json())
|
32
|
.catch(this.handleError);
|
33
|
}
|
34
|
|
35
|
|
36
|
getSetsOfRepository(baseUrl: string): Observable<string[]> {
|
37
|
let url = `${this.apiUrl}getSetsOfRepository?url=${encodeURIComponent(baseUrl)}`;
|
38
|
console.log(`knocking on: ${url}`);
|
39
|
return this.http.get(url,httpOptions)
|
40
|
.map(res => <string[]>res.json())
|
41
|
.catch(this.handleError);
|
42
|
}
|
43
|
|
44
|
getStoredJobsNew(userEmail: string,
|
45
|
jobType:string,
|
46
|
offset: string,
|
47
|
limit: string,
|
48
|
dateFrom: string,
|
49
|
dateTo: string,
|
50
|
validationStatus: string): Observable<StoredJob[]> {
|
51
|
let url = `${this.apiUrl}getStoredJobsNew?user=${userEmail}&jobType=${encodeURI(jobType)}&offset=${offset}&limit=${limit}&dateFrom=${dateFrom}&dateTo=${dateTo}&validationStatus=${validationStatus}`;
|
52
|
console.log(`knocking on: ${url}`);
|
53
|
return this.http.get(url,httpOptions)
|
54
|
.map(res => <StoredJob[]>res.json())
|
55
|
.catch(this.handleError);
|
56
|
}
|
57
|
|
58
|
/* returns true if there is a repository containing the baseUrl */
|
59
|
identifyRepository(baseUrl: string): Observable<boolean> {
|
60
|
let url = `${this.apiUrl}identifyRepository?baseUrl=${encodeURIComponent(baseUrl)}`;
|
61
|
console.log(`knocking on: ${url}`);
|
62
|
return this.http.get(url,httpOptions)
|
63
|
.map(res => <boolean>res.json())
|
64
|
.catch(this.handleError);
|
65
|
}
|
66
|
|
67
|
getInterfaceInformation(baseUrl: string): Observable<InterfaceInformation> {
|
68
|
let url = `${this.apiUrl}getInterfaceInformation?baseUrl=${encodeURIComponent(baseUrl)}`;
|
69
|
console.log(`knocking on: ${url}`);
|
70
|
return this.http.get(url,httpOptions)
|
71
|
.map(res => <InterfaceInformation>res.json())
|
72
|
.catch(this.handleError);
|
73
|
}
|
74
|
|
75
|
reSubmitJobForValidation(id: string): Observable<string> {
|
76
|
let url = `${this.apiUrl}reSubmitJobForValidation/${id}`;
|
77
|
console.log(`knocking on: ${url}`);
|
78
|
|
79
|
httpOptions.withCredentials = true;
|
80
|
return this.http.post(url,httpOptions)
|
81
|
.map(res => {
|
82
|
console.log(`responded ${res.status}`);
|
83
|
return res.status.toString();
|
84
|
})
|
85
|
.catch(this.handleError);
|
86
|
}
|
87
|
|
88
|
submitJobForValidation(job: JobForValidation): Observable<string> {
|
89
|
let url = `${this.apiUrl}submitJobForValidation`;
|
90
|
console.log(`knocking on: ${url}`);
|
91
|
let body = JSON.stringify(job);
|
92
|
httpOptions.withCredentials = true;
|
93
|
return this.http.post(url,body,httpOptions)
|
94
|
.map(res => {
|
95
|
console.log(`responded ${res.status}`);
|
96
|
return res.status.toString();
|
97
|
})
|
98
|
.catch(this.handleError);
|
99
|
}
|
100
|
|
101
|
|
102
|
/* from omtd project */
|
103
|
private handleError(error: Response | any) {
|
104
|
// In a real world app, we might use a remote logging infrastructure
|
105
|
// We'd also dig deeper into the error to get a better message
|
106
|
let errMsg = "";
|
107
|
console.log('E R R O R !!!');
|
108
|
console.log(error);
|
109
|
if (error instanceof Response) {
|
110
|
const body = error.text() || '';
|
111
|
//const err = body.error || JSON.stringify(body);
|
112
|
errMsg = `${error.status} - ${error.statusText || ''} ${body}`;
|
113
|
} else {
|
114
|
errMsg = (error.message) ? error.message :
|
115
|
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
|
116
|
console.error(errMsg); // log to console instead
|
117
|
}
|
118
|
return Observable.throw(errMsg);
|
119
|
}
|
120
|
}
|