/* * Created by myrto on 12/05/2017 */ import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import { Injectable } from '@angular/core'; import { environment } from '../../environments/environment'; import { AggregationDetails, Country, MetricsInfo, Repository, RepositoryInterface, RepositorySnippet, RepositorySummaryInfo, TermsOfUse, Timezone, Typology, User } from '../domain/typeScriptClasses'; import { Observable, of } from 'rxjs'; import { timezones } from '../domain/timezones'; import { typologies } from '../domain/typologies'; import {URLParameter} from '../domain/url-parameter'; const headerOptions = { headers : new HttpHeaders().set('Content-Type', 'application/json') .set('Accept', 'application/json'), withCredentials: true }; @Injectable () export class RepositoryService { private apiUrl = environment.API_ENDPOINT + '/repositories/'; private dashboardAPIUrl = environment.API_ENDPOINT + '/dashboard/'; constructor(private httpClient: HttpClient) { } addInterface(datatype: string, repoId: string, registeredBy: string, comment: string, newInterface: RepositoryInterface, desiredCompatibilityLevel: string): Observable { let url; comment = newInterface.comments; // temp fix for emailing comment if (comment == null || comment === '') { url = `${this.apiUrl}addInterface?datatype=${datatype}&repoId=${repoId}®isteredBy=${registeredBy}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`; } else { url = `${this.apiUrl}addInterface?datatype=${datatype}&repoId=${repoId}®isteredBy=${registeredBy}&comment=${comment}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`; } console.log(`knocking on: ${url}`); console.log(`sending ${JSON.stringify(newInterface)}`); return this.httpClient.post(url, newInterface, headerOptions); } updateInterface(repoId: string, registeredBy: string, comment: string, interfaceInfo: RepositoryInterface, desiredCompatibilityLevel?: string): Observable { let url; comment = interfaceInfo.comments; // temp fix for emailing comment if (comment == null || comment === '') { url = `${this.apiUrl}updateRepositoryInterface?repoId=${repoId}®isteredBy=${registeredBy}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`; } else { url = `${this.apiUrl}updateRepositoryInterface?repoId=${repoId}®isteredBy=${registeredBy}&comment=${comment}&desiredCompatibilityLevel=${desiredCompatibilityLevel}`; } console.log(`knocking on: ${url}`); console.log(`sending ${JSON.stringify(interfaceInfo)}`); return this.httpClient.post(url, interfaceInfo, headerOptions); } deleteInterface(id: string, registeredBy: string) { const url = `${this.apiUrl}deleteInterface/?id=${id}®isteredBy=${registeredBy}`; console.log(`knocking on: ${url}`); return this.httpClient.delete(url, {withCredentials: true, responseType: 'text'}); } getInterfaceDesiredCompatibilityLevel(repoId: string, interfaceId: string) { return this.httpClient.get(environment.API_ENDPOINT + `/compliance/${repoId}/${interfaceId}`); } addRepository(datatype: string, newRepository: Repository): Observable { const url = `${this.apiUrl}addRepository?datatype=${datatype}`; console.log(`knocking on: ${url}`); console.log(`sending ${JSON.stringify(newRepository)}`); return this.httpClient.post(url, newRepository, headerOptions); } // updateRepository(repoInfo: Repository): Observable { // const url = `${this.apiUrl}updateRepository`; // console.log(`knocking on: ${url}`); // console.log(`sending ${JSON.stringify(repoInfo)}`); // return this.httpClient.post(url, repoInfo, headerOptions); // } updateRepository(repoInfo: Repository): Observable { const url = `${this.apiUrl}updateRepository`; console.log(`knocking on: ${url}`); console.log(`sending ${JSON.stringify(repoInfo)}`); return this.httpClient.post(url, repoInfo, headerOptions); } updateRepositoriesTerms(termsList: any): Observable { const url = `${this.apiUrl}terms`; console.log(`knocking on: ${url}`); console.log(`sending ${JSON.stringify(termsList)}`); return this.httpClient.post(url, termsList, headerOptions); } getRepositoriesOfCountry(country: string, mode: string): Observable { const url = `${this.apiUrl}getRepositoriesByCountry/${country}/${mode}`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getRepositoriesSnippetsOfUser(): Observable { const url = `${this.apiUrl}snippets/user`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getRepositoryById(id: string): Observable { const url = `${this.apiUrl}getRepositoryById/${id}`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getRepositoryInterface(id: string): Observable { const url = `${this.apiUrl}getRepositoryInterface/${id}`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getUrlsOfUserRepos(): Observable { const url = `${this.apiUrl}getUrlsOfUserRepos/0/100/`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getRepositoryAggregations(id: string): Observable { const url = `${this.apiUrl}getRepositoryAggregations/${id}`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getRepositoryAggregationsByYear(id: string): Observable> { const url = `${this.apiUrl}getRepositoryAggregationsByYear/${id}`; console.log(`knocking on: ${url}`); return this.httpClient.get>(url, headerOptions); } getTimezones(): Observable { /* const url = `${this.apiUrl}getTimezones`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions);*/ return of(timezones); } getTypologies(): Observable { /* const url = `${this.apiUrl}getTypologies`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions);*/ return of(typologies); } getCountries(): Observable { const url = `${this.apiUrl}countries`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getCompatibilityClasses (mode: string): Observable> { const url = `${this.apiUrl}getCompatibilityClasses/${mode}`; console.log(`knocking on: ${url}`); return this.httpClient.get>(url, headerOptions); } getDatasourceClasses(mode: string): Observable { const url = `${this.apiUrl}getDatasourceClasses/${mode}`; console.log(`knocking on: ${url}`); return this.httpClient.get>(url, headerOptions); } getMetricsInfoForRepository (repoId: string): Observable { const url = `${this.apiUrl}getMetricsInfoForRepository/${repoId}`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getListLatestUpdate(mode: string): Observable { const url = `${this.apiUrl}getListLatestUpdate/${mode}`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } searchRegisteredRepositories(page, size, urlParams: URLParameter[]) { const url = `${this.apiUrl}searchRegisteredRepositories/${page}/${size}`; console.log(`knocking on: ${url}`); let params = new HttpParams(); for (const urlParameter of urlParams) { for (const value of urlParameter.value) { params = params.append(urlParameter.key, value); } } return this.httpClient.get(url, {params, withCredentials: true}); } getRepositoriesSummaryInfo(): Observable { const url = `${this.dashboardAPIUrl}getRepositoriesSummary/0/100`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } getRepositoryAdmins(repoId: string): Observable { const url = `${this.apiUrl}${repoId}/admins`; console.log(`knocking on: ${url}`); return this.httpClient.get(url, headerOptions); } deleteRepositoryAdmin(repoId: string, repoAdminEmail: string) { const url = `${this.apiUrl}${repoId}/admins/${repoAdminEmail}`; console.log(`knocking on: ${url}`); return this.httpClient.delete(url, headerOptions); } addRepositoryAdmin(repoId: string, repoAdminEmail: string) { const url = `${this.apiUrl}${repoId}/admins`; return this.httpClient.post(url, repoAdminEmail, headerOptions); } }