Revision 52768
Added by Myrto Koukouli almost 6 years ago
validator.service.ts | ||
---|---|---|
6 | 6 |
import { Http, Headers, RequestOptions } from '@angular/http'; |
7 | 7 |
import { Observable } from 'rxjs/Observable'; |
8 | 8 |
import { InterfaceInformation, JobForValidation, RuleSet, StoredJob } from '../domain/typeScriptClasses'; |
9 |
import {HttpClient, HttpHeaders} from "@angular/common/http"; |
|
10 |
import any = jasmine.any; |
|
9 | 11 |
|
10 | 12 |
|
11 | 13 |
let headers = new Headers({ 'Content-Type': 'application/json' }); |
12 | 14 |
let httpOptions = new RequestOptions({ headers: headers }); |
15 |
const headerOptions = { |
|
16 |
headers : new HttpHeaders().set('Content-Type', 'application/json') |
|
17 |
.set('Accept', 'application/json'), |
|
18 |
withCredentials: true |
|
19 |
}; |
|
13 | 20 |
|
14 | 21 |
@Injectable () |
15 | 22 |
export class ValidatorService { |
16 | 23 |
|
17 | 24 |
private apiUrl = process.env.API_ENDPOINT + '/validator/'; |
18 | 25 |
|
19 |
constructor(private http: Http) { } |
|
26 |
constructor(private http: Http, |
|
27 |
private httpClient: HttpClient) { } |
|
20 | 28 |
|
21 | 29 |
/* returns array of sets of rules according to mode (literature, data, cris) */ |
22 | 30 |
getRuleSets(mode: string): Observable<RuleSet[]> { |
23 | 31 |
let url = `${this.apiUrl}getRuleSets/${mode}`; |
24 | 32 |
console.log(`knocking on: ${url}`); |
25 |
httpOptions.withCredentials = true; |
|
26 |
return this.http.get(url,httpOptions) |
|
27 |
.map(res => <RuleSet[]>res.json()) |
|
28 |
.catch(this.handleError); |
|
33 |
|
|
34 |
return this.httpClient.get(url,headerOptions); |
|
29 | 35 |
} |
30 | 36 |
|
31 | 37 |
|
32 | 38 |
getSetsOfRepository(baseUrl: string): Observable<string[]> { |
33 | 39 |
let url = `${this.apiUrl}getSetsOfRepository?url=${baseUrl}`; |
34 | 40 |
console.log(`knocking on: ${url}`); |
35 |
httpOptions.withCredentials = true; |
|
36 |
return this.http.get(url,httpOptions) |
|
37 |
.map(res => <string[]>res.json()) |
|
38 |
.catch(this.handleError); |
|
41 |
|
|
42 |
return this.httpClient.get<string[]>(url,headerOptions); |
|
39 | 43 |
} |
40 | 44 |
|
41 | 45 |
getStoredJobsNew(userEmail: string, |
... | ... | |
47 | 51 |
validationStatus: string): Observable<StoredJob[]> { |
48 | 52 |
let url = `${this.apiUrl}getStoredJobsNew?user=${userEmail}&jobType=${encodeURI(jobType)}&offset=${offset}&limit=${limit}&dateFrom=${dateFrom}&dateTo=${dateTo}&validationStatus=${validationStatus}`; |
49 | 53 |
console.log(`knocking on: ${url}`); |
50 |
httpOptions.withCredentials = true; |
|
51 |
return this.http.get(url,httpOptions) |
|
52 |
.map(res => <StoredJob[]>res.json()) |
|
53 |
.catch(this.handleError); |
|
54 |
|
|
55 |
return this.httpClient.get<StoredJob[]>(url,headerOptions); |
|
54 | 56 |
} |
55 | 57 |
|
56 | 58 |
/* returns true if there is a repository containing the baseUrl */ |
57 | 59 |
identifyRepository(baseUrl: string): Observable<boolean> { |
58 | 60 |
let url = `${this.apiUrl}identifyRepository?url=${baseUrl}`; |
59 | 61 |
console.log(`knocking on: ${url}`); |
60 |
httpOptions.withCredentials = true; |
|
61 |
return this.http.get(url,httpOptions) |
|
62 |
.map(res => <boolean>res.json()) |
|
63 |
.catch(this.handleError); |
|
62 |
|
|
63 |
return this.httpClient.get<boolean>(url,headerOptions); |
|
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
getInterfaceInformation(baseUrl: string): Observable<InterfaceInformation> { |
67 | 67 |
let url = `${this.apiUrl}getInterfaceInformation?baseUrl=${encodeURIComponent(baseUrl)}`; |
68 | 68 |
console.log(`knocking on: ${url}`); |
69 |
httpOptions.withCredentials = true; |
|
70 |
return this.http.get(url,httpOptions) |
|
71 |
.map(res => <InterfaceInformation>res.json()) |
|
72 |
.catch(this.handleError); |
|
69 |
|
|
70 |
return this.httpClient.get<InterfaceInformation>(url,headerOptions); |
|
73 | 71 |
} |
74 | 72 |
|
75 |
reSubmitJobForValidation(id: string): Observable<string> {
|
|
73 |
reSubmitJobForValidation(id: string) { |
|
76 | 74 |
let url = `${this.apiUrl}reSubmitJobForValidation/${id}`; |
77 | 75 |
console.log(`knocking on: ${url}`); |
78 | 76 |
|
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); |
|
77 |
return this.httpClient.post(url, {withCredentials: true, responseType: 'text'}); |
|
86 | 78 |
} |
87 | 79 |
|
88 |
submitJobForValidation(job: JobForValidation): Observable<string> {
|
|
80 |
submitJobForValidation(job: JobForValidation) { |
|
89 | 81 |
let url = `${this.apiUrl}submitJobForValidation`; |
90 | 82 |
console.log(`knocking on: ${url}`); |
91 | 83 |
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); |
|
84 |
|
|
85 |
return this.httpClient.post(url,body,{withCredentials: true, responseType: 'text'}); |
|
99 | 86 |
} |
100 | 87 |
|
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 | 88 |
} |
Also available in: Unified diff
added new aggregations page and new repo types placeholders in registration page