Rework the Open CL window
[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 class LoopCache {
25         loopJsonCache;
26
27         constructor(loopJson) {
28                 this.loopJsonCache=loopJson;
29                 //LoopCache.SET_LOOP_JSON_CACHE(require('./example.json');
30         }
31
32         updateMsProperties(type, newMsProperties) {
33                 if (newMsProperties["name"] === type) {
34                         for (var policy in this.loopJsonCache["microServicePolicies"]) {
35                                 if (this.loopJsonCache["microServicePolicies"][policy]["name"] === type) {
36                                         this.loopJsonCache["microServicePolicies"][policy] = newMsProperties;
37                                 }
38                         }
39                 }
40         }
41
42         updateGlobalProperties(newGlobalProperties) {
43                 this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties;
44         }
45
46         updateOpPolicyProperties(newOpProperties) {
47                 this.loopJsonCache["operationalPolicies"] = newOpProperties;
48         }
49
50         getLoopName() {
51                 return this.loopJsonCache["name"];
52         }
53
54         getOperationalPolicyProperty() {
55                 return JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"]));
56         }
57
58         getOperationalPolicies() {
59                 return JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]));
60         }
61
62         getGlobalProperty() {
63                 return JSON.parse(JSON.stringify(this.loopJsonCache["globalPropertiesJson"]));
64         }
65
66         getDeploymentProperties() {
67                 return JSON.parse(JSON.stringify(this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"]));
68         }
69
70         getMsJson(type) {
71                 var msProperties = this.loopJsonCache["microServicePolicies"];
72                 for (var policy in msProperties) {
73                         if (msProperties[policy]["name"] === type) {
74                                 return JSON.parse(JSON.stringify(msProperties[policy]));
75                         }
76                 }
77                 return null;
78         }
79
80         getMsProperty(type) {
81                 var msProperties = this.loopJsonCache["microServicePolicies"];
82                 for (var policy in msProperties) {
83                         if (msProperties[policy]["name"] === type) {
84                                 if (msProperties[policy]["properties"] !== null && msProperties[policy]["properties"] !== undefined) {
85                                         return JSON.parse(JSON.stringify(msProperties[policy]["properties"]));
86                                 }
87                         }
88                 }
89                 return null;
90         }
91
92         getMsUI(type) {
93                 var msProperties = this.loopJsonCache["microServicePolicies"];
94                 for (var policy in msProperties) {
95                         if (msProperties[policy]["name"] === type) {
96                                 return JSON.parse(JSON.stringify(msProperties[policy]["jsonRepresentation"]));
97                         }
98                 }
99                 return null;
100         }
101
102         getResourceDetailsVfProperty() {
103                 return this.loopJsonCache["modelPropertiesJson"]["resourceDetails"]["VF"];
104         }
105
106         getResourceDetailsVfModuleProperty() {
107                 return this.loopJsonCache["modelPropertiesJson"]["resourceDetails"]["VFModule"];
108         }
109
110         getLoopLogsArray() {
111                 return this.loopJsonCache.loopLogs;
112         }
113
114         getComponentStates() {
115                 return this.loopJsonCache.components;
116         }
117
118         get getLoopJsonCache() {
119                 return this.loopJsonCache;
120         }
121
122         set setLoopJsonCache(newJson) {
123                 this.loopJsonCache = newJson;
124         }
125 }
126
127 export const LOOP_CACHE = new LoopCache(require('./example.json'));
128
129 export default LoopCache;