Merge "Fix groupId for nonrtric-controlpanel-gateway"
authorPatrik Buhr <patrik.buhr@est.tech>
Wed, 3 Feb 2021 14:05:26 +0000 (14:05 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Wed, 3 Feb 2021 14:05:26 +0000 (14:05 +0000)
12 files changed:
webapp-frontend/src/app/interceptor.mock.ts
webapp-frontend/src/app/interfaces/ric.ts [new file with mode: 0644]
webapp-frontend/src/app/mock/ric1.json [new file with mode: 0644]
webapp-frontend/src/app/mock/ric2.json [new file with mode: 0644]
webapp-frontend/src/app/policy-control/no-type-policy-instance-dialog.component.html
webapp-frontend/src/app/policy-control/no-type-policy-instance-dialog.component.ts
webapp-frontend/src/app/policy-control/policy-control.component.ts
webapp-frontend/src/app/policy-control/policy-instance-dialog.component.html
webapp-frontend/src/app/policy-control/policy-instance-dialog.component.ts
webapp-frontend/src/app/policy-control/policy-type.datasource.spec.ts [new file with mode: 0644]
webapp-frontend/src/app/policy-control/policy-type.datasource.ts
webapp-frontend/src/app/services/policy/policy.service.ts

index 8a1c3ab..05e1a4e 100644 (file)
@@ -33,6 +33,8 @@ 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';
+import * as ric1 from './mock/ric1.json';
+import * as ric2 from './mock/ric2.json';
 
 const urls = [
     {
@@ -91,6 +93,14 @@ const urls = [
         url: '/a1-policy/v2/policies/2000?ric=ric1&type=1',
         json: ''
     },
+    {
+        url: '/a1-policy/v2/rics?policytype_id=1',
+        json: ric1
+    },
+    {
+        url: '/a1-policy/v2/rics?policytype_id=',
+        json: ric2
+    },
     {
         url: 'api/enrichment/eijobs',
         json: eijobs
diff --git a/webapp-frontend/src/app/interfaces/ric.ts b/webapp-frontend/src/app/interfaces/ric.ts
new file mode 100644 (file)
index 0000000..7c115af
--- /dev/null
@@ -0,0 +1,28 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2021 Nordix Foundation
+ * %%
+ * 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===================================
+ */
+
+// Models of data used by the Policy Control
+
+export interface Ric {
+  ric_id: string;
+  managed_element_ids: any[];
+  policytype_ids: any[];
+  state: string;
+}
diff --git a/webapp-frontend/src/app/mock/ric1.json b/webapp-frontend/src/app/mock/ric1.json
new file mode 100644 (file)
index 0000000..de92d04
--- /dev/null
@@ -0,0 +1,15 @@
+{
+    "rics": [
+        {
+            "ric_id": "ric1",
+            "managed_element_ids": [
+                "kista_1",
+                "kista_2"
+            ],
+            "policytype_ids": [
+                "1"
+            ],
+            "state": "AVAILABLE"
+        }
+    ]
+}
\ No newline at end of file
diff --git a/webapp-frontend/src/app/mock/ric2.json b/webapp-frontend/src/app/mock/ric2.json
new file mode 100644 (file)
index 0000000..f6e36e8
--- /dev/null
@@ -0,0 +1,15 @@
+{
+    "rics": [
+        {
+            "ric_id": "ric2",
+            "managed_element_ids": [
+                "kista_1",
+                "kista_2"
+            ],
+            "policytype_ids": [
+                ""
+            ],
+            "state": "AVAILABLE"
+        }
+    ]
+}
\ No newline at end of file
index da8ab5b..81df840 100644 (file)
@@ -41,8 +41,8 @@
             <mat-select id="ricSelector" formControlName="ricSelector" matInput required [(value)]="this.ric"
                 placeholder="Target"
                 matTooltip="Element where the policy instance resides, e.g. a gNodeB or Near-RT RIC">
-                <mat-option *ngFor="let ric of this.allRics" [value]="ric">
-                    {{ric}}
+                <mat-option *ngFor="let ric of this.allRics.rics" [value]="ric">
+                    {{ric.ric_id}}
                 </mat-option>
             </mat-select>
             <div *ngIf="ricSelector.invalid && (ricSelector.dirty || ricSelector.touched)" class="alert mat-error"
index 976a4e4..66dcfb7 100644 (file)
@@ -26,6 +26,7 @@ import { UiService } from '../services/ui/ui.service';
 import { HttpErrorResponse } from '@angular/common/http';
 import { ErrorDialogService } from '../services/ui/error-dialog.service';
 import * as uuid from 'uuid';
+import { Ric } from '../interfaces/ric';
 
 @Component({
   selector: 'rd-no-type-policy-instance-dialog',
@@ -39,7 +40,7 @@ export class NoTypePolicyInstanceDialogComponent implements OnInit {
   policyJson: string;
   darkMode: boolean;
   ric: string;
-  allRics: string[];
+  allRics: Ric[];
 
   constructor(
     private policySvc: PolicyService,
@@ -95,7 +96,7 @@ export class NoTypePolicyInstanceDialogComponent implements OnInit {
     const self: NoTypePolicyInstanceDialogComponent = this;
     this.policySvc.getRics('').subscribe(
       {
-        next(value) {
+        next(value:Ric[]) {
           self.allRics = value;
           console.log(value);
         },
index 3a15226..ad3f13d 100644 (file)
@@ -89,7 +89,7 @@ export class PolicyControlComponent implements OnInit {
     }
 
     private isSchemaEmpty(policyTypeSchema: PolicyTypeSchema): boolean {
-        return Object.keys(policyTypeSchema.schemaObject).length === 0;
+        return policyTypeSchema.schemaObject === '{}';
     }
 
     getPolicyTypeInfo(policyTypeSchema: PolicyTypeSchema): PolicyTypeInfo {
index fdf80cb..fea3e84 100644 (file)
@@ -44,8 +44,8 @@
             <mat-select id="ricSelector" formControlName="ricSelector" matInput required [(value)]="this.ric"
                 placeholder="Target"
                 matTooltip="Element where the policy instance resides, e.g. a gNodeB or Near-RT RIC">
-                <mat-option *ngFor="let ric of this.allRics" [value]="ric">
-                    {{ric}}
+                <mat-option *ngFor="let ric of this.allRics.rics" [value]="ric">
+                    {{ric.ric_id}}
                 </mat-option>
             </mat-select>
             <div *ngIf="ricSelector.invalid && (ricSelector.dirty || ricSelector.touched)">
index 47c95b9..bd4de27 100644 (file)
@@ -31,6 +31,7 @@ import { UiService } from '../services/ui/ui.service';
 import { HttpErrorResponse } from '@angular/common/http';
 import { FormGroup, FormControl, Validators } from '@angular/forms';
 import { ChangeDetectorRef } from '@angular/core';
+import { Ric } from '../interfaces/ric';
 
 
 @Component({
@@ -85,14 +86,14 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
     policyTypeName: string;
     darkMode: boolean;
     ric: string;
-    allRics: string[];
+    allRics: Ric[];
 
     private fetchRics() {
         console.log('fetchRics ' + this.policyTypeName);
         const self: PolicyInstanceDialogComponent = this;
         this.dataService.getRics(this.policyTypeName).subscribe(
             {
-                next(value) {
+                next(value:Ric[]) {
                     self.allRics = value;
                     console.log(value);
                 },
diff --git a/webapp-frontend/src/app/policy-control/policy-type.datasource.spec.ts b/webapp-frontend/src/app/policy-control/policy-type.datasource.spec.ts
new file mode 100644 (file)
index 0000000..5b83368
--- /dev/null
@@ -0,0 +1,86 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2021 Nordix Foundation
+ * %%
+ * 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 { BehaviorSubject, of } from 'rxjs';
+import { NotificationService } from '../services/ui/notification.service';
+import { ToastrModule } from 'ngx-toastr';
+import { PolicyTypeDataSource } from './policy-type.datasource';
+import { PolicyService } from '../services/policy/policy.service';
+import { PolicyTypeSchema } from '../interfaces/policy.types';
+
+describe('PolicyTypeDataSource', () => {
+  let policyTypeDataSource: PolicyTypeDataSource;
+  let policyServiceSpy: any;
+
+  let policySchema = {
+    policy_schema: {
+      "$schema": "http://json-schema.org/draft-07/schema#",
+      "description": "Type 1 policy type",
+      "additionalProperties": false,
+      "title": "1",
+      "type": "object"
+    }
+  };
+
+  beforeEach(() => {
+    policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getPolicyTypes', 'getPolicyType']);
+
+    policyServiceSpy.getPolicyTypes.and.returnValue(of({ policytype_ids: ['1', '2'] }));
+    policyServiceSpy.getPolicyType.and.returnValue(of(policySchema));
+    TestBed.configureTestingModule({
+      imports: [ToastrModule.forRoot()],
+      providers: [
+        { provide: PolicyService, useValue: policyServiceSpy },
+        NotificationService
+      ]
+    });
+  });
+
+  describe('#getPolicyTypes', () => {
+    let expectedPolicyTypeValue: PolicyTypeSchema[];
+    beforeEach(() => {
+      expectedPolicyTypeValue = [
+        {
+          'id': '1',
+          'name': '1',
+          'schemaObject': policySchema.policy_schema
+        },
+        {
+          'id': '2',
+          'name': '1',
+          'schemaObject': policySchema.policy_schema
+        }
+      ];
+    });
+
+    it('should create', () => {
+      policyTypeDataSource = TestBed.get(PolicyTypeDataSource);
+      expect(policyTypeDataSource).toBeTruthy();
+    });
+
+    it('should return all policy type with Schema', () => {
+      policyTypeDataSource.getPolicyTypes();
+      const jobsSubject: BehaviorSubject<PolicyTypeSchema[]> = policyTypeDataSource.policyTypeSubject;
+      const value = jobsSubject.getValue();
+      expect(value).toEqual(expectedPolicyTypeValue);
+    });
+  });
+});
\ No newline at end of file
index 2fed8f3..2e10f55 100644 (file)
  * ========================LICENSE_END===================================
  */
 
+import { HttpErrorResponse } from '@angular/common/http';
 import { CollectionViewer, DataSource } from '@angular/cdk/collections';
 import { Injectable } from '@angular/core';
 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
 import { of } from 'rxjs/observable/of';
 import { Observable } from 'rxjs/Observable';
+import { catchError, finalize, map } from 'rxjs/operators';
 
-import { PolicyTypeSchema } from '../interfaces/policy.types';
+import { PolicyType, PolicyTypes, PolicyTypeSchema } from '../interfaces/policy.types';
 import { PolicyService } from '../services/policy/policy.service';
 import { NotificationService } from '../services/ui/notification.service';
 
@@ -36,39 +38,58 @@ export class PolicyTypeDataSource extends DataSource<PolicyTypeSchema> {
 
     policyTypes: PolicyTypeSchema[] = [];
 
-    private policyTypeSubject = new BehaviorSubject<PolicyTypeSchema[]>([]);
+    policyTypeSubject = new BehaviorSubject<PolicyTypeSchema[]>([]);
+
+    private loadingSubject = new BehaviorSubject<boolean>(false);
 
     public rowCount = 1; // hide footer during intial load
 
-    constructor(private policySvc: PolicyService,
+    constructor(public policySvc: PolicyService,
         private notificationService: NotificationService) {
         super();
     }
 
     public getPolicyTypes() {
         this.policyTypes = [] as PolicyTypeSchema[];
-        this.policySvc.getPolicyTypes().subscribe(policyType => {
-            if (policyType.policytype_ids.length != 0) {
-                policyType.policytype_ids.forEach(policyTypeId => {
-                    var policyTypeSchema = {} as PolicyTypeSchema
-                    if (policyTypeId === "") {
-                        policyTypeSchema.id = '';
-                        policyTypeSchema.name = '';
-                        policyTypeSchema.schemaObject = '{}';
-                        this.policyTypes.push(policyTypeSchema);
-                    }
-                    else {
-                        this.policySvc.getPolicyType(policyTypeId).subscribe(policyType => {
-                            policyTypeSchema.id = policyTypeId;
-                            policyTypeSchema.schemaObject = policyType.policy_schema;
-                            policyTypeSchema.name = policyType.policy_schema.title;
+        this.policySvc.getPolicyTypes()
+            .pipe(
+                catchError((httpError: HttpErrorResponse) => {
+                    this.notificationService.error('Failed to get policy types: ' + httpError.error);
+                    return of([]);
+                }),
+                finalize(() => this.loadingSubject.next(false))
+            )
+            .subscribe((policyType: PolicyTypes) => {
+                this.rowCount = policyType.policytype_ids.length;
+                if (policyType.policytype_ids.length != 0) {
+                    policyType.policytype_ids.forEach(policyTypeId => {
+                        var policyTypeSchema = {} as PolicyTypeSchema
+                        if (policyTypeId === "") {
+                            policyTypeSchema.id = '';
+                            policyTypeSchema.name = '';
+                            policyTypeSchema.schemaObject = '{}';
                             this.policyTypes.push(policyTypeSchema);
-                        })
-                    }
-                    this.policyTypeSubject.next(this.policyTypes);
-                })
-            }
-        })
+                        }
+                        else {
+                            this.policySvc.getPolicyType(policyTypeId)
+                                .pipe(
+                                    catchError((httpError: HttpErrorResponse) => {
+                                        this.notificationService.error('Failed to get policy type: ' + httpError.error);
+                                        return of([]);
+                                    }),
+                                    finalize(() => this.loadingSubject.next(false))
+                                )
+                                .subscribe((policyType: PolicyType) => {
+                                    policyTypeSchema.id = policyTypeId;
+                                    policyTypeSchema.schemaObject = policyType.policy_schema;
+                                    policyTypeSchema.name = policyType.policy_schema.title;
+                                    this.policyTypes.push(policyTypeSchema);
+                                })
+                        }
+                        this.policyTypeSubject.next(this.policyTypes);
+                    })
+                }
+            })
     }
 
     connect(collectionViewer: CollectionViewer): Observable<PolicyTypeSchema[]> {
index 50c5449..15ab710 100644 (file)
@@ -24,6 +24,7 @@ import { Observable } from 'rxjs';
 import { map } from 'rxjs/operators';
 import { PolicyInstance, PolicyInstanceAck, PolicyInstances, PolicyStatus, PolicyType, PolicyTypes } from '../../interfaces/policy.types';
 import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.types';
+import { Ric } from 'src/app/interfaces/ric';
 
 /**
  * Services for calling the policy endpoints.
@@ -108,8 +109,8 @@ export class PolicyService {
     }
 
 
-    getRics(policyTypeId: string): Observable<string[]> {
-        const url = this.buildPath('rics') + '?policyType=' + policyTypeId;
+    getRics(policyTypeId: string): Observable<Ric[]> {
+        const url = this.buildPath('rics') + '?policytype_id=' + policyTypeId;
         return this.httpClient.get<any>(url);
     }
 }