Remove unused vars and methods
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / ClosedLoopPMController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 angular.module("abs").controller('clPMController', ['$scope', '$window', '$timeout', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function($scope, $window, $timeout, PolicyAppService, PolicyNavigator, modalService, $modal, Notification){
21          $("#dialog").hide();
22          
23          $scope.policyNavigator;
24          $scope.savebutton = true;
25          $scope.refreshCheck = false;
26         
27          if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
28                  $scope.temp.policy = {
29                                  policyType : "Config",
30                                  configPolicyType : "ClosedLoop_PM"
31                  }
32          }
33          
34          $scope.refresh = function(){
35            if($scope.refreshCheck){
36                 $scope.policyNavigator.refresh();
37             }
38             $scope.modal('createNewPolicy', true);
39             $scope.temp.policy = "";
40           };
41             
42           $scope.modal = function(id, hide) {
43               return $('#' + id).modal(hide ? 'hide' : 'show');
44           };
45           
46           $('#ttlDate').datepicker({
47                   dateFormat: 'dd/mm/yy',
48                   changeMonth: true,
49                   changeYear: true,
50                   onSelect: function(date) {
51                           angular.element($('#ttlDate')).triggerHandler('input');
52                   }
53           });
54          
55          PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
56                  var j = data;
57                  $scope.data = JSON.parse(j.data);
58                  console.log($scope.data);
59                  $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
60                  console.log($scope.onapNameDictionaryDatas);
61          }, function (error) {
62                  console.log("failed");
63          });
64
65          PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
66                  var j = data;
67                  $scope.data = JSON.parse(j.data);
68                  console.log($scope.data);
69                  $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
70                  console.log($scope.riskTypeDictionaryDatas);
71          }, function (error) {
72                  console.log("failed");
73          });
74                         
75                     
76          PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
77                 var j = data;
78                 $scope.PMData = j;
79             });
80             
81             if($scope.temp.policy.readOnly && $scope.temp.policy.editPolicy){
82                 $scope.temp.policy.verticaMetrics = [];
83                     $scope.temp.policy.description = [];
84                     $scope.temp.policy.attributes = [];
85             }
86             
87             $scope.addDataToFields = function(serviceType){
88                 if($scope.PMData == undefined){
89                         $scope.temp.policy.verticaMetrics = [];
90                         $scope.temp.policy.description = [];
91                         $scope.temp.policy.attributes = [];
92                         PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
93                                 var j = data;
94                                 $scope.PMData = j;
95                                 if(serviceType.serviceTypePolicyName == 'Registration Failure(Trinity)'){
96                                         var myNewData = $scope.PMData[0];
97                                 }else if(serviceType.serviceTypePolicyName == 'International Fraud(Trinity)'){
98                                         var myNewData = $scope.PMData[1];
99                                 }else if(serviceType.serviceTypePolicyName == 'No dial tone(Trinity)'){
100                                         var myNewData = $scope.PMData[2];
101                                 }else if(serviceType.serviceTypePolicyName == 'Call storm(Trinity)'){
102                                         var myNewData = $scope.PMData[3];
103                                 }else if(serviceType.serviceTypePolicyName == 'Registration storm(Trinity)'){
104                                         var myNewData = $scope.PMData[4];
105                                 }
106                                 
107                                 $scope.temp.policy.verticaMetrics = myNewData;
108                                 $scope.temp.policy.description = myNewData;
109                                 $scope.temp.policy.attributeFields = myNewData;
110                         });
111                 }else{
112                                 $scope.temp.policy.verticaMetrics = serviceType;
113                                 $scope.temp.policy.description = serviceType;
114                                 $scope.temp.policy.attributeFields = serviceType;
115                 }
116                 
117             };
118             
119             $scope.saveCLPMPolicy = function(policy){
120                 if(policy.itemContent != undefined){
121                         $scope.refreshCheck = true; 
122                         $scope.policyNavigator = policy.itemContent;
123                         policy.itemContent = "";
124                 }
125                 $scope.savebutton = false;
126                 var uuu = "policycreation/save_policy";
127                         var postData={policyData: policy};
128                         $.ajax({
129                                 type : 'POST',
130                                 url : uuu,
131                                 dataType: 'json',
132                                 contentType: 'application/json',
133                                 data: JSON.stringify(postData),
134                                 success : function(data){
135                                         $scope.$apply(function(){
136                                                 $scope.data=data.policyData;
137                                                 if($scope.data == 'success'){
138                                                         $scope.temp.policy.readOnly = 'true';
139                                                         Notification.success("Policy Saved Successfully.");     
140                                                 }else if ($scope.data == 'PolicyExists'){
141                                                         $scope.savebutton = true;
142                                                         Notification.error("Policy Already Exists with Same Name in Scope.");
143                                                 }
144                                         });
145                                         console.log($scope.data);
146                                 },
147                                 error : function(data){
148                                         Notification.error("Error Occured while saving Policy.");
149                                 }
150                         });
151             };
152             
153             $scope.validatePolicy = function(policy){
154                 console.log(policy);
155                 document.getElementById("validate").innerHTML = "";
156                  var uuu = "policyController/validate_policy.htm";
157                         var postData={policyData: policy};
158                         $.ajax({
159                                 type : 'POST',
160                                 url : uuu,
161                                 dataType: 'json',
162                                 contentType: 'application/json',
163                                 data: JSON.stringify(postData),
164                                 success : function(data){
165                                         $scope.$apply(function(){
166                                                 $scope.validateData = data.data.replace(/\"/g, "");
167                                                         $scope.data=data.data.substring(1,8);
168                                                         var size = data.data.length;
169                                                         if($scope.data == 'success'){
170                                                                 Notification.success("Validation Success.");
171                                                                 $scope.savebutton = false;
172                                                                 if (size > 18){
173                                                                         var displayWarning = data.data.substring(19,size);
174                                                                         document.getElementById("validate").innerHTML = "Safe Policy Warning Message  :  "+displayWarning;
175                                                                         document.getElementById("validate").style.color = "white";
176                                                                         document.getElementById("validate").style.backgroundColor = "skyblue";
177                                                                 }       
178                                                         }else{
179                                                                 Notification.error("Validation Failed.");
180                                                                 document.getElementById("validate").innerHTML = $scope.validateData;
181                                                                 document.getElementById("validate").style.color = "white";
182                                                                 document.getElementById("validate").style.backgroundColor = "red";
183                                                                 $scope.savebutton = true;
184                                                         }
185                                                         
186                                         });
187                                         console.log($scope.data);                               
188                                 },
189                                 error : function(data){
190                                         Notification.error("Validation Failed.");
191                                         $scope.savebutton = true;
192                                 }
193                         });
194             };
195           
196 }]);