removing unused db file
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / FirewallPolicyController.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('fwPolicyController', function ($scope, $window, PolicyDictionaryService,modalService, $modal, Notification, PapUrlService) {
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.getSecurityZoneDictionaryData(papUrl).then(function (data) {
35                 var j = data;
36                 $scope.data = JSON.parse(j.data);
37                 console.log($scope.data);
38                 $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas);
39                 console.log($scope.securityZoneDictionaryDatas);
40             }, function (error) {
41                 console.log("failed");
42             });
43             
44             PolicyDictionaryService.getTermListDictionaryData(papUrl).then(function (data) {
45                 var j = data;
46                 $scope.data = JSON.parse(j.data);
47                 console.log($scope.data);
48                 $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
49                 console.log($scope.termListDictionaryDatas);
50             }, function (error) {
51                 console.log("failed");
52             });
53             
54             PolicyDictionaryService.getFWDictionaryListDictionaryData(papUrl).then(function (data) {
55                 var j = data;
56                 $scope.data = JSON.parse(j.data);
57                 console.log($scope.data);
58                 $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas);
59                 console.log($scope.fwDictListDictionaryDatas);
60             }, function (error) {
61                 console.log("failed");
62             });
63             
64             PolicyDictionaryService.getFWParentListDictionaryData().then(function (data) {
65                 var j = data;
66                 $scope.data = JSON.parse(j.data);
67                 console.log($scope.data);
68                 $scope.fwParentListDictionaryDatas = JSON.parse($scope.data.fwParentListDictionaryDatas);
69                 console.log($scope.fwParentListDictionaryDatas);
70             }, function (error) {
71                 console.log("failed");
72             });
73             
74             PolicyDictionaryService.getRiskTypeDictionaryData(papUrl).then(function (data) {
75                 var j = data;
76                 $scope.data = JSON.parse(j.data);
77                 console.log($scope.data);
78                 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
79                 console.log($scope.riskTypeDictionaryDatas);
80             }, function (error) {
81                 console.log("failed");
82             });
83             
84             PolicyDictionaryService.getRiskLevelValueData().then(function (data) {
85                 var j = data;
86                 $scope.data = JSON.parse(j.data);
87                 console.log($scope.data);
88                 $scope.riskLevelDatas = JSON.parse($scope.data.riskLevelDatas);
89                 console.log($scope.riskLevelDatas);
90             }, function (error) {
91                 console.log("failed");
92             });
93             
94             PolicyDictionaryService.getGuardValueData().then(function (data) {
95                 var j = data;
96                 $scope.data = JSON.parse(j.data);
97                 console.log($scope.data);
98                 $scope.guardDatas = JSON.parse($scope.data.guardDatas);
99                 console.log($scope.guardDatas);
100             }, function (error) {
101                 console.log("failed");
102             });
103         });
104     
105     
106     
107
108     function extend(obj, src) {
109         for (var key in src) {
110             if (src.hasOwnProperty(key)) obj[key] = src[key];
111         }
112         return obj;
113     }
114     
115     $scope.viewFWRule = function(policy){
116         console.log(policy);
117         var uuu = "policyController/ViewFWPolicyRule.htm";
118         var postData={policyData: policy};
119         $.ajax({
120             type : 'POST',
121             url : uuu,
122             dataType: 'json',
123             contentType: 'application/json',
124             data: JSON.stringify(postData),
125             success : function(data){
126                 $scope.$apply(function(){
127                         window.alert(data.policyData);
128                 });
129             },
130             error : function(data){
131                 Notification.error("Error Occured while Showing Rule.");
132             }
133         });
134     };
135     
136     
137     $scope.saveFWPolicy = function(policy){
138         console.log(policy);
139        /* var finalData = extend(policy, $scope.attributeDatas[0]);
140         console.log(finalData);*/
141         var uuu = "policyController/save_FirewallPolicy.htm";
142                 var postData={policyData: policy};
143                 $.ajax({
144                         type : 'POST',
145                         url : uuu,
146                         dataType: 'json',
147                         contentType: 'application/json',
148                         data: JSON.stringify(postData),
149                         success : function(data){
150                                 $scope.$apply(function(){
151                                                 $scope.data=data.data;
152                                                 $scope.temp.policy.readOnly = 'true';
153                                                 Notification.success("Policy Saved Successfully.");
154                                 });
155                                 console.log($scope.data);
156                                 $modalInstance.close();
157                                 
158                         },
159                         error : function(data){
160                                 Notification.error("Error Occured while saving Policy.");
161                         }
162                 });
163     };
164     
165     $scope.validatePolicy = function(policy){
166         console.log(policy);
167          var uuu = "policyController/validate_policy.htm";
168                 var postData={policyData: policy};
169                 $.ajax({
170                         type : 'POST',
171                         url : uuu,
172                         dataType: 'json',
173                         contentType: 'application/json',
174                         data: JSON.stringify(postData),
175                         success : function(data){
176                                 $scope.$apply(function(){
177                                                 $scope.data=data.data.substring(1,8);
178                                                 var size = data.data.length;
179                                                 if($scope.data == 'success'){
180                                                         Notification.success("Validation Success.");
181                                                         if (size > 18){
182                                                                 var displayWarning = data.data.substring(19,size);
183                                                                 window.alert(displayWarning);
184                                                         }       
185                                                 }else{
186                                                         Notification.error("Validation Failed.");
187                                                 }
188                                                 
189                                 });
190                                 console.log($scope.data);
191                                 /*$modalInstance.close();*/
192                                 
193                         },
194                         error : function(data){
195                                 Notification.error("Validation Failed.");
196                         }
197                 });
198     };
199     
200     if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
201         $scope.temp.policy.attributes = [];
202         $scope.temp.policy.fwattributes = [];
203     }else{
204            if($scope.temp.policy.attributes.length == 0){
205                    $scope.temp.policy.attributes = [];
206            }
207            if($scope.temp.policy.fwPolicyType == 'Parent Policy'){
208                    if($scope.temp.policy.fwattributes.length == 0){
209                            $scope.temp.policy.fwattributes = [];
210                    }
211            }
212    }
213     
214     $scope.attributeDatas = [{"ruleSetup" : $scope.temp.policy.attributes}];
215     $scope.addNewChoice = function() {
216       var newItemNo = $scope.temp.policy.attributes.length+1;
217       $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
218     };    
219     $scope.removeChoice = function() {
220       var lastItem = $scope.temp.policy.attributes.length-1;
221       $scope.temp.policy.attributes.splice(lastItem);
222     };
223     
224     $scope.fwattributeDatas = [{"parentSetup" : $scope.temp.policy.fwattributes}];
225     $scope.addNewFWDictList = function() {
226       var newItemNo = $scope.temp.policy.fwattributes.length+1;
227       $scope.temp.policy.fwattributes.push({'id':'choice'+newItemNo});
228     };    
229     $scope.removefwDictChoice = function() {
230       var lastItem = $scope.temp.policy.fwattributes.length-1;
231       $scope.temp.policy.fwattributes.splice(lastItem);
232     };
233         
234 });