Add A1 Policy Type/Policy Types logic from backend 96/5496/6
authorLathish <lathishbabu.ganesan@est.tech>
Fri, 22 Jan 2021 10:43:14 +0000 (10:43 +0000)
committerLathish <lathishbabu.ganesan@est.tech>
Mon, 25 Jan 2021 15:46:43 +0000 (15:46 +0000)
This commit do not test the Policy instances functionality.

Issue-ID: NONRTRIC-407
Change-Id: Id537ae199737d4892b1f344c68cf397cda5f5853
Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
15 files changed:
webapp-frontend/nginx.conf
webapp-frontend/src/app/interceptor.mock.ts
webapp-frontend/src/app/interfaces/policy.types.ts
webapp-frontend/src/app/mock/policy-instance-notype.json [moved from webapp-frontend/src/app/mock/policy-instance-2.json with 100% similarity]
webapp-frontend/src/app/mock/policy-type1.json [new file with mode: 0644]
webapp-frontend/src/app/mock/policy-types.json [new file with mode: 0644]
webapp-frontend/src/app/policy-control/policy-control.component.html
webapp-frontend/src/app/policy-control/policy-control.component.spec.ts
webapp-frontend/src/app/policy-control/policy-control.component.ts
webapp-frontend/src/app/policy-control/policy-instance-dialog.component.ts
webapp-frontend/src/app/policy-control/policy-instance.component.ts
webapp-frontend/src/app/policy-control/policy-instance.datasource.ts
webapp-frontend/src/app/policy-control/policy-type.datasource.ts
webapp-frontend/src/app/services/policy/policy.service.spec.ts
webapp-frontend/src/app/services/policy/policy.service.ts

index 47d7b26..4700d85 100644 (file)
@@ -5,7 +5,7 @@ http {
 
     upstream backend {
         # to be replaced with hostname:port of nonrtric-gateway once it gets ready
-        server  controlpanel-backend-container:8080;
+        server  nonrtricgateway:8080;
     }
 
     server {
index 89034a8..e444d91 100644 (file)
@@ -22,41 +22,54 @@ import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } fr
 import { Injectable, Injector } from '@angular/core';
 import { Observable, of } from 'rxjs';
 import * as policyinstances1 from './mock/policy-instance-1.json';
-import * as policyinstances2 from './mock/policy-instance-2.json';
+import * as policyinstancesNoType from './mock/policy-instance-notype.json';
 import * as eijobs from './mock/ei-jobs.json';
 import * as eiproducers from './mock/ei-producers.json';
 import * as nopolicyinstances from './mock/nopolicyinstances.json';
-import * as policytypes from './mock/policytypes.json';
+import * as policytypesList from './mock/policy-types.json';
+import * as policytypes1 from './mock/policy-type1.json';
 import * as policyinstanceedit from './mock/policy-instance-edit.json';
 import * as rics from './mock/rics.json';
 
 const urls = [
     {
-        url: 'api/policy/policytypes',
-        json: policytypes
+        url: 'v2/policy-types',
+        json: policytypesList
     },
     {
-        url: 'api/policy/policies?type=1',
+        url: 'v2/policy-types/',
+        json: policytypes1
+    },
+    {
+        url: 'v2/policy-types/1',
+        json: policytypes1
+    },
+    {
+        url: 'v2/policies?type=1',
         json: policyinstances1
     },
     {
-        url: 'api/policy/policies?type=2',
-        json: policyinstances2
+        url: 'v2/policies?type=',
+        json: policyinstancesNoType
     },
     {
-        url: 'api/policy/policies?type=2',
+        url: 'v2/policies?type=2',
         json: nopolicyinstances
     },
     {
-        url: 'api/policy/policies/2000?type=1',
+        url: 'v2/policies/2000?type=1',
+        json: policyinstanceedit
+    },
+    {
+        url: 'v2/policies/3000?type=1',
         json: policyinstanceedit
     },
     {
-        url: 'api/policy/policies/2001?type=2',
+        url: 'v2/policies/2001?type=',
         json: policyinstanceedit
     },
     {
-        url: 'api/policy/policies/2000?ric=ric1&type=1',
+        url: 'v2/policies/2000?ric=ric1&type=1',
         json: ''
     },
     {
index b6ecce6..8bc5eb1 100644 (file)
 
 // Models of data used by the Policy Control
 
-export interface PolicyType {
+export interface PolicyTypeSchema {
   name: string;
-  schema: string;
   schemaObject: any;
 }
 
+export interface PolicyType {
+  policy_schema: any;
+}
+
+export interface PolicyTypes {
+  policytype_ids: any[];
+}
+
 export interface PolicyInstance {
   id: string;
   json: string;
diff --git a/webapp-frontend/src/app/mock/policy-type1.json b/webapp-frontend/src/app/mock/policy-type1.json
new file mode 100644 (file)
index 0000000..2777ca1
--- /dev/null
@@ -0,0 +1,43 @@
+{
+  "policy_schema": {
+    "$schema": "http://json-schema.org/draft-07/schema#",
+    "description": "Type 1 policy type",
+    "additionalProperties": false,
+    "title": "1",
+    "type": "object",
+    "properties": {
+      "qosObjectives": {
+        "additionalProperties": false,
+        "type": "object",
+        "properties": {
+          "priorityLevel": {
+            "type": "number"
+          }
+        },
+        "required": [
+          "priorityLevel"
+        ]
+      },
+      "scope": {
+        "additionalProperties": false,
+        "type": "object",
+        "properties": {
+          "qosId": {
+            "type": "string"
+          },
+          "ueId": {
+            "type": "string"
+          }
+        },
+        "required": [
+          "ueId",
+          "qosId"
+        ]
+      }
+    },
+    "required": [
+      "scope",
+      "qosObjectives"
+    ]
+  }
+}
\ No newline at end of file
diff --git a/webapp-frontend/src/app/mock/policy-types.json b/webapp-frontend/src/app/mock/policy-types.json
new file mode 100644 (file)
index 0000000..9bad9ad
--- /dev/null
@@ -0,0 +1,6 @@
+{
+  "policytype_ids": [
+    "",
+    "1"
+  ]
+}
\ No newline at end of file
index 27e56e3..a8f5021 100644 (file)
@@ -18,7 +18,7 @@
   ========================LICENSE_END===================================
   -->
 
-<div fxLayout="row">
+  <div fxLayout="row">
     <div class="rd-global-page-title">Policy Control</div>
     <div class="refresh-button">
         <button mat-icon-button color="primary" aria-label="Button with a refresh icon" (click)="refreshTables()">
 
     <ng-container matColumnDef="name">
         <mat-header-cell *matHeaderCellDef>Policy Type</mat-header-cell>
-        <mat-cell *matCellDef="let policyType">
-            <mat-icon matTooltip="Properties">{{isInstancesShown(policyType)  ? 'expand_less' : 'expand_more'}}
+        <mat-cell *matCellDef="let policyTypeSchema">
+            <mat-icon matTooltip="Properties">{{isInstancesShown(policyTypeSchema)  ? 'expand_less' : 'expand_more'}}
             </mat-icon>
-            {{this.getDisplayName(policyType)}}
+            {{this.getDisplayName(policyTypeSchema)}}
         </mat-cell>
     </ng-container>
 
     <ng-container matColumnDef="description">
         <mat-header-cell *matHeaderCellDef> Description </mat-header-cell>
-        <mat-cell *matCellDef="let policyType"> {{policyType.schemaObject.description}}
+        <mat-cell *matCellDef="let policyTypeSchema"> {{policyTypeSchema.schemaObject.description}}
         </mat-cell>
     </ng-container>
 
     <ng-container matColumnDef="action">
         <mat-header-cell class="action-cell" *matHeaderCellDef>Action </mat-header-cell>
-        <mat-cell class="action-cell" *matCellDef="let policyType" (click)="$event.stopPropagation()">
-            <button mat-icon-button (click)="createPolicyInstance(policyType)">
+        <mat-cell class="action-cell" *matCellDef="let policyTypeSchema" (click)="$event.stopPropagation()">
+            <button mat-icon-button (click)="createPolicyInstance(policyTypeSchema)">
                 <mat-icon matTooltip="Create instance">add_box</mat-icon>
             </button>
         </mat-cell>
@@ -56,8 +56,8 @@
 
     <!-- =================== Policy instances for one type ======================== -->
     <ng-container matColumnDef="instanceTableContainer">
-        <mat-cell *matCellDef="let policyType">
-            <rd-policy-instance [policyType]=policyType [expanded]=this.getExpandedObserver(policyType)>
+        <mat-cell *matCellDef="let policyTypeSchema">
+            <rd-policy-instance [policyTypeSchema]=policyTypeSchema [expanded]=this.getExpandedObserver(policyTypeSchema)>
             </rd-policy-instance>
         </mat-cell>
     </ng-container>
     </ng-container>
 
     <mat-header-row *matHeaderRowDef="['name', 'description', 'action']"></mat-header-row>
-    <mat-row *matRowDef="let policyType; columns: ['name', 'description', 'action']"
-        (click)="toggleListInstances(policyType)">
+    <mat-row *matRowDef="let policyTypeSchema; columns: ['name', 'description', 'action']"
+        (click)="toggleListInstances(policyTypeSchema)">
     </mat-row>
 
-    <mat-row *matRowDef="let policyType; columns: ['instanceTableContainer'];"
-        [@detailExpand]="isInstancesShown(policyType) ? 'expanded' : 'collapsed'" style="overflow: hidden">
+    <mat-row *matRowDef="let policyTypeSchema; columns: ['instanceTableContainer'];"
+        [@detailExpand]="isInstancesShown(policyTypeSchema) ? 'expanded' : 'collapsed'" style="overflow: hidden">
     </mat-row>
 
     <mat-footer-row *matFooterRowDef="['noRecordsFound']"
index a3df258..73914f1 100644 (file)
  */
 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
-import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
 import { MatDialog } from '@angular/material/dialog';
 import { MatIconModule, MatTableModule } from '@angular/material';
+import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
 import { of } from 'rxjs';
 
 import { NotificationService } from '../services/ui/notification.service';
 import { PolicyControlComponent } from './policy-control.component';
 import { PolicyTypeDataSource } from './policy-type.datasource';
 import { UiService } from '../services/ui/ui.service';
+import { PolicyTypeSchema } from '../interfaces/policy.types';
 
 describe('PolicyControlComponent', () => {
   let component: PolicyControlComponent;
   let fixture: ComponentFixture<PolicyControlComponent>;
 
   beforeEach(async(() => {
-    const policyTypeDataSourceSpy = jasmine.createSpyObj('PolicyTypeDataSource', [ 'connect', 'loadTable',  'disconnect' ]);
-    const policyType = {
-      name: "type1",
-      schema: "{}",
-      schemaObject: "{}"
-    }
-    policyTypeDataSourceSpy.connect.and.returnValue(of([ policyType]));
+    const policyTypeDataSourceSpy = jasmine.createSpyObj('PolicyTypeDataSource', [ 'connect', 'getPolicyTypes',  'disconnect' ]);
+    var policyTypeSchema = {} as PolicyTypeSchema;
+    policyTypeSchema.name = '';
+    policyTypeSchema.schemaObject = '';
+    policyTypeDataSourceSpy.connect.and.returnValue(of([ policyTypeSchema]));
     policyTypeDataSourceSpy.disconnect();
 
     let matDialogStub: Partial<MatDialog>;
index d74dc78..3a15226 100644 (file)
@@ -24,14 +24,14 @@ import { MatDialog } from '@angular/material/dialog';
 import { BehaviorSubject, Observable } from 'rxjs';
 
 import { NoTypePolicyInstanceDialogComponent } from './no-type-policy-instance-dialog.component';
-import { PolicyType } from '../interfaces/policy.types';
+import { PolicyTypeSchema } from '../interfaces/policy.types';
 import { PolicyTypeDataSource } from './policy-type.datasource';
 import { getPolicyDialogProperties } from './policy-instance-dialog.component';
 import { PolicyInstanceDialogComponent } from './policy-instance-dialog.component';
 import { UiService } from '../services/ui/ui.service';
 
 class PolicyTypeInfo {
-    constructor(public type: PolicyType) { }
+    constructor(public type: PolicyTypeSchema) { }
 
     isExpanded: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
 }
@@ -60,22 +60,22 @@ export class PolicyControlComponent implements OnInit {
         private ui: UiService) { }
 
     ngOnInit() {
-        this.policyTypesDataSource.loadTable();
+        this.policyTypesDataSource.getPolicyTypes();
         this.ui.darkModeState.subscribe((isDark) => {
             this.darkMode = isDark;
         });
     }
 
-    createPolicyInstance(policyType: PolicyType): void {
+    createPolicyInstance(policyTypeSchema: PolicyTypeSchema): void {
         let dialogRef;
-        if (this.isSchemaEmpty(policyType)) {
+        if (this.isSchemaEmpty(policyTypeSchema)) {
             dialogRef = this.dialog.open(NoTypePolicyInstanceDialogComponent,
-                getPolicyDialogProperties(policyType, null, this.darkMode));
+                getPolicyDialogProperties(policyTypeSchema, null, this.darkMode));
         } else {
             dialogRef = this.dialog.open(PolicyInstanceDialogComponent,
-                getPolicyDialogProperties(policyType, null, this.darkMode));
+                getPolicyDialogProperties(policyTypeSchema, null, this.darkMode));
         }
-        const info: PolicyTypeInfo = this.getPolicyTypeInfo(policyType);
+        const info: PolicyTypeInfo = this.getPolicyTypeInfo(policyTypeSchema);
         dialogRef.afterClosed().subscribe(
             (_) => {
                 info.isExpanded.next(info.isExpanded.getValue());
@@ -83,40 +83,40 @@ export class PolicyControlComponent implements OnInit {
         );
     }
 
-    toggleListInstances(policyType: PolicyType): void {
-        const info = this.getPolicyTypeInfo(policyType);
+    toggleListInstances(policyTypeSchema: PolicyTypeSchema): void {
+        const info = this.getPolicyTypeInfo(policyTypeSchema);
         info.isExpanded.next(!info.isExpanded.getValue());
     }
 
-    private isSchemaEmpty(policyType: PolicyType): boolean {
-        return Object.keys(policyType.schemaObject).length === 0;
+    private isSchemaEmpty(policyTypeSchema: PolicyTypeSchema): boolean {
+        return Object.keys(policyTypeSchema.schemaObject).length === 0;
     }
 
-    getPolicyTypeInfo(policyType: PolicyType): PolicyTypeInfo {
-        let info: PolicyTypeInfo = this.policyTypeInfo.get(policyType.name);
+    getPolicyTypeInfo(policyTypeSchema: PolicyTypeSchema): PolicyTypeInfo {
+        let info: PolicyTypeInfo = this.policyTypeInfo.get(policyTypeSchema.name);
         if (!info) {
-            info = new PolicyTypeInfo(policyType);
-            this.policyTypeInfo.set(policyType.name, info);
+            info = new PolicyTypeInfo(policyTypeSchema);
+            this.policyTypeInfo.set(policyTypeSchema.name, info);
         }
         return info;
     }
 
-    getDisplayName(policyType: PolicyType): string {
-        if (policyType.schemaObject.title) {
-            return policyType.schemaObject.title;
+    getDisplayName(policyTypeSchema: PolicyTypeSchema): string {
+        if (policyTypeSchema.schemaObject.title) {
+            return policyTypeSchema.schemaObject.title;
         }
         return '< No type >';
     }
 
-    isInstancesShown(policyType: PolicyType): boolean {
-        return this.getPolicyTypeInfo(policyType).isExpanded.getValue();
+    isInstancesShown(policyTypeSchema: PolicyTypeSchema): boolean {
+        return this.getPolicyTypeInfo(policyTypeSchema).isExpanded.getValue();
     }
 
-    getExpandedObserver(policyType: PolicyType): Observable<boolean> {
-        return this.getPolicyTypeInfo(policyType).isExpanded.asObservable();
+    getExpandedObserver(policyTypeSchema: PolicyTypeSchema): Observable<boolean> {
+        return this.getPolicyTypeInfo(policyTypeSchema).isExpanded.asObservable();
     }
 
     refreshTables() {
-        this.policyTypesDataSource.loadTable();
+        this.policyTypesDataSource.getPolicyTypes();
     }
 }
index 3dcd79a..781efca 100644 (file)
@@ -23,7 +23,7 @@ import { MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/materia
 import { MatMenuTrigger } from '@angular/material/menu';
 import { JsonPointer } from 'angular6-json-schema-form';
 import * as uuid from 'uuid';
-import { PolicyInstance, PolicyType } from '../interfaces/policy.types';
+import { PolicyInstance, PolicyTypeSchema } from '../interfaces/policy.types';
 import { PolicyService } from '../services/policy/policy.service';
 import { ErrorDialogService } from '../services/ui/error-dialog.service';
 import { NotificationService } from './../services/ui/notification.service';
@@ -223,11 +223,11 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
     }
 }
 
-export function getPolicyDialogProperties(policyType: PolicyType, instance: PolicyInstance, darkMode: boolean): MatDialogConfig {
-    const createSchema = policyType.schemaObject;
+export function getPolicyDialogProperties(policyTypeSchema: PolicyTypeSchema, instance: PolicyInstance, darkMode: boolean): MatDialogConfig {
+    const createSchema = policyTypeSchema.schemaObject;
     const instanceId = instance ? instance.id : null;
     const instanceJson = instance ? instance.json : null;
-    const name = policyType.name;
+    const name = policyTypeSchema.name;
     const ric = instance ? instance.ric : null;
     return {
         maxWidth: '1200px',
index ab9bfd9..f77bd83 100644 (file)
@@ -21,7 +21,7 @@
 import { MatSort } from '@angular/material';
 import { Component, OnInit, ViewChild, Input, AfterViewInit } from '@angular/core';
 import { MatDialog } from '@angular/material/dialog';
-import { PolicyType } from '../interfaces/policy.types';
+import { PolicyTypeSchema } from '../interfaces/policy.types';
 import { PolicyInstanceDataSource } from './policy-instance.datasource';
 import { ErrorDialogService } from '../services/ui/error-dialog.service';
 import { NotificationService } from '../services/ui/notification.service';
@@ -44,7 +44,7 @@ import { UiService } from '../services/ui/ui.service';
 
 export class PolicyInstanceComponent implements OnInit, AfterViewInit {
     instanceDataSource: PolicyInstanceDataSource;
-    @Input() policyType: PolicyType;
+    @Input() policyTypeSchema: PolicyTypeSchema;
     @Input() expanded: Observable<boolean>;
     @ViewChild(MatSort, { static: true }) sort: MatSort;
     darkMode: boolean;
@@ -59,7 +59,7 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit {
     }
 
     ngOnInit() {
-        this.instanceDataSource = new PolicyInstanceDataSource(this.policySvc, this.sort, this.notificationService, this.policyType);
+        this.instanceDataSource = new PolicyInstanceDataSource(this.policySvc, this.sort, this.notificationService, this.policyTypeSchema);
         this.expanded.subscribe((isExpanded: boolean) => this.onExpand(isExpanded));
         this.ui.darkModeState.subscribe((isDark) => {
             this.darkMode = isDark;
@@ -77,17 +77,17 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit {
     }
 
     private isSchemaEmpty(): boolean {
-        return Object.keys(this.policyType.schemaObject).length === 0;
+        return Object.keys(this.policyTypeSchema.schemaObject).length === 0;
     }
 
     modifyInstance(instance: PolicyInstance): void {
-        this.policySvc.getPolicy(this.policyType.name, instance.id).subscribe(
+        this.policySvc.getPolicy(this.policyTypeSchema.name, instance.id).subscribe(
             (refreshedJson: any) => {
                 instance.json = JSON.stringify(refreshedJson);
                 if (this.isSchemaEmpty()) {
                     this.dialog.open(
                         NoTypePolicyInstanceDialogComponent,
-                        getPolicyDialogProperties(this.policyType, instance, this.darkMode)).afterClosed().subscribe(
+                        getPolicyDialogProperties(this.policyTypeSchema, instance, this.darkMode)).afterClosed().subscribe(
                            (_: any) => {
                                 this.instanceDataSource.loadTable();
                            }
@@ -95,7 +95,7 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit {
                 } else {
                     this.dialog.open(
                         PolicyInstanceDialogComponent,
-                        getPolicyDialogProperties(this.policyType, instance, this.darkMode)).afterClosed().subscribe(
+                        getPolicyDialogProperties(this.policyTypeSchema, instance, this.darkMode)).afterClosed().subscribe(
                            (_: any) => {
                                 this.instanceDataSource.loadTable();
                            }
@@ -126,7 +126,7 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit {
             .afterClosed().subscribe(
                 (res: any) => {
                     if (res) {
-                        this.policySvc.deletePolicy(this.policyType.name, instance.id)
+                        this.policySvc.deletePolicy(this.policyTypeSchema.name, instance.id)
                             .subscribe(
                                 (response: HttpResponse<Object>) => {
                                     switch (response.status) {
@@ -144,7 +144,4 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit {
                     }
                 });
     }
-
-
-
 }
index 9cf1d72..4bf2aad 100644 (file)
@@ -26,10 +26,9 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
 import { merge } from 'rxjs';
 import { of } from 'rxjs/observable/of';
 import { catchError, finalize, map } from 'rxjs/operators';
-import { PolicyInstance } from '../interfaces/policy.types';
+import { PolicyInstance, PolicyTypeSchema } from '../interfaces/policy.types';
 import { PolicyService } from '../services/policy/policy.service';
 import { NotificationService } from '../services/ui/notification.service';
-import { PolicyType } from '../interfaces/policy.types';
 
 export class PolicyInstanceDataSource extends DataSource<PolicyInstance> {
 
@@ -45,13 +44,13 @@ export class PolicyInstanceDataSource extends DataSource<PolicyInstance> {
         private policySvc: PolicyService,
         public sort: MatSort,
         private notificationService: NotificationService,
-        private policyType: PolicyType) {
+        private policyTypeSchema: PolicyTypeSchema) {
         super();
     }
 
     loadTable() {
         this.loadingSubject.next(true);
-        this.policySvc.getPolicyInstances(this.policyType.name)
+        this.policySvc.getPolicyInstances(this.policyTypeSchema.name)
             .pipe(
                 catchError((her: HttpErrorResponse) => {
                     this.notificationService.error('Failed to get policy instances: ' + her.error);
index 61ecc4a..db8f01f 100644 (file)
  */
 
 import { CollectionViewer, DataSource } from '@angular/cdk/collections';
-import { HttpErrorResponse } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
 import { of } from 'rxjs/observable/of';
-import { catchError, finalize, map } from 'rxjs/operators';
 import { Observable } from 'rxjs/Observable';
 
-import { PolicyType } from '../interfaces/policy.types';
+import { PolicyTypeSchema } from '../interfaces/policy.types';
 import { PolicyService } from '../services/policy/policy.service';
 import { NotificationService } from '../services/ui/notification.service';
 
@@ -34,13 +32,11 @@ import { NotificationService } from '../services/ui/notification.service';
     providedIn: 'root'
 })
 
-export class PolicyTypeDataSource extends DataSource<PolicyType> {
+export class PolicyTypeDataSource extends DataSource<PolicyTypeSchema> {
 
-    private policyTypeSubject = new BehaviorSubject<PolicyType[]>([]);
+    policyTypes: PolicyTypeSchema[] = [];
 
-    private loadingSubject = new BehaviorSubject<boolean>(false);
-
-    public loading$ = this.loadingSubject.asObservable();
+    private policyTypeSubject = new BehaviorSubject<PolicyTypeSchema[]>([]);
 
     public rowCount = 1; // hide footer during intial load
 
@@ -49,37 +45,35 @@ export class PolicyTypeDataSource extends DataSource<PolicyType> {
         super();
     }
 
-    loadTable() {
-        this.loadingSubject.next(true);
-        this.policySvc.getPolicyTypes()
-            .pipe(
-                catchError((her: HttpErrorResponse) => {
-                    this.notificationService.error('Failed to get policy types: ' + her.statusText + ', ' + her.error);
-                    return of([]);
-                }),
-                finalize(() => this.loadingSubject.next(false))
-            )
-            .subscribe((types: PolicyType[]) => {
-                this.rowCount = types.length;
-                for (let i = 0; i < types.length; i++) {
-                    const policyType = types[i];
-                    try {
-                        policyType.schemaObject = JSON.parse(policyType.schema);
-                    } catch (jsonError) {
-                        console.error('Could not parse schema: ' + policyType.schema);
-                        policyType.schemaObject = { description: 'Incorrect schema: ' + jsonError };
+    public getPolicyTypes() {
+        this.policyTypes = [] as PolicyTypeSchema[];
+        this.policySvc.getPolicyTypes().subscribe(data => {
+            if (data.policytype_ids.length != 0) {
+                data.policytype_ids.forEach(policyId => {
+                    var policyTypeSchema = {} as PolicyTypeSchema
+                    if (policyId === "") {
+                        policyTypeSchema.name = '';
+                        policyTypeSchema.schemaObject = '{}';
+                        this.policyTypes.push(policyTypeSchema);
+                    }
+                    else {
+                        this.policySvc.getPolicyType(policyId).subscribe(policyType => {
+                            policyTypeSchema.schemaObject = policyType.policy_schema;
+                            policyTypeSchema.name = policyType.policy_schema.title;
+                            this.policyTypes.push(policyTypeSchema);
+                        })
                     }
-                }
-                this.policyTypeSubject.next(types);
-            });
+                    this.policyTypeSubject.next(this.policyTypes);
+                })
+            }
+        })
     }
 
-    connect(collectionViewer: CollectionViewer): Observable<PolicyType[]> {
+    connect(collectionViewer: CollectionViewer): Observable<PolicyTypeSchema[]> {
         return of(this.policyTypeSubject.getValue());
     }
 
     disconnect(collectionViewer: CollectionViewer): void {
         this.policyTypeSubject.complete();
-        this.loadingSubject.complete();
     }
 }
index 15f849c..ee20509 100644 (file)
@@ -21,10 +21,11 @@ import { TestBed } from '@angular/core/testing';
 
 import { PolicyService } from './policy.service';
 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
-import { PolicyInstance, PolicyType } from '../../interfaces/policy.types';
+import { PolicyInstance, PolicyTypes } from '../../interfaces/policy.types';
 
 describe('PolicyService', () => {
-  let basePath = 'api/policy';
+  let apiVersion2 = 'v2'
+  let basePath = '';
   let policyService: PolicyService;
   let httpTestingController: HttpTestingController;
   beforeEach(() => TestBed.configureTestingModule({
@@ -39,15 +40,18 @@ describe('PolicyService', () => {
   });
 
   describe('#getPolicyTypes', () => {
-    let expectedPolicytypes: PolicyType[];
+    let expectedPolicytypes: PolicyTypes;
+    let emptyPolicyType: PolicyTypes;
 
     beforeEach(() => {
       policyService = TestBed.get(PolicyService);
       httpTestingController = TestBed.get(HttpTestingController);
-      expectedPolicytypes = [
-        { name: '1', schema: '{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"description\":\"Type 2 policy type\",\"additionalProperties\":false,\"title\":\"2\",\"type\":\"object\",\"properties\":{\"qosObjectives\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"priorityLevel\":{\"type\":\"number\"}},\"required\":[\"priorityLevel\"]},\"scope\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"qosId\":{\"type\":\"string\"},\"ueId\":{\"type\":\"string\"}},\"required\":[\"ueId\",\"qosId\"]}},\"required\":[\"scope\",\"qosObjectives\"]}' },
-        { name: '2', schema: '{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"description\":\"Type 1 policy type\",\"additionalProperties\":false,\"title\":\"1\",\"type\":\"object\",\"properties\":{\"qosObjectives\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"priorityLevel\":{\"type\":\"number\"}},\"required\":[\"priorityLevel\"]},\"scope\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"qosId\":{\"type\":\"string\"},\"ueId\":{\"type\":\"string\"}},\"required\":[\"ueId\",\"qosId\"]}},\"required\":[\"scope\",\"qosObjectives\"]}' },
-      ] as PolicyType[];
+      expectedPolicytypes = {
+        "policytype_ids": [
+          "",
+          "1"
+        ]
+      } as PolicyTypes;
     });
     //Policy Type Test Case 1:
     it('should return all policy types', () => {
@@ -55,22 +59,26 @@ describe('PolicyService', () => {
         policytypes => expect(policytypes).toEqual(expectedPolicytypes, 'should return expected PolicyTypes'),
         fail
       );
-
-      const req = httpTestingController.expectOne(basePath + '/' + policyService.policyTypePath);
+      
+      const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyTypesPath);
       expect(req.request.method).toEqual('GET');
 
-      req.flush(expectedPolicytypes); //Return expectedEmps
+      req.flush(expectedPolicytypes);
     });
 
     //Policy Type Test Case 2:
+    emptyPolicyType = {
+      "policytype_ids": [
+      ]
+    } as PolicyTypes;
     it('should return no policy types', () => {
       policyService.getPolicyTypes().subscribe(
-        policytypes => expect(policytypes.length).toEqual(0, 'should return empty array of Policy Types'),
+        policytypes => expect(policytypes).toEqual(emptyPolicyType, 'should return empty array of Policy Types'),
         fail
       );
 
-      const req = httpTestingController.expectOne(basePath + '/' + policyService.policyTypePath);
-      req.flush([]); //Return empty data
+      const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyTypesPath);
+      req.flush(emptyPolicyType); //Return empty data
     });
   });
   describe('#getPolicyInstance', () => {
@@ -90,18 +98,18 @@ describe('PolicyService', () => {
         policyinstances => expect(policyinstances).toEqual(expectedPolicyInstances, 'should return expected Policy Instances'),
         fail
       );
-      const req = httpTestingController.expectOne(basePath + '/' + policyService.policyPath + '?type=' + policyTypeId);
+      const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyPath + '?type=' + policyTypeId);
       expect(req.request.method).toEqual('GET');
-      req.flush(expectedPolicyInstances); //Return expectedEmps
+      req.flush(expectedPolicyInstances);
     });
 
     //Policy Instances Test Case 2:
     it('should return no policy instances', () => {
       policyService.getPolicyInstances(policyTypeId).subscribe(
-        policyinstances => expect(policyinstances.length).toEqual(0, 'should return empty array of Policy Isntances'),
+        policyinstances => expect(policyinstances.length).toEqual(0, 'should return empty array of Policy Instances'),
         fail
       );
-      const req = httpTestingController.expectOne(basePath + '/' + policyService.policyPath + '?type=' + policyTypeId);
+      const req = httpTestingController.expectOne(basePath + apiVersion2 + '/' + policyService.policyPath + '?type=' + policyTypeId);
       req.flush([]); //Return empty data
     });
   });
index f24747b..c903b2c 100644 (file)
@@ -22,7 +22,7 @@ import { Injectable } from '@angular/core';
 import { HttpClient } from '@angular/common/http';
 import { Observable } from 'rxjs';
 import { map } from 'rxjs/operators';
-import { PolicyType, PolicyInstance, PolicyInstanceAck } from '../../interfaces/policy.types';
+import { PolicyInstance, PolicyInstanceAck, PolicyType, PolicyTypes } from '../../interfaces/policy.types';
 import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.types';
 
 /**
@@ -33,12 +33,13 @@ import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.type
 })
 export class PolicyService {
 
-    private basePath = 'api/policy';
-    policyTypePath = 'policytypes';
+    private apiVersion2 = 'v2'
+    private basePath = '';
+    policyTypesPath = 'policy-types';
     policyPath = 'policies';
 
     private buildPath(...args: any[]) {
-        let result = this.basePath;
+        let result = this.basePath + this.apiVersion2;
         args.forEach(part => {
             result = result + '/' + part;
         });
@@ -49,21 +50,14 @@ export class PolicyService {
         // injects to variable httpClient
     }
 
-    /**
-     * Gets version details
-     * @returns Observable that should yield a String
-     */
-    getVersion(): Observable<string> {
-        const url = this.buildPath('version');
-        return this.httpClient.get<ControlpanelSuccessTransport>(url).pipe(
-            // Extract the string here
-            map(res => res['data'])
-        );
+    getPolicyTypes(): Observable<PolicyTypes> {
+        const url = this.buildPath(this.policyTypesPath);
+        return this.httpClient.get<PolicyTypes>(url);
     }
 
-    getPolicyTypes(): Observable<PolicyType[]> {
-        const url = this.buildPath(this.policyTypePath);
-        return this.httpClient.get<PolicyType[]>(url);
+    getPolicyType(policyTypeId: string): Observable<PolicyType> {
+        const url = this.buildPath(this.policyTypesPath + '/' + policyTypeId);
+        return this.httpClient.get<PolicyType>(url);
     }
 
     getPolicyInstances(policyTypeId: string): Observable<PolicyInstance[]> {