X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fservices%2Fpolicy%2Fpolicy.service.ts;h=028caa07e6836aa519dbbb7ed27e45a5a1371e1d;hb=refs%2Fchanges%2F71%2F6071%2F2;hp=f24747b79673d57c3689ad32a250a9bfa5bd051e;hpb=3b19af38b08cd6838cf58fbc03064e4a6fc091eb;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/services/policy/policy.service.ts b/webapp-frontend/src/app/services/policy/policy.service.ts index f24747b..028caa0 100644 --- a/webapp-frontend/src/app/services/policy/policy.service.ts +++ b/webapp-frontend/src/app/services/policy/policy.service.ts @@ -18,94 +18,114 @@ * ========================LICENSE_END=================================== */ -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 { ControlpanelSuccessTransport } from '../../interfaces/controlpanel.types'; +import { Injectable } from "@angular/core"; +import { HttpClient } from "@angular/common/http"; +import { Observable } from "rxjs"; +import { + CreatePolicyInstance, + PolicyInstance, + PolicyInstanceAck, + PolicyInstances, + PolicyStatus, + PolicyType, + PolicyTypes, +} from "@interfaces/policy.types"; +import { Rics } from "@interfaces/ric"; +import { RicConfig } from "@interfaces/ric.config"; +import { HttpHeaders } from "@angular/common/http"; /** * Services for calling the policy endpoints. */ @Injectable({ - providedIn: 'root' + providedIn: "root", }) export class PolicyService { + private apiVersion2 = "/v2"; + private basePath = "/a1-policy"; + policyTypesPath = "policy-types"; + policyPath = "policies"; - private basePath = 'api/policy'; - policyTypePath = 'policytypes'; - policyPath = 'policies'; + private buildPath(...args: any[]) { + let result = this.basePath + this.apiVersion2; + args.forEach((part) => { + result = result + "/" + part; + }); + return result; + } - private buildPath(...args: any[]) { - let result = this.basePath; - args.forEach(part => { - result = result + '/' + part; - }); - return result; - } + constructor(private httpClient: HttpClient) { + // injects to variable httpClient + } - constructor(private httpClient: HttpClient) { - // injects to variable httpClient - } + getPolicyTypes(): Observable { + const url = this.buildPath(this.policyTypesPath); + return this.httpClient.get(url); + } - /** - * Gets version details - * @returns Observable that should yield a String - */ - getVersion(): Observable { - const url = this.buildPath('version'); - return this.httpClient.get(url).pipe( - // Extract the string here - map(res => res['data']) - ); - } + getPolicyType(policyTypeId: string): Observable { + const url = this.buildPath(this.policyTypesPath + "/" + policyTypeId); + return this.httpClient.get(url); + } - getPolicyTypes(): Observable { - const url = this.buildPath(this.policyTypePath); - return this.httpClient.get(url); - } + getPolicyInstancesByType(policyTypeId: string): Observable { + const url = this.buildPath( + this.policyPath + "?" + "policytype_id=" + policyTypeId + ); + return this.httpClient.get(url); + } - getPolicyInstances(policyTypeId: string): Observable { - const url = this.buildPath(this.policyPath) + '?type=' + policyTypeId; - return this.httpClient.get(url); - } + getPolicyInstance(policyId: string): Observable { + const url = this.buildPath(this.policyPath) + "/" + policyId; + return this.httpClient.get(url); + } - /** - * Gets policy parameters. - * @returns Observable that should yield a policy instance - */ - getPolicy(policyTypeId: string, policyInstanceId: string): Observable { - const url = this.buildPath(this.policyPath, policyInstanceId) + '?type=' + policyTypeId; - return this.httpClient.get(url); - } + getPolicyStatus(policyId: string): Observable { + const url = this.buildPath(this.policyPath) + "/" + policyId + "/status"; + return this.httpClient.get(url); + } - /** - * Creates or replaces policy instance. - * @param policyTypeId ID of the policy type that the instance will have - * @param policyInstanceId ID of the instance - * @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 { - const url = this.buildPath(this.policyPath, policyInstanceId) + '?ric=' + ric + '&type=' + policyTypeId; - return this.httpClient.put(url, policyJson, { observe: 'response' }); - } + /** + * Creates or replaces policy instance. + * @param policyTypeId ID of the policy type that the instance will have + * @param policyInstanceId ID of the instance + * @param policyJson Json with the policy content + * @returns Observable that should yield a response code, no data + */ + putPolicy(createPolicyInstance: CreatePolicyInstance): Observable { + const url = this.buildPath(this.policyPath); + return this.httpClient.put(url, createPolicyInstance, { + observe: "response", + }); + } - /** - * Deletes a policy instance. - * @param policyTypeId ID of the policy type that the instance belong to - * @param policyInstanceId ID of the instance - * @returns Observable that should yield a response code, no data - */ - deletePolicy(policyTypeId: string, policyInstanceId: string): Observable { - const url = this.buildPath(this.policyPath, policyInstanceId) + '?type=' + policyTypeId; - return this.httpClient.delete(url, { observe: 'response' }); - } + /** + * Deletes a policy instance. + * @param policyTypeId ID of the policy type that the instance belong to + * @param policyInstanceId ID of the instance + * @returns Observable that should yield a response code, no data + */ + deletePolicy(policyInstanceId: string): Observable { + const url = this.buildPath(this.policyPath, policyInstanceId); + return this.httpClient.delete(url, { observe: "response" }); + } + + getRics(policyTypeId: string): Observable { + const url = this.buildPath("rics") + "?policytype_id=" + policyTypeId; + return this.httpClient.get(url); + } + getConfiguration(): Observable { + const url = this.buildPath("configuration"); + return this.httpClient.get(url); + } - getRics(policyTypeId: string): Observable { - const url = this.buildPath('rics') + '?policyType=' + policyTypeId; - return this.httpClient.get(url); + updateConfiguration(ricConfig: RicConfig): Observable { + const httpOptions = { + headers: new HttpHeaders({'Content-Type': 'application/json'}), + observe: 'response' as 'body' } + const url = this.buildPath("configuration"); + return this.httpClient.put(url, ricConfig, httpOptions); + } }