Move Enrichment Job Logic from backend
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / interceptor.mock.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2021 Nordix Foundation
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';
22 import { Injectable, Injector } from '@angular/core';
23 import { Observable, of } from 'rxjs';
24 import * as policyinstances1 from './mock/policy-instance-1.json';
25 import * as policies from './mock/policies.json';
26 import * as policyinstances2 from './mock/policy-instance-2.json';
27 import * as policyinstances1Status from './mock/policy-instance-1-status.json';
28 import * as policyinstances2Status from './mock/policy-instance-2-status.json';
29 import * as eijobsProd1 from './mock/ei-jobs-producer1.json';
30 import * as eijobsProd2 from './mock/ei-jobs-producer2.json';
31 import * as eiProducerIds from './mock/ei-producerids.json';
32 import * as eiproducers from './mock/ei-producers.json';
33 import * as policytypesList from './mock/policy-types.json';
34 import * as policytypes1 from './mock/policy-type1.json';
35 import * as policyinstanceedit from './mock/policy-instance-edit.json';
36 import * as rics from './mock/rics.json';
37 import * as ric1 from './mock/ric1.json';
38 import * as ric2 from './mock/ric2.json';
39
40 const urls = [
41     {
42         url: '/a1-policy/v2/policy-types',
43         json: policytypesList
44     },
45     {
46         url: '/a1-policy/v2/policy-types/',
47         json: policytypes1
48     },
49     {
50         url: '/a1-policy/v2/policy-types/1',
51         json: policytypes1
52     },
53     {
54         url: '/a1-policy/v2/policies?policytype_id=',
55         json: policies
56     },
57     {
58         url: '/a1-policy/v2/policies?policytype_id=1',
59         json: policies
60     },
61     {
62         url: '/a1-policy/v2/policies/2000',
63         json: policyinstances1
64     },
65     {
66         url: '/a1-policy/v2/policies/2100',
67         json: policyinstances2
68     },
69     {
70         url: '/a1-policy/v2/policies/2000/status',
71         json: policyinstances1Status
72     },
73     {
74         url: '/a1-policy/v2/policies/2100/status',
75         json: policyinstances2Status
76     },
77     {
78         url: '/a1-policy/v2/policies/2000?type=',
79         json: policyinstanceedit
80     },
81     {
82         url: '/a1-policy/v2/policies/2100?type=',
83         json: policyinstanceedit
84     },
85     {
86         url: '/a1-policy/v2/policies/2000?type=1',
87         json: policyinstanceedit
88     },
89     {
90         url: '/a1-policy/v2/policies/2100?type=1',
91         json: policyinstanceedit
92     },
93     {
94         url: '/a1-policy/v2/policies/2000?ric=ric1&type=1',
95         json: ''
96     },
97     {
98         url: '/a1-policy/v2/rics?policytype_id=1',
99         json: ric1
100     },
101     {
102         url: '/a1-policy/v2/rics?policytype_id=',
103         json: ric2
104     },
105     {
106         url: 'api/enrichment/eiproducers',
107         json: eiproducers
108     },
109     {
110         url: 'api/policy/rics?policyType=1',
111         json: rics
112     },
113     {
114         url: 'api/policy/rics?policyType=2',
115         json: rics
116     },
117     {
118         url: '/ei-producer/v1/eiproducers',
119         json: eiProducerIds
120     },
121     {
122         url: '/ei-producer/v1/eiproducers/producer1/eijobs',
123         json: eijobsProd1
124     },
125     {
126         url: '/ei-producer/v1/eiproducers/producer2/eijobs',
127         json: eijobsProd2
128     }
129 ];
130
131 @Injectable()
132 export class HttpMockRequestInterceptor implements HttpInterceptor {
133     constructor(private injector: Injector) {}
134
135     intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
136         if (request.method === "PUT" && request.url.includes("policies")) {
137             console.log('Answered PUT policy ' + request.url);
138             return of(new HttpResponse({ status: 200 }));
139         }
140         for (const element of urls) {
141             if (request.url === element.url) {
142                 console.log('Loaded from stub json : ' + request.url);
143                 return of(new HttpResponse({ status: 200, body: ((element.json) as any).default }));
144             }
145         }
146         console.log('Loaded from mock http call :' + request.url);
147         return next.handle(request);
148     }
149 }