5eaa79a64584a5ca17861f0ff766dd61011da435
[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                     if (opConfig["policyModel"]["policyPdpGroup"] !== undefined && opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) {
133                             return opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
134                         }
135                 }
136                 return [];
137         }
138
139         getOperationalPolicyPdpGroup(name) {
140                 var opConfig=this.getOperationalPolicyForName(name);
141                 if (opConfig !== null) {
142                         return opConfig["pdpGroup"];
143                 }
144                 return null;
145         }
146
147         getOperationalPolicyPdpSubgroup(name) {
148                 var opConfig=this.getOperationalPolicyForName(name);
149                 if (opConfig !== null) {
150                         return opConfig["pdpSubgroup"];
151                 }
152                 return null;
153         }
154
155         getMicroServiceSupportedPdpGroup(name) {
156                 var microService=this.getMicroServiceForName(name);
157                 if (microService !== null) {
158                     if (microService["policyModel"]["policyPdpGroup"] !== undefined && microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) {
159                             return microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
160                         }
161                 }
162                 return [];
163         }
164
165         getMicroServicePdpGroup(name) {
166                 var microService=this.getMicroServiceForName(name);
167                 if (microService !== null) {
168                         return microService["pdpGroup"];
169                 }
170                 return null;
171         }
172
173         getMicroServicePdpSubgroup(name) {
174                 var microService=this.getMicroServiceForName(name);
175                 if (microService !== null) {
176                         return microService["pdpSubgroup"];
177                 }
178                 return null;
179         }
180
181         getMicroServiceForName(name) {
182                 var msProperties=this.getMicroServicePolicies();
183                 for (var policy in msProperties) {
184                         if (msProperties[policy]["name"] === name) {
185                                 return msProperties[policy];
186                         }
187                 }
188                 return null;
189         }
190
191         getMicroServicePropertiesForName(name) {
192                 var msConfig = this.getMicroServiceForName(name);
193                 if (msConfig !== null) {
194                         return msConfig["configurationsJson"];
195                 }
196                 return null;
197         }
198
199         getMicroServiceJsonRepresentationForName(name) {
200                 var msConfig = this.getMicroServiceForName(name);
201                 if (msConfig !== null) {
202                         return msConfig["jsonRepresentation"];
203                 }
204                 return null;
205         }
206
207         getResourceDetailsVfProperty() {
208                 return this.loopJsonCache["modelService"]["resourceDetails"]["VF"];
209         }
210
211         getResourceDetailsVfModuleProperty() {
212                 return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"];
213         }
214
215         getLoopLogsArray() {
216                 return this.loopJsonCache.loopLogs;
217         }
218
219         getComputedState() {
220                 return this.loopJsonCache.lastComputedState;
221         }
222
223         getComponentStates() {
224                 return this.loopJsonCache.components;
225         }
226 }