4f22dc2bb926e8862d1e76bbbfed0c3aecf93efe
[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         getOperationalPolicyJsonSchema() {
74                 return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"];
75         }
76
77         getOperationalPolicies() {
78                 return this.loopJsonCache["operationalPolicies"];
79         }
80
81         getOperationalPoliciesNoJsonSchema() {
82                 var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]));
83                 delete operationalPolicies[0]["jsonRepresentation"];
84                 return operationalPolicies;
85         }
86
87         getGlobalProperties() {
88                 return this.loopJsonCache["globalPropertiesJson"];
89         }
90
91         getDcaeDeploymentProperties() {
92                 return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"];
93         }
94
95         getMicroServicePolicies() {
96                 return this.loopJsonCache["microServicePolicies"];
97         }
98
99         getOperationalPolicyForName(name) {
100                 var opProperties=this.getOperationalPolicies();
101                 for (var policy in opProperties) {
102                         if (opProperties[policy]["name"] === name) {
103                                 return opProperties[policy];
104                         }
105                 }
106                 return null;
107         }
108
109         getOperationalPolicyPropertiesForName(name) {
110                 var opConfig = this.getOperationalPolicyForName(name);
111                 if (opConfig !== null) {
112                         return opConfig["configurationsJson"];
113                 }
114                 return null;
115         }
116
117         getOperationalPolicyJsonRepresentationForName(name) {
118                 var opConfig = this.getOperationalPolicyForName(name);
119                 if (opConfig !== null) {
120                         return opConfig["jsonRepresentation"];
121                 }
122                 return null;
123         }
124
125         getOperationalPolicySupportedPdpGroup(name) {
126                 var opConfig=this.getOperationalPolicyForName(name);
127                 if (opConfig !== null) {
128                     if (opConfig["policyModel"]["policyPdpGroup"] !== undefined && opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) {
129                             return opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
130                         }
131                 }
132                 return [];
133         }
134
135         getOperationalPolicyPdpGroup(name) {
136                 var opConfig=this.getOperationalPolicyForName(name);
137                 if (opConfig !== null) {
138                         return opConfig["pdpGroup"];
139                 }
140                 return null;
141         }
142
143         getOperationalPolicyPdpSubgroup(name) {
144                 var opConfig=this.getOperationalPolicyForName(name);
145                 if (opConfig !== null) {
146                         return opConfig["pdpSubgroup"];
147                 }
148                 return null;
149         }
150
151         getMicroServiceSupportedPdpGroup(name) {
152                 var microService=this.getMicroServiceForName(name);
153                 if (microService !== null) {
154                     if (microService["policyModel"]["policyPdpGroup"] !== undefined && microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) {
155                             return microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"];
156                         }
157                 }
158                 return [];
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
223         getTemplateName() {
224             if (this.loopJsonCache["loopTemplate"] !== undefined) {
225                                 return this.loopJsonCache["loopTemplate"].name;
226         }
227             return null;
228         }
229 }