Project

General

Profile

1
/*
2
* Created by myrto on 1/24/2018
3
*/
4

    
5
import { HttpClient, HttpHeaders } from '@angular/common/http';
6
import { Injectable } from '@angular/core';
7
import { environment } from '../../environments/environment';
8
import { Observable } from 'rxjs';
9
import { InterfaceInformation, JobForValidation, RuleSet, StoredJob } from '../domain/typeScriptClasses';
10

    
11
const headerOptions = {
12
  headers : new HttpHeaders().set('Content-Type', 'application/json')
13
    .set('Accept', 'application/json'),
14
  withCredentials: true
15
};
16

    
17
@Injectable ()
18
export class ValidatorService {
19

    
20
  private apiUrl = environment.API_ENDPOINT + '/validator/';
21

    
22
    constructor(private httpClient: HttpClient) { }
23

    
24
  /* returns array of sets of rules according to mode (literature, data, cris) */
25
  getRuleSets(mode: string): Observable<RuleSet[]> {
26
    const url = `${this.apiUrl}getRuleSets/${mode}`;
27
    console.log(`knocking on: ${url}`);
28

    
29
    return this.httpClient.get<RuleSet[]>(url, headerOptions);
30
  }
31

    
32

    
33
  getSetsOfRepository(baseUrl: string): Observable<string[]> {
34
    const url = `${this.apiUrl}getSetsOfRepository?url=${baseUrl}`;
35
    console.log(`knocking on: ${url}`);
36

    
37
    return this.httpClient.get<string[]>(url, headerOptions);
38
  }
39

    
40
  getStoredJobsNew(userEmail: string,
41
                   jobType: string,
42
                   offset: string,
43
                   limit: string,
44
                   dateFrom: string,
45
                   dateTo: string,
46
                   validationStatus: string): Observable<StoredJob[]> {
47
    let url = `${this.apiUrl}getStoredJobsNew?user=${userEmail}&jobType=${encodeURI(jobType)}`;
48
    url = `${url}&offset=${offset}&limit=${limit}&dateFrom=${dateFrom}&dateTo=${dateTo}&validationStatus=${validationStatus}`;
49
    console.log(`knocking on: ${url}`);
50

    
51
    return this.httpClient.get<StoredJob[]>(url, headerOptions);
52
  }
53

    
54
  /* returns true if there is a repository containing the baseUrl */
55
  identifyRepository(baseUrl: string): Observable<boolean> {
56
    const url = `${this.apiUrl}identifyRepository?url=${baseUrl}`;
57
    console.log(`knocking on: ${url}`);
58

    
59
    return this.httpClient.get<boolean>(url, headerOptions);
60
  }
61

    
62
  getInterfaceInformation(baseUrl: string): Observable<InterfaceInformation> {
63
    const url = `${this.apiUrl}getInterfaceInformation?baseUrl=${encodeURIComponent(baseUrl)}`;
64
    console.log(`knocking on: ${url}`);
65

    
66
    return this.httpClient.get<InterfaceInformation>(url, headerOptions);
67
  }
68

    
69
  reSubmitJobForValidation(id: string, userEmail: string) {
70
    const url = `${this.apiUrl}reSubmitJobForValidation/${userEmail}/${id}`;
71
    console.log(`knocking on: ${url}`);
72
    const body = {};
73

    
74
    return this.httpClient.post(url, body, {withCredentials: true, responseType: 'text'});
75
  }
76

    
77
  submitJobForValidation(job: JobForValidation): Observable<JobForValidation> {
78
    const url = `${this.apiUrl}submitJobForValidation`;
79
    console.log(`knocking on: ${url}`);
80
    const body = JSON.stringify(job);
81

    
82
    return this.httpClient.post<JobForValidation>(url, body, headerOptions);
83
  }
84

    
85
}
(11-11/11)