Modified logic to handle Modify/Create/Delete Policy Instance 87/5587/1
authorLathish <lathishbabu.ganesan@est.tech>
Wed, 3 Feb 2021 16:12:13 +0000 (16:12 +0000)
committerLathish <lathishbabu.ganesan@est.tech>
Wed, 3 Feb 2021 16:38:50 +0000 (16:38 +0000)
Issue-ID: NONRTRIC-427
Change-Id: I583e4096ee3705e2fd0973f43a31582f769b5857
Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
webapp-frontend/src/app/interceptor.mock.ts
webapp-frontend/src/app/interfaces/policy.types.ts
webapp-frontend/src/app/policy-control/no-type-policy-instance-dialog.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/services/policy/policy.service.ts

index 66807d7..826d625 100644 (file)
@@ -130,7 +130,7 @@ const urls = [
 
 @Injectable()
 export class HttpMockRequestInterceptor implements HttpInterceptor {
-    constructor(private injector: Injector) {}
+    constructor(private injector: Injector) { }
 
     intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
         if (request.method === "PUT" && request.url.includes("policies")) {
@@ -140,6 +140,9 @@ export class HttpMockRequestInterceptor implements HttpInterceptor {
         for (const element of urls) {
             if (request.url === element.url) {
                 console.log('Loaded from stub json : ' + request.url);
+                if (request.method === 'DELETE') {
+                    return of(new HttpResponse({ status: 204 }));
+                }
                 return of(new HttpResponse({ status: 200, body: ((element.json) as any).default }));
             }
         }
index 9688a23..0c46ec4 100644 (file)
@@ -53,3 +53,11 @@ export interface PolicyInstanceAck {
   status: string;
   message: string;
 }
+
+export interface CreatePolicyInstance {
+  policy_data: any,
+  policy_id: string,
+  policytype_id: string,
+  ric_id: string,
+  service_id: string
+}
index 66dcfb7..6ebbbcc 100644 (file)
@@ -27,6 +27,7 @@ import { HttpErrorResponse } from '@angular/common/http';
 import { ErrorDialogService } from '../services/ui/error-dialog.service';
 import * as uuid from 'uuid';
 import { Ric } from '../interfaces/ric';
+import { CreatePolicyInstance } from '../interfaces/policy.types';
 
 @Component({
   selector: 'rd-no-type-policy-instance-dialog',
@@ -80,7 +81,8 @@ export class NoTypePolicyInstanceDialogComponent implements OnInit {
       this.policyInstanceId = uuid.v4();
     }
     const self: NoTypePolicyInstanceDialogComponent = this;
-    this.policySvc.putPolicy('', this.policyInstanceId, this.policyJsonTextArea.value, this.ric).subscribe(
+    let createPolicyInstance = this.createPolicyInstance(this.policyJsonTextArea.value);
+    this.policySvc.putPolicy(createPolicyInstance).subscribe(
       {
         next(_) {
           self.notificationService.success('Policy without type:' + self.policyInstanceId + ' submitted');
@@ -92,11 +94,21 @@ export class NoTypePolicyInstanceDialogComponent implements OnInit {
       });
   }
 
+  private createPolicyInstance(policyJson: string) {
+    let createPolicyInstance = {} as CreatePolicyInstance;
+    createPolicyInstance.policy_data = JSON.parse(policyJson);
+    createPolicyInstance.policy_id = this.policyInstanceId;
+    createPolicyInstance.policytype_id = '';
+    createPolicyInstance.ric_id = (!this.ricSelector.value.ric_id) ? this.ric : this.ricSelector.value.ric_id;
+    createPolicyInstance.service_id = 'controlpanel';
+    return createPolicyInstance;
+  }
+
   private fetchRics() {
     const self: NoTypePolicyInstanceDialogComponent = this;
     this.policySvc.getRics('').subscribe(
       {
-        next(value:Ric[]) {
+        next(value: Ric[]) {
           self.allRics = value;
           console.log(value);
         },
index bd4de27..72a2041 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, PolicyTypeSchema } from '../interfaces/policy.types';
+import { CreatePolicyInstance, 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';
@@ -93,7 +93,7 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
         const self: PolicyInstanceDialogComponent = this;
         this.dataService.getRics(this.policyTypeName).subscribe(
             {
-                next(value:Ric[]) {
+                next(value: Ric[]) {
                     self.allRics = value;
                     console.log(value);
                 },
@@ -148,7 +148,8 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
         }
         const policyJson: string = this.prettyLiveFormData;
         const self: PolicyInstanceDialogComponent = this;
-        this.dataService.putPolicy(this.policyTypeName, this.policyInstanceId, policyJson, this.ric).subscribe(
+        let createPolicyInstance = this.createPolicyInstance(policyJson);
+        this.dataService.putPolicy(createPolicyInstance).subscribe(
             {
                 next(_) {
                     self.notificationService.success('Policy ' + self.policyTypeName + ':' + self.policyInstanceId +
@@ -161,6 +162,16 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
             });
     }
 
+    private createPolicyInstance(policyJson: string) {
+        let createPolicyInstance = {} as CreatePolicyInstance;
+        createPolicyInstance.policy_data = JSON.parse(policyJson);
+        createPolicyInstance.policy_id = this.policyInstanceId;
+        createPolicyInstance.policytype_id = this.policyTypeName;
+        createPolicyInstance.ric_id = (!this.ricSelector.value.ric_id) ? this.ric : this.ricSelector.value.ric_id;
+        createPolicyInstance.service_id = 'controlpanel';
+        return createPolicyInstance;
+    }
+
     onClose() {
         this.dialogRef.close();
     }
index b8861d6..eb6bea8 100644 (file)
@@ -126,11 +126,11 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit {
             .afterClosed().subscribe(
                 (res: any) => {
                     if (res) {
-                        this.policySvc.deletePolicy(this.policyTypeSchema.name, instance.policy_id)
+                        this.policySvc.deletePolicy(instance.policy_id)
                             .subscribe(
                                 (response: HttpResponse<Object>) => {
                                     switch (response.status) {
-                                        case 200:
+                                        case 204:
                                             this.notificationService.success('Delete succeeded!');
                                             this.instanceDataSource.getPolicyInstances();
                                             break;
index 15ab710..5ffff13 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 { PolicyInstance, PolicyInstanceAck, PolicyInstances, PolicyStatus, PolicyType, PolicyTypes } from '../../interfaces/policy.types';
+import { CreatePolicyInstance, PolicyInstance, PolicyInstanceAck, PolicyInstances, PolicyStatus, PolicyType, PolicyTypes } from '../../interfaces/policy.types';
 import { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.types';
 import { Ric } from 'src/app/interfaces/ric';
 
@@ -92,9 +92,9 @@ export class PolicyService {
      * @param policyJson Json with the policy content
      * @returns Observable that should yield a response code, no data
      */
-    putPolicy(policyTypeId: string, policyInstanceId: string, policyJson: string, ric: string): Observable<any> {
-        const url = this.buildPath(this.policyPath, policyInstanceId) + '?ric=' + ric + '&type=' + policyTypeId;
-        return this.httpClient.put<PolicyInstanceAck>(url, policyJson, { observe: 'response' });
+    putPolicy(createPolicyInstance: CreatePolicyInstance): Observable<any> {
+        const url = this.buildPath(this.policyPath);
+        return this.httpClient.put<PolicyInstanceAck>(url, createPolicyInstance, { observe: 'response' });
     }
 
     /**
@@ -103,8 +103,8 @@ export class PolicyService {
      * @param policyInstanceId ID of the instance
      * @returns Observable that should yield a response code, no data
      */
-    deletePolicy(policyTypeId: string, policyInstanceId: string): Observable<any> {
-        const url = this.buildPath(this.policyPath, policyInstanceId) + '?type=' + policyTypeId;
+    deletePolicy(policyInstanceId: string): Observable<any> {
+        const url = this.buildPath(this.policyPath, policyInstanceId);
         return this.httpClient.delete(url, { observe: 'response' });
     }