From: Lott, Christopher (cl778h) Date: Fri, 21 Jun 2019 14:30:39 +0000 (-0400) Subject: Add mock user data to backend X-Git-Tag: R2~76 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=1fde0c3b93c9cf75b9e48382f298f644b03fa249;hp=b7c9d29d2b472e63bbe0331a413da0e7cd492aee;p=portal%2Fric-dashboard.git Add mock user data to backend Revise frontend to call new backend method Change-Id: Ic3983c09900d31864352ffd37ea36ae601998190 Signed-off-by: Lott, Christopher (cl778h) --- diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 7202a322..f87c161c 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -20,7 +20,7 @@ RIC Dashboard Release Notes =========================== -Version 1.0.4, 20 June 2019 +Version 1.0.4, 21 June 2019 --------------------------- * Add AC xApp neighbor control screen * Add ANR xApp neighbor cell relation table @@ -37,6 +37,7 @@ Version 1.0.4, 20 June 2019 * Add feature resilient to malformed instance data * Extend Xapp Controller with config endpoints * Add build number to dashboard version string +* Move mock admin screen user data to backend Version 1.0.3, 28 May 2019 -------------------------- diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java index c913efb1..67826ded 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java @@ -28,5 +28,6 @@ public abstract class DashboardConstants { public static final String ENDPOINT_PREFIX = "/api/"; public static final String HEALTHCHECK_PATH = "health"; public static final String VERSION_PATH = "version"; + public static final String USER_PATH = "user"; } diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/HealthcheckController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java similarity index 55% rename from webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/HealthcheckController.java rename to webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java index 235bcabd..ed4837d8 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/HealthcheckController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java @@ -7,9 +7,9 @@ * 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. @@ -23,7 +23,10 @@ import java.lang.invoke.MethodHandles; import org.oransc.ric.portal.dashboard.DashboardApplication; import org.oransc.ric.portal.dashboard.DashboardConstants; +import org.oransc.ric.portal.dashboard.model.DashboardUser; import org.oransc.ric.portal.dashboard.model.SuccessTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -32,24 +35,46 @@ import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.ApiOperation; /** - * Answers REST requests for the API service health etc. + * Answers REST requests for admin services like version, health etc. */ @RestController -@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/dashboard", produces = MediaType.APPLICATION_JSON_VALUE) -public class HealthcheckController { +@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/admin", produces = MediaType.APPLICATION_JSON_VALUE) +public class AdminController { - @ApiOperation(value = "Checks the health of the application by (TBD).", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.HEALTHCHECK_PATH, method = RequestMethod.GET) - public SuccessTransport getDashblardHealth() { - long count = 0; - return new SuccessTransport(200, "(TBD) reports count is " + count); + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private final DashboardUser[] users; + + public AdminController() { + // Mock data + users = new DashboardUser[] { // + new DashboardUser(1, "John", "Doe", "Active"), // + new DashboardUser(2, "Alice", "Nolan", "Active"), // + new DashboardUser(3, "Pierce", "King", "Inactive"), // + new DashboardUser(4, "Paul", "Smith", "Inactive"), // + new DashboardUser(5, "Jack", "Reacher", "Active") }; } @ApiOperation(value = "Gets the Dashboard MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) - public SuccessTransport getDashboardVersion() { + public SuccessTransport getVersion() { + logger.debug("getVersion"); return new SuccessTransport(200, DashboardApplication.getImplementationVersion(MethodHandles.lookup().lookupClass())); } + @ApiOperation(value = "Checks the health of the application.", response = SuccessTransport.class) + @RequestMapping(value = DashboardConstants.HEALTHCHECK_PATH, method = RequestMethod.GET) + public SuccessTransport getHealth() { + logger.debug("getHealth"); + return new SuccessTransport(200, "Dashboard is healthy!"); + } + + @ApiOperation(value = "Gets the list of application users.", response = DashboardUser.class, responseContainer = "List") + @RequestMapping(value = DashboardConstants.USER_PATH, method = RequestMethod.GET) + public DashboardUser[] getUsers() { + logger.debug("getUsers"); + return users; + } + } diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/DashboardUser.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/DashboardUser.java new file mode 100644 index 00000000..37186aeb --- /dev/null +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/DashboardUser.java @@ -0,0 +1,101 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * 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=================================== + */ + +/* + * TODO: this mocks user properties until integration with ONAP Portal is done. + */ +package org.oransc.ric.portal.dashboard.model; + +import java.util.Objects; + +public class DashboardUser { + + private long id; + private String firstName; + private String lastName; + private String status; + + public DashboardUser() { + } + + public DashboardUser(long id, String firstName, String lastName, String status) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.status = status; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DashboardUser other = (DashboardUser) obj; + return Objects.equals(id, other.id) && Objects.equals(firstName, other.firstName) + && Objects.equals(lastName, other.lastName) && Objects.equals(status, other.status); + } + +} diff --git a/webapp-frontend/src/app/admin/admin.component.ts b/webapp-frontend/src/app/admin/admin.component.ts index 33ce1e79..8f8a2629 100644 --- a/webapp-frontend/src/app/admin/admin.component.ts +++ b/webapp-frontend/src/app/admin/admin.component.ts @@ -19,15 +19,15 @@ */ import { Component, OnInit } from '@angular/core'; import { LocalDataSource } from 'ng2-smart-table'; -import { AdminService } from '../services/admin/admin.service'; +import { DashboardService } from '../services/dashboard/dashboard.service'; +import { DashboardUser } from '../interfaces/dashboard.types'; @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.css'] }) -export class AdminComponent { - +export class AdminComponent implements OnInit { usersettings = { columns: { @@ -52,9 +52,11 @@ export class AdminComponent { usersource: LocalDataSource = new LocalDataSource(); - constructor(private service: AdminService) { - const data = this.service.getData(); - this.usersource.load(data); + constructor(private service: DashboardService) { + } + + ngOnInit() { + this.service.getUsers().subscribe((res: DashboardUser[]) => this.usersource.load(res)); } onDeleteUserConfirm(event): void { diff --git a/webapp-frontend/src/app/app.module.ts b/webapp-frontend/src/app/app.module.ts index b170af39..5d8a611b 100644 --- a/webapp-frontend/src/app/app.module.ts +++ b/webapp-frontend/src/app/app.module.ts @@ -40,7 +40,6 @@ import { AppComponent } from './app.component'; import { LoginComponent } from './login/login.component'; import { CatalogComponent } from './catalog/catalog.component'; import { UiService } from './services/ui/ui.service'; -import { AdminService } from './services/admin/admin.service'; import { XappMgrService } from './services/xapp-mgr/xapp-mgr.service'; import { DashboardService } from './services/dashboard/dashboard.service'; import { E2ManagerService } from './services/e2-mgr/e2-mgr.service'; @@ -145,7 +144,6 @@ import { AcXappComponent } from './ac-xapp/ac-xapp.component'; ], providers: [ UiService, - AdminService, XappMgrService, DashboardService, E2ManagerService, diff --git a/webapp-frontend/src/app/interfaces/dashboard.types.ts b/webapp-frontend/src/app/interfaces/dashboard.types.ts index 01a9d72a..c35016c0 100644 --- a/webapp-frontend/src/app/interfaces/dashboard.types.ts +++ b/webapp-frontend/src/app/interfaces/dashboard.types.ts @@ -18,9 +18,16 @@ * ========================LICENSE_END=================================== */ -// Models of data used by the Dashboard +// Models of data used by Dashboard admin services export interface DashboardSuccessTransport { status: number; data: string; } + +export interface DashboardUser { + id: number; + firstName: string; + lastName: string; + status: string; +} diff --git a/webapp-frontend/src/app/services/admin/admin.service.spec.ts b/webapp-frontend/src/app/services/admin/admin.service.spec.ts deleted file mode 100644 index acc9f437..00000000 --- a/webapp-frontend/src/app/services/admin/admin.service.spec.ts +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia - * %% - * 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 { AdminService } from './admin.service'; - -describe('ControlService', () => { - beforeEach(() => TestBed.configureTestingModule({})); - - it('should be created', () => { - const service: AdminService = TestBed.get(AdminService); - expect(service).toBeTruthy(); - }); -}); diff --git a/webapp-frontend/src/app/services/admin/admin.service.ts b/webapp-frontend/src/app/services/admin/admin.service.ts deleted file mode 100644 index 41b2b220..00000000 --- a/webapp-frontend/src/app/services/admin/admin.service.ts +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia - * %% - * 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() -export class AdminService { - -data = [{ - id: 1, - firstName: 'John', - lastName: 'Doe', - status: 'Active', - }, { - id: 2, - firstName: 'Alice', - lastName: 'Nolan', - status: 'Active', - }, { - id: 3, - firstName: 'Pierce', - lastName: 'King', - status: 'InActive', - }, { - id: 4, - firstName: 'Paul', - lastName: 'Smith', - status: 'InActive', - }, { - id: 5, - firstName: 'Jack', - lastName: 'Reacher', - status: 'Active', - }]; - - getData() { - return this.data; // @TODO implement the service to fetch the backend data - } -} diff --git a/webapp-frontend/src/app/services/dashboard/dashboard.service.ts b/webapp-frontend/src/app/services/dashboard/dashboard.service.ts index 9a79f143..ea4b7ebf 100644 --- a/webapp-frontend/src/app/services/dashboard/dashboard.service.ts +++ b/webapp-frontend/src/app/services/dashboard/dashboard.service.ts @@ -19,17 +19,19 @@ */ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { DashboardSuccessTransport, DashboardUser } from '../../interfaces/dashboard.types'; @Injectable({ providedIn: 'root' }) /** - * Services to query the dashboard's healthcheck controller. + * Services to query the dashboard's admin endpoints. */ export class DashboardService { - private basePath = 'api/dashboard/'; + private basePath = 'api/admin/'; constructor(private httpClient: HttpClient) { // injects to variable httpClient @@ -39,16 +41,24 @@ export class DashboardService { * Checks app health * @returns Observable that should yield a DashboardSuccessTransport */ - getHealth() { - return this.httpClient.get(this.basePath + 'health'); + getHealth(): Observable { + return this.httpClient.get(this.basePath + 'health'); } /** * Gets Dashboard version details * @returns Observable that should yield a DashboardSuccessTransport object */ - getVersion() { - return this.httpClient.get(this.basePath + 'version'); + getVersion(): Observable { + return this.httpClient.get(this.basePath + 'version'); + } + + /** + * Gets Dashboard users + * @returns Observable that should yield a DashboardUser array + */ + getUsers(): Observable { + return this.httpClient.get(this.basePath + 'user'); } }