Add mock user data to backend 00/400/2
authorLott, Christopher (cl778h) <cl778h@att.com>
Fri, 21 Jun 2019 14:30:39 +0000 (10:30 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Fri, 21 Jun 2019 14:33:18 +0000 (10:33 -0400)
Revise frontend to call new backend method

Change-Id: Ic3983c09900d31864352ffd37ea36ae601998190
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
docs/release-notes.rst
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/DashboardConstants.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java [moved from webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/HealthcheckController.java with 55% similarity]
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/DashboardUser.java [new file with mode: 0644]
webapp-frontend/src/app/admin/admin.component.ts
webapp-frontend/src/app/app.module.ts
webapp-frontend/src/app/interfaces/dashboard.types.ts
webapp-frontend/src/app/services/admin/admin.service.spec.ts [deleted file]
webapp-frontend/src/app/services/admin/admin.service.ts [deleted file]
webapp-frontend/src/app/services/dashboard/dashboard.service.ts

index 7202a32..f87c161 100644 (file)
@@ -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
 --------------------------
index c913efb..67826de 100644 (file)
@@ -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";
 
 }
@@ -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 (file)
index 0000000..37186ae
--- /dev/null
@@ -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);
+       }
+
+}
index 33ce1e7..8f8a262 100644 (file)
  */
 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 {
index b170af3..5d8a611 100644 (file)
@@ -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,
index 01a9d72..c35016c 100644 (file)
  * ========================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 (file)
index acc9f43..0000000
+++ /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 (file)
index 41b2b22..0000000
+++ /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
-  }
-}
index 9a79f14..ea4b7eb 100644 (file)
  */
 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<DashboardSuccessTransport> {
+    return this.httpClient.get<DashboardSuccessTransport>(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<DashboardSuccessTransport> {
+    return this.httpClient.get<DashboardSuccessTransport>(this.basePath + 'version');
+  }
+
+  /**
+   * Gets Dashboard users
+   * @returns Observable that should yield a DashboardUser array
+   */
+  getUsers(): Observable<DashboardUser[]> {
+    return this.httpClient.get<DashboardUser[]>(this.basePath + 'user');
   }
 
 }