Add UI tests
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / propertyController.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 function saveMsProperties(type, form) {
25          var newMsProperties = cl_props["microServicePolicies"];
26     for (p in newMsProperties) {
27         if (newMsProperties[p]["name"] == type) {
28                 newMsProperties[p]["properties"] = form;
29         }
30     }
31
32          var def = $q.defer();
33          var sets = [];
34          var svcUrl = "/restservices/clds/v2/loop/updateMicroservicePolicies/" + modelName;
35          var svcRequest = {
36                          loopName : modelName,
37                          newMicroservicePolicies : newMsProperties
38          };
39          $http.post(svcUrl, svcRequest).success(function(data) {
40                  def.resolve(data);
41          }).error(function(data) {
42                  def.reject("Save Model not successful");
43          });
44     cl_props["microServicePolicies"] = newMsProperties;
45     return def.promise;
46 }
47
48 function saveGlobalProperties(form) {
49          var def = $q.defer();
50          var sets = [];
51          var svcUrl = "/restservices/clds/v2/loop/globalProperties/" + modelName;
52          var svcRequest = {
53                          loopName : modelName,
54                          newGlobalPolicies : form
55          };
56          $http.post(svcUrl, svcRequest).success(function(data) {
57                  def.resolve(data);
58          }).error(function(data) {
59                  def.reject("Save Model not successful");
60          });
61     cl_props["globalPropertiesJson"] = form;
62     return def.promise;
63 }
64
65 function saveOpPolicyProperties(form) {
66         var newOpProperties = cl_props["operationalPolicies"];
67         newOpProperties["0"]["configurationsJson"]= form;
68         
69         var def = $q.defer();
70          var sets = [];
71          var svcUrl = "/restservices/clds/v2/loop/updateOperationalPolicies/" + modelName;
72          var svcRequest = {
73                          loopName : modelName,
74                          newGlobalPolicies : newOpProperties
75          };
76          $http.post(svcUrl, svcRequest).success(function(data) {
77                  def.resolve(data);
78          }).error(function(data) {
79                  def.reject("Save Model not successful");
80    });
81         
82    cl_props["operationalPolicies"] = newOpProperties;
83    return def.promise;
84 }
85
86 function getOperationalPolicyProperty() {
87     return cl_props["operationalPolicies"]["0"]["configurationsJson"];
88 }
89
90 function getGlobalProperty() {
91     return cl_props["globalPropertiesJson"];
92 }
93
94 function getMsProperty(type) {
95     var msProperties = cl_props["microServicePolicies"];
96     for (p in msProperties) {
97         if (msProperties[p]["name"] == type) {
98            return msProperties[p]["properties"];
99         }
100     }
101     return null;
102 }
103
104 function getMsUI(type) {
105     var msProperties = cl_props["microServicePolicies"];
106     for (p in msProperties) {
107         if (msProperties[p]["name"] == type) {
108            return msProperties[p]["jsonRepresentation"];
109         }
110     }
111     return null;
112 }
113
114 function getStatus() {
115     return cl_props["lastComputedState"];
116 }
117
118 function getDeploymentID() {
119     return cl_props["dcaeDeploymentId"];
120 }
121
122 function getDeploymentStatusURL() {
123     return cl_props["dcaeDeploymentStatusUrl"];
124 }
125 module.exports = { getOperationalPolicyProperty,getGlobalProperty,getMsProperty,getMsUI,getStatus,getDeploymentID,getDeploymentStatusURL };