Project

General

Profile

1 54479 myrto.kouk
/*
2
* Created by myrto on 12/05/2017
3
*/
4
5 56635 antonis.le
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
6 54479 myrto.kouk
import { Injectable } from '@angular/core';
7
import { environment } from '../../environments/environment';
8
import {
9
  AggregationDetails,
10
  Country, MetricsInfo,
11
  Repository,
12
  RepositoryInterface,
13 62080 stefania.m
  RepositorySnippet, RepositorySummaryInfo, TermsOfUse,
14 54479 myrto.kouk
  Timezone,
15 61394 stefania.m
  Typology, User
16 54479 myrto.kouk
} from '../domain/typeScriptClasses';
17
import { Observable, of } from 'rxjs';
18
import { timezones } from '../domain/timezones';
19
import { typologies } from '../domain/typologies';
20 56635 antonis.le
import {URLParameter} from '../domain/url-parameter';
21 54479 myrto.kouk
22
const headerOptions = {
23
  headers : new HttpHeaders().set('Content-Type', 'application/json')
24
                             .set('Accept', 'application/json'),
25
  withCredentials: true
26
};
27
28
29
@Injectable ()
30
export class RepositoryService {
31 61394 stefania.m
  private apiUrl = environment.API_ENDPOINT + '/repositories/';
32 56635 antonis.le
  private dashboardAPIUrl = environment.API_ENDPOINT + '/dashboard/';
33 54479 myrto.kouk
34
  constructor(private httpClient: HttpClient) { }
35
36 62552 j.balasis9
  addInterface(datatype: string, repoId: string, registeredBy: string, comment: string, newInterface: RepositoryInterface, desiredCompatibilityLevel?: string): Observable<RepositoryInterface> {
37 60937 andreas.ma
    let url;
38 62434 andreas.ma
    comment = newInterface.comments; // temp fix for emailing comment
39 60937 andreas.ma
    if (comment == null || comment === '') {
40 62552 j.balasis9
      url = `${this.apiUrl}addInterface?datatype=${datatype}&repoId=${repoId}&registeredBy=${registeredBy}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`;
41 60937 andreas.ma
    } else {
42 62552 j.balasis9
      url = `${this.apiUrl}addInterface?datatype=${datatype}&repoId=${repoId}&registeredBy=${registeredBy}&comment=${comment}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`;
43 60937 andreas.ma
    }
44 54479 myrto.kouk
    console.log(`knocking on: ${url}`);
45
    console.log(`sending ${JSON.stringify(newInterface)}`);
46
    return this.httpClient.post<RepositoryInterface>(url, newInterface, headerOptions);
47
  }
48
49 62550 j.balasis9
  updateInterface(repoId: string, registeredBy: string, comment: string, interfaceInfo: RepositoryInterface, desiredCompatibilityLevel?: string): Observable<RepositoryInterface> {
50 60937 andreas.ma
    let url;
51 62434 andreas.ma
    comment = interfaceInfo.comments; // temp fix for emailing comment
52 60937 andreas.ma
    if (comment == null || comment === '') {
53 62551 j.balasis9
      url = `${this.apiUrl}updateRepositoryInterface?repoId=${repoId}&registeredBy=${registeredBy}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`;
54 60937 andreas.ma
    } else {
55 62552 j.balasis9
      url  = `${this.apiUrl}updateRepositoryInterface?repoId=${repoId}&registeredBy=${registeredBy}&comment=${comment}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`;
56 60937 andreas.ma
    }
57 54479 myrto.kouk
    console.log(`knocking on: ${url}`);
58
    console.log(`sending ${JSON.stringify(interfaceInfo)}`);
59
    return this.httpClient.post<RepositoryInterface>(url, interfaceInfo, headerOptions);
60
  }
61
62
  deleteInterface(id: string, registeredBy: string) {
63
    const url = `${this.apiUrl}deleteInterface/?id=${id}&registeredBy=${registeredBy}`;
64
    console.log(`knocking on: ${url}`);
65
66
    return this.httpClient.delete(url, {withCredentials: true, responseType: 'text'});
67
  }
68
69 62551 j.balasis9
  getInterfaceDesiredCompatibilityLevel(repoId: string, interfaceId: string) {
70
    return this.httpClient.get(environment.API_ENDPOINT + `/compliance/${repoId}/${interfaceId}`);
71
  }
72
73 54479 myrto.kouk
  addRepository(datatype: string, newRepository: Repository): Observable<Repository> {
74
    const url = `${this.apiUrl}addRepository?datatype=${datatype}`;
75
    console.log(`knocking on: ${url}`);
76
    console.log(`sending ${JSON.stringify(newRepository)}`);
77
    return this.httpClient.post<Repository>(url, newRepository, headerOptions);
78
  }
79
80 58098 stefania.m
  // updateRepository(repoInfo: Repository): Observable<Repository> {
81
  //   const url = `${this.apiUrl}updateRepository`;
82
  //   console.log(`knocking on: ${url}`);
83
  //   console.log(`sending ${JSON.stringify(repoInfo)}`);
84
  //   return this.httpClient.post<Repository>(url, repoInfo, headerOptions);
85
  // }
86
87 54479 myrto.kouk
  updateRepository(repoInfo: Repository): Observable<Repository> {
88
    const url = `${this.apiUrl}updateRepository`;
89
    console.log(`knocking on: ${url}`);
90
    console.log(`sending ${JSON.stringify(repoInfo)}`);
91
    return this.httpClient.post<Repository>(url, repoInfo, headerOptions);
92
  }
93
94 62080 stefania.m
  updateRepositoriesTerms(termsList: any): Observable<TermsOfUse> {
95
    const url = `${this.apiUrl}terms`;
96
    console.log(`knocking on: ${url}`);
97
    console.log(`sending ${JSON.stringify(termsList)}`);
98
    return this.httpClient.post<TermsOfUse>(url, termsList, headerOptions);
99
  }
100
101 54479 myrto.kouk
  getRepositoriesOfCountry(country: string, mode: string): Observable<RepositorySnippet[]> {
102
    const url = `${this.apiUrl}getRepositoriesByCountry/${country}/${mode}`;
103
    console.log(`knocking on: ${url}`);
104
    return this.httpClient.get<RepositorySnippet[]>(url, headerOptions);
105
  }
106
107 61394 stefania.m
  getRepositoriesSnippetsOfUser(): Observable<RepositorySnippet[]> {
108
    const url = `${this.apiUrl}snippets/user`;
109 54479 myrto.kouk
    console.log(`knocking on: ${url}`);
110 57990 andreas.ma
    return this.httpClient.get<RepositorySnippet[]>(url, headerOptions);
111 54479 myrto.kouk
  }
112
113
  getRepositoryById(id: string): Observable<Repository> {
114 61394 stefania.m
    const   url = `${this.apiUrl}getRepositoryById/${id}`;
115 54479 myrto.kouk
    console.log(`knocking on: ${url}`);
116
    return this.httpClient.get<Repository>(url, headerOptions);
117
  }
118
119
  getRepositoryInterface(id: string): Observable<RepositoryInterface[]> {
120
    const url = `${this.apiUrl}getRepositoryInterface/${id}`;
121
    console.log(`knocking on: ${url}`);
122
    return this.httpClient.get<RepositoryInterface[]>(url, headerOptions);
123
  }
124
125 57990 andreas.ma
  getUrlsOfUserRepos(): Observable<string[]> {
126
    const url = `${this.apiUrl}getUrlsOfUserRepos/0/100/`;
127 54479 myrto.kouk
    console.log(`knocking on: ${url}`);
128
    return this.httpClient.get<string[]>(url, headerOptions);
129
  }
130
131
  getRepositoryAggregations(id: string): Observable<AggregationDetails[]> {
132
    const url = `${this.apiUrl}getRepositoryAggregations/${id}`;
133
    console.log(`knocking on: ${url}`);
134
    return this.httpClient.get<AggregationDetails[]>(url, headerOptions);
135
  }
136
137
  getRepositoryAggregationsByYear(id: string): Observable<Map<string, AggregationDetails[]>> {
138
    const url = `${this.apiUrl}getRepositoryAggregationsByYear/${id}`;
139
    console.log(`knocking on: ${url}`);
140
    return this.httpClient.get<Map<string, AggregationDetails[]>>(url, headerOptions);
141
  }
142
143
  getTimezones(): Observable<Timezone[]> {
144
/*    const url = `${this.apiUrl}getTimezones`;
145
    console.log(`knocking on: ${url}`);
146
    return this.httpClient.get<Timezone[]>(url, headerOptions);*/
147
    return of(<Timezone[]>timezones);
148
  }
149
150
  getTypologies(): Observable<Typology[]> {
151
/*    const url = `${this.apiUrl}getTypologies`;
152
    console.log(`knocking on: ${url}`);
153
    return this.httpClient.get<Typology[]>(url, headerOptions);*/
154
    return of(<Typology[]>typologies);
155
  }
156
157
  getCountries(): Observable<Country[]> {
158 61394 stefania.m
    const url = `${this.apiUrl}countries`;
159 54479 myrto.kouk
    console.log(`knocking on: ${url}`);
160
    return this.httpClient.get<Country[]>(url, headerOptions);
161
  }
162
163
164
  getCompatibilityClasses (mode: string): Observable<Map<string, string>> {
165
    const url = `${this.apiUrl}getCompatibilityClasses/${mode}`;
166
    console.log(`knocking on: ${url}`);
167
    return this.httpClient.get<Map<string, string>>(url, headerOptions);
168
  }
169
170 62389 andreas.ma
  getDatasourceClasses(mode: string): Observable<Object> {
171 54479 myrto.kouk
    const url = `${this.apiUrl}getDatasourceClasses/${mode}`;
172
    console.log(`knocking on: ${url}`);
173
    return this.httpClient.get<Map<string, string>>(url, headerOptions);
174
  }
175
176
177
  getMetricsInfoForRepository (repoId: string): Observable<MetricsInfo> {
178
    const url = `${this.apiUrl}getMetricsInfoForRepository/${repoId}`;
179
    console.log(`knocking on: ${url}`);
180
    return this.httpClient.get<MetricsInfo>(url, headerOptions);
181
  }
182
183
  getListLatestUpdate(mode: string): Observable<any> {
184
    const url = `${this.apiUrl}getListLatestUpdate/${mode}`;
185
    console.log(`knocking on: ${url}`);
186
    return this.httpClient.get<any>(url, headerOptions);
187
  }
188
189 56635 antonis.le
  searchRegisteredRepositories(page, size, urlParams: URLParameter[]) {
190
    const url = `${this.apiUrl}searchRegisteredRepositories/${page}/${size}`;
191
    console.log(`knocking on: ${url}`);
192
    let params = new HttpParams();
193
    for (const urlParameter of urlParams) {
194
      for (const value of urlParameter.value) {
195
        params = params.append(urlParameter.key, value);
196
      }
197
    }
198
199
    return this.httpClient.get<RepositorySnippet[]>(url, {params, withCredentials: true});
200
  }
201
202 57990 andreas.ma
  getRepositoriesSummaryInfo(): Observable<RepositorySummaryInfo[]> {
203
    const url = `${this.dashboardAPIUrl}getRepositoriesSummary/0/100`;
204 56635 antonis.le
    console.log(`knocking on: ${url}`);
205
    return this.httpClient.get<RepositorySummaryInfo[]>(url, headerOptions);
206
  }
207 61394 stefania.m
208
  getRepositoryAdmins(repoId: string): Observable<User[]> {
209
    const url = `${this.apiUrl}${repoId}/admins`;
210
    console.log(`knocking on: ${url}`);
211
    return this.httpClient.get<User[]>(url, headerOptions);
212
  }
213
214
  deleteRepositoryAdmin(repoId: string, repoAdminEmail: string) {
215
    const url = `${this.apiUrl}${repoId}/admins/${repoAdminEmail}`;
216
    console.log(`knocking on: ${url}`);
217
218
    return this.httpClient.delete(url, headerOptions);
219
  }
220
221
  addRepositoryAdmin(repoId: string, repoAdminEmail: string) {
222
    const url = `${this.apiUrl}${repoId}/admins`;
223
    return this.httpClient.post<string>(url, repoAdminEmail, headerOptions);
224
  }
225 54479 myrto.kouk
}