diff options
Diffstat (limited to 'mod2/ui/src/app/services')
25 files changed, 1228 insertions, 0 deletions
diff --git a/mod2/ui/src/app/services/auth.service.spec.ts b/mod2/ui/src/app/services/auth.service.spec.ts new file mode 100644 index 0000000..eecc055 --- /dev/null +++ b/mod2/ui/src/app/services/auth.service.spec.ts @@ -0,0 +1,43 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { AuthService } from './auth.service'; + +describe('AuthService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ], + imports: [ + HttpClientTestingModule, + RouterTestingModule + ] + }); + }); + it('should be created', () => { + const service: AuthService = TestBed.get(AuthService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/auth.service.ts b/mod2/ui/src/app/services/auth.service.ts new file mode 100644 index 0000000..49bb5f1 --- /dev/null +++ b/mod2/ui/src/app/services/auth.service.ts @@ -0,0 +1,95 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHandler, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { tap } from 'rxjs/internal/operators'; +import { User } from '../models/User'; +import { JwtHelperService } from '@auth0/angular-jwt'; +import { AuthResponse } from '../models/AuthResponse'; +import { Router } from '@angular/router'; +import { environment } from '../../environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class AuthService{ + + private user: User = { + username: '', + roles:[] + }; + authPass=false; + isAdmin=false; + reLoginMsg = false; + + constructor( + private http:HttpClient, + private jwtHelper: JwtHelperService, + private router: Router + ) { + + } + + register(user: User): Observable<AuthResponse> { + return this.http.post<AuthResponse>(`http://${environment.api_baseURL}:31003/api/auth/signup`, user); + // return this.http.post<AuthResponse>(`http://localhost:8082/api/auth/signup`, user); + + } + + login(user: User): Observable<AuthResponse> { + return this.http.post<AuthResponse>(`http://${environment.api_baseURL}:31003/api/auth/signin`, user) + .pipe( + tap((res: AuthResponse) => { + localStorage.setItem('token', res.token); + this.setUser(); + this.authPass = true; + }) + ); + } + + setUser() { + this.user.username = this.jwtHelper.decodeToken(localStorage.getItem('token')).sub; + this.user.roles = this.jwtHelper.decodeToken(localStorage.getItem('token')).roles; + this.user.fullName = this.jwtHelper.decodeToken(localStorage.getItem('token')).fullName; + + } + + checkLogin(): Observable<boolean>{ + return this.http.post<boolean>(`http://${environment.api_baseURL}:31003/api/auth/validate-token`, null); + } + + getJwt() { + if(localStorage.getItem('token')){ + return localStorage.getItem('token'); + } + return ""; + } + + logout() { + localStorage.removeItem('token'); + this.authPass = false; + this.router.navigate(['/login']); + } + + getUser(): User { + return this.user; + } + +} diff --git a/mod2/ui/src/app/services/base-microservice.service.spec.ts b/mod2/ui/src/app/services/base-microservice.service.spec.ts new file mode 100644 index 0000000..1cef5bd --- /dev/null +++ b/mod2/ui/src/app/services/base-microservice.service.spec.ts @@ -0,0 +1,42 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { BaseMicroserviceService } from './base-microservice.service'; + +describe('BaseMicroserviceService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + + it('should be created', () => { + const service: BaseMicroserviceService = TestBed.get(BaseMicroserviceService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/base-microservice.service.ts b/mod2/ui/src/app/services/base-microservice.service.ts new file mode 100644 index 0000000..a5c64b1 --- /dev/null +++ b/mod2/ui/src/app/services/base-microservice.service.ts @@ -0,0 +1,35 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; +import { HttpClient } from '@angular/common/http'; + +@Injectable({ + providedIn: 'root' +}) +export class BaseMicroserviceService { + + private url: string = `http://${environment.api_baseURL}:31001/api/`; + + constructor(private http: HttpClient) { } + + getAllBaseMs() { + return this.http.get(this.url + "base-microservice"); + } +} diff --git a/mod2/ui/src/app/services/breadcrumb.service.ts b/mod2/ui/src/app/services/breadcrumb.service.ts new file mode 100644 index 0000000..aa647aa --- /dev/null +++ b/mod2/ui/src/app/services/breadcrumb.service.ts @@ -0,0 +1,73 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { Observable, of, Subject, BehaviorSubject } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) + +export class BreadcrumbService { + + breadcrumbs: any[] = []; + + breadcrumbs$: Subject<any[]> = new BehaviorSubject([]); + + constructor() { + this.setBreadcrumbs('', "reset"); + } + + setBreadcrumbs(component: string, action: string) { + if (action == "reset") { + this.breadcrumbs = []; + this.breadcrumbs.push({ page: 'Home', link: '/home' }); + } + + // If the breadcrumb item is clicked, remove evwrything to the right of the clicked item + if (action == "crumbClicked") { + const pos = this.breadcrumbs.map(function(crumb) { return crumb.page }).indexOf(component); + for (1; this.breadcrumbs.length -1 -pos; 1) { + this.breadcrumbs.pop() + } + } else { // Add the component that was selected + if (component == 'Microservices') { + this.breadcrumbs.push({ page: 'Microservices', link: '/base-microservices' }); + } else if (component == 'MS Instances') { + this.breadcrumbs.push({ page: 'MS Instances', link: '/ms-instances' }); + } else if (component == 'Blueprints') { + this.breadcrumbs.push({ page: 'Blueprints', link: '/blueprints' }); + } else if (component == 'Component Specs') { + this.breadcrumbs.push({ page: 'Component Specs', link: '/CompSpecs' }); + } else if (component == 'User Management') { + this.breadcrumbs.push({ page: 'User Management', link: '/users' }); + } else if (component == 'Onboarding Tools') { + this.breadcrumbs.push({ page: 'Onboarding Tools', link: '/OnboardingTools' }); + } else if (component == 'Spec Validator') { + this.breadcrumbs.push({ page: 'Spec Validator', link: '/spec-validator' }); + } + } + this.notifySubscriber() + } + + + notifySubscriber() { + this.breadcrumbs$.next(this.breadcrumbs); + } +} + diff --git a/mod2/ui/src/app/services/comp-spec-add.service.spec.ts b/mod2/ui/src/app/services/comp-spec-add.service.spec.ts new file mode 100644 index 0000000..f7f5913 --- /dev/null +++ b/mod2/ui/src/app/services/comp-spec-add.service.spec.ts @@ -0,0 +1,42 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { CompSpecAddService } from './comp-spec-add.service'; + +describe('CompSpecAddService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + + it('should be created', () => { + const service: CompSpecAddService = TestBed.get(CompSpecAddService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/comp-spec-add.service.ts b/mod2/ui/src/app/services/comp-spec-add.service.ts new file mode 100644 index 0000000..d269ac4 --- /dev/null +++ b/mod2/ui/src/app/services/comp-spec-add.service.ts @@ -0,0 +1,45 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { environment } from '../../environments/environment'; +import { Observable } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) + +export class CompSpecAddService { + + private URL: string = `http://${environment.api_baseURL}:31001/api/specification/`; + + constructor(private http: HttpClient) { } + + addCsToCatalog(msInstanceId: string, addCsJson: any): Observable<any> { + let url = this.URL + msInstanceId; + let body = addCsJson; + let headers = new HttpHeaders({ + 'Content-Type': 'application/json' + }); + + let options = {headers:headers} + return this.http.post<any>(url, body, options); + } + +} diff --git a/mod2/ui/src/app/services/comp-specs-service.service.spec.ts b/mod2/ui/src/app/services/comp-specs-service.service.spec.ts new file mode 100644 index 0000000..58cf0a2 --- /dev/null +++ b/mod2/ui/src/app/services/comp-specs-service.service.spec.ts @@ -0,0 +1,43 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { compSpecsService } from './comp-specs-service.service'; + +describe('CompSpecsServiceService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + RouterTestingModule + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + it('should be created', () => { + const service: compSpecsService = TestBed.get(compSpecsService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/comp-specs-service.service.ts b/mod2/ui/src/app/services/comp-specs-service.service.ts new file mode 100644 index 0000000..6fcd92c --- /dev/null +++ b/mod2/ui/src/app/services/comp-specs-service.service.ts @@ -0,0 +1,43 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { environment } from '../../environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class compSpecsService { + + private baseUrl: string = `http://${environment.api_baseURL}:31001/api/specification/`; + constructor(private http: HttpClient) { + } + + getAllCompSpecs(instanceId) { + let url = this.baseUrl + instanceId + + return this.http.get(url); + } + + post(msId, body){ + let url: string = this.baseUrl + msId + + return this.http.post<any>(url, body) + } +} diff --git a/mod2/ui/src/app/services/deployment-artifact.service.spec.ts b/mod2/ui/src/app/services/deployment-artifact.service.spec.ts new file mode 100644 index 0000000..f392732 --- /dev/null +++ b/mod2/ui/src/app/services/deployment-artifact.service.spec.ts @@ -0,0 +1,43 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { DeploymentArtifactService } from './deployment-artifact.service'; + +describe('DeploymentArtifactService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + RouterTestingModule + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + it('should be created', () => { + const service: DeploymentArtifactService = TestBed.get(DeploymentArtifactService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/deployment-artifact.service.ts b/mod2/ui/src/app/services/deployment-artifact.service.ts new file mode 100644 index 0000000..e344bff --- /dev/null +++ b/mod2/ui/src/app/services/deployment-artifact.service.ts @@ -0,0 +1,71 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { environment } from '../../environments/environment'; +import { AuthService } from './auth.service'; + +@Injectable({ + providedIn: 'root' +}) +export class DeploymentArtifactService { + + private URL: string = `http://${environment.api_baseURL}:31001/api/deployment-artifact/`; + private username = this.authService.getUser().username; + private url_User = "?user=" + this.username; + + constructor(private http: HttpClient, private authService: AuthService) { } + + getAllBlueprints() { + return this.http.get(this.URL); + } + + getStatuses() { + let url = this.URL + 'statuses' + + return this.http.get(url) + } + + patchBlueprintStatus(update, bpId){ + let url = this.URL + bpId + "?user=" + this.username + let status: string = update + let body = { + status: status + } + + return this.http.patch(url, body) + } + + postBlueprint(instanceID: string){ + let url = '' + + url = this.URL + instanceID + "?user=" + this.username + console.log(url) + + return this.http.post<any>(url, '') + } + + deleteBlueprint(instanceID: string){ + console.log(instanceID) + let url = this.URL + instanceID + this.url_User + + return this.http.delete(url) + } + +} diff --git a/mod2/ui/src/app/services/download.service.spec.ts b/mod2/ui/src/app/services/download.service.spec.ts new file mode 100644 index 0000000..1df7bfd --- /dev/null +++ b/mod2/ui/src/app/services/download.service.spec.ts @@ -0,0 +1,41 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { DownloadService } from './download.service'; + +describe('DownloadService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + it('should be created', () => { + const service: DownloadService = TestBed.get(DownloadService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/download.service.ts b/mod2/ui/src/app/services/download.service.ts new file mode 100644 index 0000000..619eff7 --- /dev/null +++ b/mod2/ui/src/app/services/download.service.ts @@ -0,0 +1,85 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import * as saveAs from 'file-saver'; + +@Injectable({ + providedIn: 'root' +}) +export class DownloadService { + + constructor() { } + + /* * * * Download json file * * * */ + downloadJSON(content, fileName){ + let file = new Blob([JSON.stringify(content)], { type: 'text;charset=utf-8' }); + let name: string = `${fileName}.json` + saveAs(file, name) + } + + /* * * * Export ms instance table to excel or csv * * * */ + exportTableData(exportTo, downloadElements, arrHeader) { + if (exportTo === "excel") { + import("xlsx").then(xlsx => { + const worksheet = xlsx.utils.json_to_sheet(downloadElements); + const workbook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] }; + const excelBuffer: any = xlsx.write(workbook, { bookType: 'xlsx', type: 'array' }); + this.saveAsExcelFile(excelBuffer, "Table_Data"); + }); + } else if (exportTo === "csv") { + let csvData = this.convertToCSV(downloadElements, arrHeader) + var blob = new Blob([csvData], { type: 'text/csv' }) + saveAs(blob, "Table_Data.csv"); + } + } + saveAsExcelFile(buffer: any, fileName: string): void { + import("file-saver").then(FileSaver => { + let EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'; + let EXCEL_EXTENSION = '.xlsx'; + const data: Blob = new Blob([buffer], { + type: EXCEL_TYPE + }); + FileSaver.saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION); + }); + } + convertToCSV(objArray, headerList) { + let array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; + let str = ''; + let row = ''; + for (let index in headerList) { + row += headerList[index] + ','; + } + row = row.slice(0, -1); + str += row + '\r\n'; + for (let i = 0; i < array.length; i++) { + let line = ''; + for (let index in headerList) { + let head = headerList[index]; + if (array[i][head] === null || array[i][head] === undefined) { + line += ',' + } else { + if (head === "Labels" && array[i][head].length > 1) { line += '[' + array[i][head].join('] [') + '],'; } + else { line += array[i][head] + ','; } + } + } + str += line + '\r\n'; + } + return str; + } +} diff --git a/mod2/ui/src/app/services/global-filters.service.spec.ts b/mod2/ui/src/app/services/global-filters.service.spec.ts new file mode 100644 index 0000000..cadfd3f --- /dev/null +++ b/mod2/ui/src/app/services/global-filters.service.spec.ts @@ -0,0 +1,30 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { TestBed } from '@angular/core/testing'; + +import { GlobalFiltersService } from './global-filters.service'; + +describe('GlobalFiltersService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: GlobalFiltersService = TestBed.get(GlobalFiltersService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/global-filters.service.ts b/mod2/ui/src/app/services/global-filters.service.ts new file mode 100644 index 0000000..0937f92 --- /dev/null +++ b/mod2/ui/src/app/services/global-filters.service.ts @@ -0,0 +1,55 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class GlobalFiltersService { + + //global filter values + instanceName: string; + instanceTag: string; + release: string; + status: string; + + shouldFilter: boolean = false; + + constructor() { } + + setFilters(filters){ + this.instanceName = filters.instanceName + this.instanceTag = filters.instanceTag + this.release = filters.release + this.status = filters.status + } + + getFilters(){ + let globalFilters = {instanceName: this.instanceName, instanceTag: this.instanceTag, release: this.release, status: this.status} + return globalFilters + } + + checkShouldFilter(){ + return this.shouldFilter + } + + setShouldFilter(){ + this.shouldFilter = !this.shouldFilter + } +} diff --git a/mod2/ui/src/app/services/jwt-interceptor.service.spec.ts b/mod2/ui/src/app/services/jwt-interceptor.service.spec.ts new file mode 100644 index 0000000..6fea9ba --- /dev/null +++ b/mod2/ui/src/app/services/jwt-interceptor.service.spec.ts @@ -0,0 +1,30 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { TestBed } from '@angular/core/testing'; + +import { JwtInterceptorService } from './jwt-interceptor.service'; + +describe('JwtInterceptorService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: JwtInterceptorService = TestBed.get(JwtInterceptorService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/jwt-interceptor.service.ts b/mod2/ui/src/app/services/jwt-interceptor.service.ts new file mode 100644 index 0000000..2647583 --- /dev/null +++ b/mod2/ui/src/app/services/jwt-interceptor.service.ts @@ -0,0 +1,40 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable, Injector } from '@angular/core'; +import { HttpInterceptor } from '@angular/common/http'; +import { AuthService } from './auth.service'; + +@Injectable({ + providedIn: 'root' +}) +export class JwtInterceptorService implements HttpInterceptor{ + + constructor(private injector: Injector) { } + + intercept(req: import("@angular/common/http").HttpRequest<any>, next: import("@angular/common/http").HttpHandler): import("rxjs").Observable<import("@angular/common/http").HttpEvent<any>> { + let authService = this.injector.get(AuthService); + let jwtReq = req.clone({ + setHeaders: { + Authorization: `Bearer ${authService.getJwt()}` + } + }) + return next.handle(jwtReq); + } + +} diff --git a/mod2/ui/src/app/services/microservice-instance.service.spec.ts b/mod2/ui/src/app/services/microservice-instance.service.spec.ts new file mode 100644 index 0000000..b3c4074 --- /dev/null +++ b/mod2/ui/src/app/services/microservice-instance.service.spec.ts @@ -0,0 +1,41 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { MicroserviceInstanceService } from './microservice-instance.service'; + +describe('MicroserviceInstanceService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + it('should be created', () => { + const service: MicroserviceInstanceService = TestBed.get(MicroserviceInstanceService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/microservice-instance.service.ts b/mod2/ui/src/app/services/microservice-instance.service.ts new file mode 100644 index 0000000..96cce77 --- /dev/null +++ b/mod2/ui/src/app/services/microservice-instance.service.ts @@ -0,0 +1,46 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; +import { HttpClient } from '@angular/common/http'; +import { AddMsInstance } from '../microservices/microservices.component'; + +@Injectable({ + providedIn: 'root' +}) +export class MicroserviceInstanceService { + + private url: string = `http://${environment.api_baseURL}:31001/api/microservice-instance/`; + + constructor(private http: HttpClient) { } + + getAllMsInstances() { + return this.http.get(this.url); + } + + addChangeMsInstance(addOrChange: string, msNameOrId: string, body: AddMsInstance){ + let URL = this.url + msNameOrId + + if (addOrChange == "ADD") { + return this.http.post<any>(URL, body); + } else { + return this.http.patch<any>(URL, body); + } + } +} diff --git a/mod2/ui/src/app/services/ms-add.service.spec.ts b/mod2/ui/src/app/services/ms-add.service.spec.ts new file mode 100644 index 0000000..dc53a56 --- /dev/null +++ b/mod2/ui/src/app/services/ms-add.service.spec.ts @@ -0,0 +1,42 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { MsAddService } from './ms-add.service'; + +describe('MsAddService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + + it('should be created', () => { + const service: MsAddService = TestBed.get(MsAddService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/ms-add.service.ts b/mod2/ui/src/app/services/ms-add.service.ts new file mode 100644 index 0000000..367799d --- /dev/null +++ b/mod2/ui/src/app/services/ms-add.service.ts @@ -0,0 +1,52 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { environment } from '../../environments/environment'; +import { Observable } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) + + + +export class MsAddService { + + private URL: string = `http://${environment.api_baseURL}:31001/api/base-microservice`; + + constructor(private http: HttpClient) { } + + addChangeMsToCatalog(addOrChange, msID, addChangeMsJson): Observable<any> { + let url = this.URL; + let headers = new HttpHeaders({'Content-Type': 'application/json'}); + let options = {headers:headers}; + let body; + + body = addChangeMsJson; + + if (addOrChange == "Add") { + return this.http.post<any>(url, body, options); + } else { + url = url + "/" + msID; + return this.http.patch<any>(url, body, options); + } + } + +} diff --git a/mod2/ui/src/app/services/spec-validation.service.spec.ts b/mod2/ui/src/app/services/spec-validation.service.spec.ts new file mode 100644 index 0000000..e83f832 --- /dev/null +++ b/mod2/ui/src/app/services/spec-validation.service.spec.ts @@ -0,0 +1,41 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { SpecValidationService } from './spec-validation.service'; + +describe('SpecValidationService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule, + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + it('should be created', () => { + const service: SpecValidationService = TestBed.get(SpecValidationService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/spec-validation.service.ts b/mod2/ui/src/app/services/spec-validation.service.ts new file mode 100644 index 0000000..2785efe --- /dev/null +++ b/mod2/ui/src/app/services/spec-validation.service.ts @@ -0,0 +1,53 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; + +@Injectable({ + providedIn: 'root' +}) +export class SpecValidationService { + + private URL: string = 'http://zlecdyh2adcc1s2dokr04.1463c9.dyh2a.tci.att.com:31002/'; + + constructor(private http: HttpClient) { } + + sendSpecFile(specContent, type, release){ + + let url = '' + + if(release === "2007"){ + url = `${this.URL}v6/api/comp_spec_validator/` + } + + let body = { + compspec_content: specContent, + type: type + } + + return this.http.post(url, body) + } + + getSchema(type){ + let url = `${this.URL}v6/api/schema/${type}` + + return this.http.get(url) + } +} diff --git a/mod2/ui/src/app/services/user.service.spec.ts b/mod2/ui/src/app/services/user.service.spec.ts new file mode 100644 index 0000000..979e9fa --- /dev/null +++ b/mod2/ui/src/app/services/user.service.spec.ts @@ -0,0 +1,44 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { async, TestBed } from '@angular/core/testing'; +import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt'; + +import { UserService } from './user.service'; + +describe('UserService', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + HttpClientTestingModule + ], + providers: [ + { provide: JWT_OPTIONS, useValue: JWT_OPTIONS }, + JwtHelperService + ] + }).compileComponents(); + })); + + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: UserService = TestBed.get(UserService); + expect(service).toBeTruthy(); + }); +}); diff --git a/mod2/ui/src/app/services/user.service.ts b/mod2/ui/src/app/services/user.service.ts new file mode 100644 index 0000000..ec1d503 --- /dev/null +++ b/mod2/ui/src/app/services/user.service.ts @@ -0,0 +1,53 @@ +/* + * # ============LICENSE_START======================================================= + * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * # ================================================================================ + * # Licensed under the Apache License, Version 2.0 (the "License"); + * # you may not use this file except in compliance with the License. + * # You may obtain a copy of the License at + * # + * # http://www.apache.org/licenses/LICENSE-2.0 + * # + * # Unless required by applicable law or agreed to in writing, software + * # distributed under the License is distributed on an "AS IS" BASIS, + * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * # See the License for the specific language governing permissions and + * # limitations under the License. + * # ============LICENSE_END========================================================= + */ + +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { User } from '../models/User'; +import { AuthResponse } from '../models/AuthResponse'; +import { environment } from '../../environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class UserService { + + constructor(private http: HttpClient) {} + + getUsers(): Observable<User[]> { + return this.http.get<User[]>(`http://${environment.api_baseURL}:31003/api/users/getAll`); + } + + editUser(username: string, user: User): Observable<any>{ + return this.http.patch<any>(`http://${environment.api_baseURL}:31003/api/users/admin/${username}`, user); + } + + editProfile(username: string, user: User): Observable<any>{ + return this.http.patch<any>(`http://${environment.api_baseURL}:31003/api/users/user/${username}`, user); + } + + deleteUser(username: string): Observable<{message:string}> { + return this.http.delete<{message: string}>(`http://${environment.api_baseURL}:31003/api/users/${username}`); + } + + getRoles() { + return this.http.get(`http://${environment.api_baseURL}:31003/api/roles`); + } + +} |