Project

General

Profile

1
/*
2
* Created by myrto on 12/05/2017
3
*/
4

    
5
import { HttpClient, HttpHeaders } from '@angular/common/http';
6
import { Injectable } from '@angular/core';
7
import { environment } from '../../environments/environment';
8
import {
9
  AggregationDetails,
10
  Country, MetricsInfo,
11
  Repository,
12
  RepositoryInterface,
13
  RepositorySnippet,
14
  Timezone,
15
  Typology
16
} from '../domain/typeScriptClasses';
17
import { Observable, of } from 'rxjs';
18
import { timezones } from '../domain/timezones';
19
import { typologies } from '../domain/typologies';
20

    
21
const headerOptions = {
22
  headers : new HttpHeaders().set('Content-Type', 'application/json')
23
                             .set('Accept', 'application/json'),
24
  withCredentials: true
25
};
26

    
27

    
28
@Injectable ()
29
export class RepositoryService {
30
  private apiUrl = environment.API_ENDPOINT + '/repository/';
31

    
32
  constructor(private httpClient: HttpClient) { }
33

    
34
  addInterface(datatype: string, repoId: string, registeredBy: string, newInterface: RepositoryInterface): Observable<RepositoryInterface> {
35
    const url = `${this.apiUrl}addInterface?datatype=${datatype}&repoId=${repoId}&registeredBy=${registeredBy}`;
36
    console.log(`knocking on: ${url}`);
37
    console.log(`sending ${JSON.stringify(newInterface)}`);
38
    return this.httpClient.post<RepositoryInterface>(url, newInterface, headerOptions);
39
  }
40

    
41
  updateInterface(repoId: string, registeredBy: string, interfaceInfo: RepositoryInterface): Observable<RepositoryInterface> {
42
    const url = `${this.apiUrl}updateRepositoryInterface?repoId=${repoId}&registeredBy=${registeredBy}`;
43
    console.log(`knocking on: ${url}`);
44
    console.log(`sending ${JSON.stringify(interfaceInfo)}`);
45
    return this.httpClient.post<RepositoryInterface>(url, interfaceInfo, headerOptions);
46
  }
47

    
48
  deleteInterface(id: string, registeredBy: string) {
49
    const url = `${this.apiUrl}deleteInterface/?id=${id}&registeredBy=${registeredBy}`;
50
    console.log(`knocking on: ${url}`);
51

    
52
    return this.httpClient.delete(url, {withCredentials: true, responseType: 'text'});
53
  }
54

    
55
  addRepository(datatype: string, newRepository: Repository): Observable<Repository> {
56
    const url = `${this.apiUrl}addRepository?datatype=${datatype}`;
57
    console.log(`knocking on: ${url}`);
58
    console.log(`sending ${JSON.stringify(newRepository)}`);
59
    return this.httpClient.post<Repository>(url, newRepository, headerOptions);
60
  }
61

    
62
  updateRepository(repoInfo: Repository): Observable<Repository> {
63
    const url = `${this.apiUrl}updateRepository`;
64
    console.log(`knocking on: ${url}`);
65
    console.log(`sending ${JSON.stringify(repoInfo)}`);
66
    return this.httpClient.post<Repository>(url, repoInfo, headerOptions);
67
  }
68

    
69
  getRepositoriesOfCountry(country: string, mode: string): Observable<RepositorySnippet[]> {
70
    const url = `${this.apiUrl}getRepositoriesByCountry/${country}/${mode}`;
71
    console.log(`knocking on: ${url}`);
72
    return this.httpClient.get<RepositorySnippet[]>(url, headerOptions);
73
  }
74

    
75
  getRepositoriesOfUser(userEmail: string): Observable<Repository[]> {
76
    const url = `${this.apiUrl}getRepositoriesOfUser/${userEmail}/0/100`;
77
    console.log(`knocking on: ${url}`);
78
    return this.httpClient.get<Repository[]>(url, headerOptions);
79
  }
80

    
81

    
82
  getRepositoryById(id: string): Observable<Repository> {
83
    const url = `${this.apiUrl}getRepositoryById/${id}`;
84
    console.log(`knocking on: ${url}`);
85
    return this.httpClient.get<Repository>(url, headerOptions);
86
  }
87

    
88
  getRepositoryInterface(id: string): Observable<RepositoryInterface[]> {
89
    const url = `${this.apiUrl}getRepositoryInterface/${id}`;
90
    console.log(`knocking on: ${url}`);
91
    return this.httpClient.get<RepositoryInterface[]>(url, headerOptions);
92
  }
93

    
94

    
95
  getUrlsOfUserRepos(userEmail: string): Observable<string[]> {
96
    const url = `${this.apiUrl}getUrlsOfUserRepos/${userEmail}/0/100/`;
97
    console.log(`knocking on: ${url}`);
98
    return this.httpClient.get<string[]>(url, headerOptions);
99
  }
100

    
101
  getRepositoryAggregations(id: string): Observable<AggregationDetails[]> {
102
    const url = `${this.apiUrl}getRepositoryAggregations/${id}`;
103
    console.log(`knocking on: ${url}`);
104
    return this.httpClient.get<AggregationDetails[]>(url, headerOptions);
105
  }
106

    
107
  getRepositoryAggregationsByYear(id: string): Observable<Map<string, AggregationDetails[]>> {
108
    const url = `${this.apiUrl}getRepositoryAggregationsByYear/${id}`;
109
    console.log(`knocking on: ${url}`);
110
    return this.httpClient.get<Map<string, AggregationDetails[]>>(url, headerOptions);
111
  }
112

    
113
  getTimezones(): Observable<Timezone[]> {
114
/*    const url = `${this.apiUrl}getTimezones`;
115
    console.log(`knocking on: ${url}`);
116
    return this.httpClient.get<Timezone[]>(url, headerOptions);*/
117
    return of(<Timezone[]>timezones);
118
  }
119

    
120
  getTypologies(): Observable<Typology[]> {
121
/*    const url = `${this.apiUrl}getTypologies`;
122
    console.log(`knocking on: ${url}`);
123
    return this.httpClient.get<Typology[]>(url, headerOptions);*/
124
    return of(<Typology[]>typologies);
125
  }
126

    
127
  getCountries(): Observable<Country[]> {
128
    const url = `${this.apiUrl}getCountries`;
129
    console.log(`knocking on: ${url}`);
130
    return this.httpClient.get<Country[]>(url, headerOptions);
131
  }
132

    
133

    
134
  getCompatibilityClasses (mode: string): Observable<Map<string, string>> {
135
    const url = `${this.apiUrl}getCompatibilityClasses/${mode}`;
136
    console.log(`knocking on: ${url}`);
137
    return this.httpClient.get<Map<string, string>>(url, headerOptions);
138
  }
139

    
140
  getDatasourceClasses(mode: string): Observable<Map<string, string>> {
141
    const url = `${this.apiUrl}getDatasourceClasses/${mode}`;
142
    console.log(`knocking on: ${url}`);
143
    return this.httpClient.get<Map<string, string>>(url, headerOptions);
144
  }
145

    
146

    
147
  getMetricsInfoForRepository (repoId: string): Observable<MetricsInfo> {
148
    const url = `${this.apiUrl}getMetricsInfoForRepository/${repoId}`;
149
    console.log(`knocking on: ${url}`);
150
    return this.httpClient.get<MetricsInfo>(url, headerOptions);
151
  }
152

    
153
  getListLatestUpdate(mode: string): Observable<any> {
154
    const url = `${this.apiUrl}getListLatestUpdate/${mode}`;
155
    console.log(`knocking on: ${url}`);
156
    return this.httpClient.get<any>(url, headerOptions);
157
  }
158

    
159
}
(8-8/11)