Update UI to define Pdp Group
[clamp.git] / ui-react / src / api / LoopCache.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 export default class LoopCache {
25         loopJsonCache;
26
27         constructor(loopJson) {
28                 this.loopJsonCache=loopJson;
29         }
30
31         updateMicroServiceProperties(name, newMsProperties) {
32                         for (var policy in this.loopJsonCache["microServicePolicies"]) {
33                                 if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) {
34                                         this.loopJsonCache["microServicePolicies"][policy]["configurationsJson"] = newMsProperties;
35                                 }
36                         }
37         }
38
39         updateMicroServicePdpGroup(name, pdpGroup, pdpSubgroup) {
40                         for (var policy in this.loopJsonCache["microServicePolicies"]) {
41                                 if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) {
42                                         this.loopJsonCache["microServicePolicies"][policy]["pdpGroup"] = pdpGroup;
43                                         this.loopJsonCache["microServicePolicies"][policy]["pdpSubgroup"] = pdpSubgroup;
44                                 }
45                         }
46         }
47
48         updateGlobalProperties(newGlobalProperties) {
49                 this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties;
50         }
51
52         updateOperationalPolicyProperties(name, newOpProperties) {
53                 for (var policy in this.loopJsonCache["operationalPolicies"]) {
54                                 if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) {
55                                         this.loopJsonCache["operationalPolicies"][policy]["configurationsJson"] = newOpProperties;
56                                 }
57                         }
58         }
59
60         updateOperationalPolicyPdpGroup(name, pdpGroup, pdpSubgroup) {
61                 for (var policy in this.loopJsonCache["operationalPolicies"]) {
62                         if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) {
63                                 this.loopJsonCache["operationalPolicies"][policy]["pdpGroup"] = pdpGroup;
64                                 this.loopJsonCache["operationalPolicies"][policy]["pdpSubgroup"] = pdpSubgroup;
65                         }
66                 }
67         }
68
69         getLoopName() {
70                 return this.loopJsonCache["name"];
71         }
72
73         getOperationalPolicyConfigurationJson() {
74                 return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"];
75         }
76
77         getOperationalPolicyJsonSchema() {
78                 return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"];
79         }
80
81         getOperationalPolicies() {
82                 return this.loopJsonCache["operationalPolicies"];
83         }
84
85         getOperationalPoliciesNoJsonSchema() {
86                 var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]));
87                 delete operationalPolicies[0]["jsonRepresentation"];
88                 return operationalPolicies;
89         }
90
91         getGlobalProperties() {
92                 return this.loopJsonCache["globalPropertiesJson"];
93         }
94
95         getDcaeDeploymentProperties() {
96                 return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"];
97         }
98
99         getMicroServicePolicies() {
100                 return this.loopJsonCache["microServicePolicies"];
101         }
102
103         getOperationalPolicyForName(name) {
104                 var opProperties=this.getOperationalPolicies();
105                 for (var policy in opProperties) {
106                         if (opProperties[policy]["name"] === name) {
107                                 return opProperties[policy];
108                         }
109                 }
110                 return null;
111         }
112
113         getOperationalPolicyPropertiesForName(name) {
114                 var opConfig = this.getOperationalPolicyForName(name);
115                 if (opConfig !== null) {
116                         return opConfig["configurationsJson"];
117                 }
118                 return null;
119         }
120
121         getOperationalPolicyJsonRepresentationForName(name) {
122                 var opConfig = this.getOperationalPolicyForName(name);
123                 if (opConfig !== null) {
124                         return opConfig["jsonRepresentation"];
125                 }
126                 return null;
127         }
128
129         getOperationalPolicySupportedPdpgroup(name) {
130                 var opConfig=this.getOperationalPolicyForName(name);
131                 if (opConfig !== null) {
132                         return opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
133                 }
134                 return null;
135         }
136
137         getOperationalPolicyPdpGroup(name) {
138                 var opConfig=this.getOperationalPolicyForName(name);
139                 if (opConfig !== null) {
140                         return opConfig["pdpGroup"];
141                 }
142                 return null;
143         }
144
145         getOperationalPolicyPdpSubgroup(name) {
146                 var opConfig=this.getOperationalPolicyForName(name);
147                 if (opConfig !== null) {
148                         return opConfig["pdpSubgroup"];
149                 }
150                 return null;
151         }
152
153         getMicroServiceSupportedPdpgroup(name) {
154                 var microService=this.getMicroServiceForName(name);
155                 if (microService !== null) {
156                         return microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
157                 }
158                 return null;
159         }
160
161         getMicroServicePdpGroup(name) {
162                 var microService=this.getMicroServiceForName(name);
163                 if (microService !== null) {
164                         return microService["pdpGroup"];
165                 }
166                 return null;
167         }
168
169         getMicroServicePdpSubgroup(name) {
170                 var microService=this.getMicroServiceForName(name);
171                 if (microService !== null) {
172                         return microService["pdpSubgroup"];
173                 }
174                 return null;
175         }
176
177         getMicroServiceForName(name) {
178                 var msProperties=this.getMicroServicePolicies();
179                 for (var policy in msProperties) {
180                         if (msProperties[policy]["name"] === name) {
181                                 return msProperties[policy];
182                         }
183                 }
184                 return null;
185         }
186
187         getMicroServicePropertiesForName(name) {
188                 var msConfig = this.getMicroServiceForName(name);
189                 if (msConfig !== null) {
190                         return msConfig["configurationsJson"];
191                 }
192                 return null;
193         }
194
195         getMicroServiceJsonRepresentationForName(name) {
196                 var msConfig = this.getMicroServiceForName(name);
197                 if (msConfig !== null) {
198                         return msConfig["jsonRepresentation"];
199                 }
200                 return null;
201         }
202
203         getResourceDetailsVfProperty() {
204                 return this.loopJsonCache["modelService"]["resourceDetails"]["VF"];
205         }
206
207         getResourceDetailsVfModuleProperty() {
208                 return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"];
209         }
210
211         getLoopLogsArray() {
212                 return this.loopJsonCache.loopLogs;
213         }
214
215         getComputedState() {
216                 return this.loopJsonCache.lastComputedState;
217         }
218
219         getComponentStates() {
220                 return this.loopJsonCache.components;
221         }
222 }