1
|
/*
|
2
|
* Created by myrto on 1/24/2018
|
3
|
*/
|
4
|
|
5
|
import { Injectable } from '@angular/core';
|
6
|
import { Http, Headers, RequestOptions } from '@angular/http';
|
7
|
import { Observable } from 'rxjs/Observable';
|
8
|
import { InterfaceInformation, JobForValidation, RuleSet, StoredJob } from '../domain/typeScriptClasses';
|
9
|
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
10
|
import any = jasmine.any;
|
11
|
|
12
|
|
13
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
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
|
};
|
20
|
|
21
|
@Injectable ()
|
22
|
export class ValidatorService {
|
23
|
|
24
|
private apiUrl = process.env.API_ENDPOINT + '/validator/';
|
25
|
|
26
|
constructor(private http: Http,
|
27
|
private httpClient: HttpClient) { }
|
28
|
|
29
|
/* returns array of sets of rules according to mode (literature, data, cris) */
|
30
|
getRuleSets(mode: string): Observable<RuleSet[]> {
|
31
|
let url = `${this.apiUrl}getRuleSets/${mode}`;
|
32
|
console.log(`knocking on: ${url}`);
|
33
|
|
34
|
return this.httpClient.get(url,headerOptions);
|
35
|
}
|
36
|
|
37
|
|
38
|
getSetsOfRepository(baseUrl: string): Observable<string[]> {
|
39
|
let url = `${this.apiUrl}getSetsOfRepository?url=${baseUrl}`;
|
40
|
console.log(`knocking on: ${url}`);
|
41
|
|
42
|
return this.httpClient.get<string[]>(url,headerOptions);
|
43
|
}
|
44
|
|
45
|
getStoredJobsNew(userEmail: string,
|
46
|
jobType:string,
|
47
|
offset: string,
|
48
|
limit: string,
|
49
|
dateFrom: string,
|
50
|
dateTo: string,
|
51
|
validationStatus: string): Observable<StoredJob[]> {
|
52
|
let url = `${this.apiUrl}getStoredJobsNew?user=${userEmail}&jobType=${encodeURI(jobType)}&offset=${offset}&limit=${limit}&dateFrom=${dateFrom}&dateTo=${dateTo}&validationStatus=${validationStatus}`;
|
53
|
console.log(`knocking on: ${url}`);
|
54
|
|
55
|
return this.httpClient.get<StoredJob[]>(url,headerOptions);
|
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?url=${baseUrl}`;
|
61
|
console.log(`knocking on: ${url}`);
|
62
|
|
63
|
return this.httpClient.get<boolean>(url,headerOptions);
|
64
|
}
|
65
|
|
66
|
getInterfaceInformation(baseUrl: string): Observable<InterfaceInformation> {
|
67
|
let url = `${this.apiUrl}getInterfaceInformation?baseUrl=${encodeURIComponent(baseUrl)}`;
|
68
|
console.log(`knocking on: ${url}`);
|
69
|
|
70
|
return this.httpClient.get<InterfaceInformation>(url,headerOptions);
|
71
|
}
|
72
|
|
73
|
reSubmitJobForValidation(id: string) {
|
74
|
let url = `${this.apiUrl}reSubmitJobForValidation/${id}`;
|
75
|
console.log(`knocking on: ${url}`);
|
76
|
|
77
|
return this.httpClient.post(url, {withCredentials: true, responseType: 'text'});
|
78
|
}
|
79
|
|
80
|
submitJobForValidation(job: JobForValidation) {
|
81
|
let url = `${this.apiUrl}submitJobForValidation`;
|
82
|
console.log(`knocking on: ${url}`);
|
83
|
let body = JSON.stringify(job);
|
84
|
|
85
|
return this.httpClient.post(url,body,{withCredentials: true, responseType: 'text'});
|
86
|
}
|
87
|
|
88
|
}
|