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(): Observable<StoredJob[]> {
41
    const url = `${this.apiUrl}`;
42
    console.log(`knocking on: ${url}`);
43

    
44
    return this.httpClient.get<StoredJob[]>(url, headerOptions);
45
  }
46

    
47
  /* returns true if there is a repository containing the baseUrl */
48
  identifyRepository(baseUrl: string): Observable<boolean> {
49
    const url = `${this.apiUrl}identifyRepository?url=${baseUrl}`;
50
    console.log(`knocking on: ${url}`);
51

    
52
    return this.httpClient.get<boolean>(url, headerOptions);
53
  }
54

    
55
  getInterfaceInformation(baseUrl: string): Observable<InterfaceInformation> {
56
    const url = `${this.apiUrl}getInterfaceInformation?baseUrl=${encodeURIComponent(baseUrl)}`;
57
    console.log(`knocking on: ${url}`);
58

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

    
62
  reSubmitJobForValidation(id: string) {
63
    const url = `${this.apiUrl}reSubmitJobForValidation/${id}`;
64
    console.log(`knocking on: ${url}`);
65
    const body = {};
66

    
67
    return this.httpClient.post(url, body, {withCredentials: true, responseType: 'text'});
68
  }
69

    
70
  submitJobForValidation(job: JobForValidation): Observable<JobForValidation> {
71
    const url = `${this.apiUrl}submitJobForValidation`;
72
    console.log(`knocking on: ${url}`);
73
    const body = JSON.stringify(job);
74

    
75
    return this.httpClient.post<JobForValidation>(url, body, headerOptions);
76
  }
77

    
78
  getValidationSummary(repoId: string): Observable<StoredJob[]> {
79
    const url = `${this.apiUrl}validationSummary/${repoId}/?size=5`;
80
    console.log(`knocking on: ${url}`);
81

    
82
    return this.httpClient.get<StoredJob[]>(url, headerOptions);
83
  }
84
}
(13-13/13)