Update react
[clamp.git] / ui-react / src / api / LoopCache.js
index d44b5cf..dd8c5b5 100644 (file)
  *
  */
 
-class LoopCache {
+export default class LoopCache {
        loopJsonCache;
 
        constructor(loopJson) {
                this.loopJsonCache=loopJson;
-               //LoopCache.SET_LOOP_JSON_CACHE(require('./example.json');
        }
 
-       updateMsProperties(type, newMsProperties) {
-               if (newMsProperties["name"] === type) {
+       updateMicroServiceProperties(name, newMsProperties) {
                        for (var policy in this.loopJsonCache["microServicePolicies"]) {
-                               if (this.loopJsonCache["microServicePolicies"][policy]["name"] === type) {
-                                       this.loopJsonCache["microServicePolicies"][policy] = newMsProperties;
+                               if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) {
+                                       this.loopJsonCache["microServicePolicies"][policy]["properties"] = newMsProperties;
                                }
                        }
-               }
        }
 
        updateGlobalProperties(newGlobalProperties) {
                this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties;
        }
 
-       updateOpPolicyProperties(newOpProperties) {
+       updateOperationalPolicyProperties(newOpProperties) {
                this.loopJsonCache["operationalPolicies"] = newOpProperties;
        }
 
@@ -51,50 +48,52 @@ class LoopCache {
                return this.loopJsonCache["name"];
        }
 
-       getOperationalPolicyProperty() {
-               return JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"]));
+       getOperationalPolicyConfigurationJson() {
+               return this.loopJsonCache["operationalPolicies"]["0"]["configurationsJson"];
+       }
+       
+       getOperationalPolicyJsonSchema() {
+               return this.loopJsonCache["operationalPolicySchema"];
        }
 
        getOperationalPolicies() {
-               return JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"]));
+               return this.loopJsonCache["operationalPolicies"];
        }
 
-       getGlobalProperty() {
-               return JSON.parse(JSON.stringify(this.loopJsonCache["globalPropertiesJson"]));
+       getGlobalProperties() {
+               return this.loopJsonCache["globalPropertiesJson"];
        }
 
-       getDeploymentProperties() {
-               return JSON.parse(JSON.stringify(this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"]));
+       getDcaeDeploymentProperties() {
+               return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"];
        }
 
-       getMsJson(type) {
-               var msProperties = this.loopJsonCache["microServicePolicies"];
+       getMicroServicePolicies() {
+               return this.loopJsonCache["microServicePolicies"];
+       }
+
+       getMicroServiceForName(name) {
+               var msProperties=this.getMicroServicePolicies();
                for (var policy in msProperties) {
-                       if (msProperties[policy]["name"] === type) {
-                               return JSON.parse(JSON.stringify(msProperties[policy]));
+                       if (msProperties[policy]["name"] === name) {
+                               return msProperties[policy];
                        }
                }
                return null;
        }
 
-       getMsProperty(type) {
-               var msProperties = this.loopJsonCache["microServicePolicies"];
-               for (var policy in msProperties) {
-                       if (msProperties[policy]["name"] === type) {
-                               if (msProperties[policy]["properties"] !== null && msProperties[policy]["properties"] !== undefined) {
-                                       return JSON.parse(JSON.stringify(msProperties[policy]["properties"]));
-                               }
-                       }
+       getMicroServicePropertiesForName(name) {
+               var msConfig = this.getMicroServiceForName(name);
+               if (msConfig !== null) {
+                       return msConfig["properties"];
                }
                return null;
        }
 
-       getMsUI(type) {
-               var msProperties = this.loopJsonCache["microServicePolicies"];
-               for (var policy in msProperties) {
-                       if (msProperties[policy]["name"] === type) {
-                               return JSON.parse(JSON.stringify(msProperties[policy]["jsonRepresentation"]));
-                       }
+       getMicroServiceJsonRepresentationForName(name) {
+               var msConfig = this.getMicroServiceForName(name);
+               if (msConfig !== null) {
+                       return msConfig["jsonRepresentation"];
                }
                return null;
        }
@@ -111,19 +110,11 @@ class LoopCache {
                return this.loopJsonCache.loopLogs;
        }
 
-       getComponentStates() {
-               return this.loopJsonCache.components;
-       }
-
-       get getLoopJsonCache() {
-               return this.loopJsonCache;
+       getComputedState() {
+               return this.loopJsonCache.lastComputedState;
        }
 
-       set setLoopJsonCache(newJson) {
-               this.loopJsonCache = newJson;
+       getComponentStates() {
+               return this.loopJsonCache.components;
        }
 }
-
-export const LOOP_CACHE = new LoopCache(require('./example.json'));
-
-export default LoopCache;