Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / ClosedLoopPMController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 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
21 /**
22  * 
23  */
24 angular.module("abs").controller('clPMController', function($scope, $window, $timeout, PapUrlService, ClosedLoopPMService, PolicyDictionaryService, modalService, $modal, Notification){
25          $("#dialog").hide();
26          
27                 $scope.temp.policy.ttlDate = new Date($scope.temp.policy.ttlDate);
28                 var papUrl;
29                 PapUrlService.getPapUrl().then(function(data) {
30                         var config = data;
31                         papUrl = config.PAP_URL;
32                         console.log(papUrl);
33                         
34                     PolicyDictionaryService.getEcompDictionaryData(papUrl).then(function (data) {
35                         var j = data;
36                         $scope.data = JSON.parse(j.data);
37                         console.log($scope.data);
38                         $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
39                         console.log($scope.ecompNameDictionaryDatas);
40                     }, function (error) {
41                         console.log("failed");
42                     });
43                     PolicyDictionaryService.getRiskTypeDictionaryData(papUrl).then(function (data) {
44                         var j = data;
45                         $scope.data = JSON.parse(j.data);
46                         console.log($scope.data);
47                         $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
48                         console.log($scope.riskTypeDictionaryDatas);
49                     }, function (error) {
50                         console.log("failed");
51                     });
52                     PolicyDictionaryService.getRiskLevelValueData().then(function (data) {
53                         var j = data;
54                         $scope.data = JSON.parse(j.data);
55                         console.log($scope.data);
56                         $scope.riskLevelDatas = JSON.parse($scope.data.riskLevelDatas);
57                         console.log($scope.riskLevelDatas);
58                     }, function (error) {
59                         console.log("failed");
60                     });
61                     PolicyDictionaryService.getGuardValueData().then(function (data) {
62                         var j = data;
63                         $scope.data = JSON.parse(j.data);
64                         console.log($scope.data);
65                         $scope.guardDatas = JSON.parse($scope.data.guardDatas);
66                         console.log($scope.guardDatas);
67                     }, function (error) {
68                         console.log("failed");
69                     });
70                         
71                 });
72                     
73             ClosedLoopPMService.getPMJSONBodyData().then(function(data){
74                 var j = data;
75                 $scope.PMData = j;
76             });
77             
78             $scope.temp.policy.verticaMetrics = [];
79             $scope.temp.policy.description = [];
80             $scope.temp.policy.attributes = [];
81             
82             $scope.addDataToFields = function(serviceType){
83                 if($scope.PMData == undefined){
84                         $scope.temp.policy.verticaMetrics = [];
85                         $scope.temp.policy.description = [];
86                         $scope.temp.policy.attributes = [];
87                         ClosedLoopPMService.getPMJSONBodyData().then(function(data){
88                                 var j = data;
89                                 $scope.PMData = j;
90                                 if(serviceType.serviceTypePolicyName == 'Registration Failure(Trinity)'){
91                                         var myNewData = $scope.PMData[0];
92                                 }else if(serviceType.serviceTypePolicyName == 'International Fraud(Trinity)'){
93                                         var myNewData = $scope.PMData[1];
94                                 }else if(serviceType.serviceTypePolicyName == 'No dial tone(Trinity)'){
95                                         var myNewData = $scope.PMData[2];
96                                 }else if(serviceType.serviceTypePolicyName == 'Call storm(Trinity)'){
97                                         var myNewData = $scope.PMData[3];
98                                 }else if(serviceType.serviceTypePolicyName == 'Registration storm(Trinity)'){
99                                         var myNewData = $scope.PMData[4];
100                                 }
101                                 
102                                 $scope.temp.policy.verticaMetrics = myNewData;
103                                 $scope.temp.policy.description = myNewData;
104                                 $scope.temp.policy.attributeFields = myNewData;
105                         });
106                 }else{
107                         var key = $scope.PMData.indexOf(serviceType);
108                                 var myNewData = $scope.PMData[key];
109                                 $scope.temp.policy.verticaMetrics = myNewData;
110                                 $scope.temp.policy.description = myNewData;
111                                 $scope.temp.policy.attributeFields = myNewData;
112                 }
113                 
114             };
115             
116             $scope.saveCLPMPolicy = function(policy){
117                 console.log(policy);
118                 console.log();
119                 var uuu = "policyController/save_PMPolicy.htm";
120                         var postData={policyData: policy};
121                         $.ajax({
122                                 type : 'POST',
123                                 url : uuu,
124                                 dataType: 'json',
125                                 contentType: 'application/json',
126                                 data: JSON.stringify(postData),
127                                 success : function(data){
128                                         $scope.$apply(function(){
129                                                         $scope.data=data.data;
130                                                         $scope.temp.policy.readOnly = 'true';
131                                                         Notification.success("Policy Saved Successfully.");
132                                         });
133                                         console.log($scope.data);
134                                         $modalInstance.close();
135                                         
136                                 },
137                                 error : function(data){
138                                         Notification.error("Error Occured while saving Policy.");
139                                 }
140                         });
141             };
142             
143             $scope.validatePolicy = function(policy){
144                 console.log(policy);
145                  var uuu = "policyController/validate_policy.htm";
146                         var postData={policyData: policy};
147                         $.ajax({
148                                 type : 'POST',
149                                 url : uuu,
150                                 dataType: 'json',
151                                 contentType: 'application/json',
152                                 data: JSON.stringify(postData),
153                                 success : function(data){
154                                         $scope.$apply(function(){
155                                                         $scope.data=data.data.substring(1,8);
156                                                         var size = data.data.length;
157                                                         if($scope.data == 'success'){
158                                                                 Notification.success("Validation Success.");
159                                                                 if (size > 18){
160                                                                         var displayWarning = data.data.substring(19,size);
161                                                                         window.alert(displayWarning);
162                                                                 }       
163                                                         }else{
164                                                                 Notification.error("Validation Failed.");
165                                                         }
166                                                         
167                                         });
168                                         console.log($scope.data);
169                                         /*$modalInstance.close();*/
170                                         
171                                 },
172                                 error : function(data){
173                                         Notification.error("Validation Failed.");
174                                 }
175                         });
176             };
177           
178 })