@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")) {
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 }));
}
}
status: string;
message: string;
}
+
+export interface CreatePolicyInstance {
+ policy_data: any,
+ policy_id: string,
+ policytype_id: string,
+ ric_id: string,
+ service_id: string
+}
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',
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');
});
}
+ 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);
},
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';
const self: PolicyInstanceDialogComponent = this;
this.dataService.getRics(this.policyTypeName).subscribe(
{
- next(value:Ric[]) {
+ next(value: Ric[]) {
self.allRics = value;
console.log(value);
},
}
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 +
});
}
+ 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();
}
.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;
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';
* @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' });
}
/**
* @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' });
}