2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
23 $scope.policyNavigator;
24 $scope.savebutton = true;
25 $scope.refreshCheck = false;
27 $scope.refresh = function(){
28 if($scope.refreshCheck){
29 $scope.policyNavigator.refresh();
31 $scope.modal('createNewPolicy', true);
32 $scope.temp.policy = "";
35 $scope.modal = function(id, hide) {
36 return $('#' + id).modal(hide ? 'hide' : 'show');
39 if($scope.temp.policy.ruleProvider==undefined){
40 $scope.temp.policy.ruleProvider="Custom";
43 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
45 $scope.data = JSON.parse(j.data);
46 console.log($scope.data);
47 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
48 console.log($scope.ecompNameDictionaryDatas);
50 console.log("failed");
53 PolicyAppService.getData('getDictionary/get_SettingsDictionaryDataByName').then(function (data) {
55 $scope.data = JSON.parse(j.data);
56 console.log($scope.data);
57 $scope.settingsDictionaryDatas = JSON.parse($scope.data.settingsDictionaryDatas);
58 console.log($scope.settingsDictionaryDatas);
60 console.log("failed");
63 PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function (data) {
65 $scope.data = JSON.parse(j.data);
66 console.log($scope.data);
67 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
68 console.log($scope.functionDefinitionDatas);
70 console.log("failed");
73 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
75 $scope.data = JSON.parse(j.data);
76 console.log($scope.data);
77 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
78 console.log($scope.attributeDictionaryDatas);
80 console.log("failed");
85 function extend(obj, src) {
86 for (var key in src) {
87 if (src.hasOwnProperty(key)) obj[key] = src[key];
92 $scope.saveDecisionPolicy = function(policy){
93 if(policy.itemContent != undefined){
94 $scope.refreshCheck = true;
95 $scope.policyNavigator = policy.itemContent;
96 policy.itemContent = "";
98 $scope.savebutton = false;
100 var uuu = "policycreation/save_policy";
101 var postData={policyData: policy};
106 contentType: 'application/json',
107 data: JSON.stringify(postData),
108 success : function(data){
109 $scope.$apply(function(){
110 $scope.data=data.policyData;
111 if($scope.data == 'success'){
112 $scope.temp.policy.readOnly = 'true';
113 Notification.success("Policy Saved Successfully.");
114 }else if ($scope.data == 'PolicyExists'){
115 $scope.savebutton = true;
116 Notification.error("Policy Already Exists with Same Name in Scope.");
119 console.log($scope.data);
122 error : function(data){
123 Notification.error("Error Occured while saving Policy.");
128 $scope.validatePolicy = function(policy){
130 document.getElementById("validate").innerHTML = "";
131 var uuu = "policyController/validate_policy.htm";
132 var postData={policyData: policy};
137 contentType: 'application/json',
138 data: JSON.stringify(postData),
139 success : function(data){
140 $scope.$apply(function(){
141 $scope.validateData = data.data.replace(/\"/g, "");
142 $scope.data=data.data;
143 if($scope.data == '"success"'){
144 Notification.success("Validation Success.");
145 $scope.savebutton = false;
147 Notification.error("Validation Failed.");
148 document.getElementById("validate").innerHTML = $scope.validateData;
149 document.getElementById("validate").style.color = "white";
150 document.getElementById("validate").style.backgroundColor = "red";
151 $scope.savebutton = true;
155 console.log($scope.data);
157 error : function(data){
158 Notification.error("Validation Failed.");
159 $scope.savebutton = true;
164 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
165 $scope.temp.policy.attributes = [];
166 $scope.temp.policy.settings = [];
167 $scope.temp.policy.ruleAlgorithmschoices = [];
168 if(!$scope.temp.policy.yamlparams){
169 $scope.temp.policy.yamlparams = {};
171 if(!$scope.temp.policy.yamlparams.blackList){
172 $scope.temp.policy.yamlparams.blackList = [];
174 }else if($scope.temp.policy.ruleProvider=="Custom"){
175 if($scope.temp.policy.attributes.length == 0){
176 $scope.temp.policy.attributes = [];
178 if($scope.temp.policy.settings.length == 0){
179 $scope.temp.policy.settings = [];
181 if($scope.temp.policy.ruleAlgorithmschoices == null || $scope.temp.policy.ruleAlgorithmschoices.length == 0){
182 $scope.temp.policy.ruleAlgorithmschoices = [];
184 }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){
185 if($scope.temp.policy.yamlparams.blackList.length==0){
186 $scope.temp.policy.yamlparams.blackList = [];
189 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
190 $scope.addNewChoice = function() {
191 var newItemNo = $scope.temp.policy.attributes.length+1;
192 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
194 $scope.removeChoice = function() {
195 var lastItem = $scope.temp.policy.attributes.length-1;
196 $scope.temp.policy.attributes.splice(lastItem);
200 $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
201 $scope.addNewSettingsChoice = function() {
202 var newItemNo = $scope.temp.policy.settings.length+1;
203 $scope.temp.policy.settings.push({'id':'choice'+newItemNo});
205 $scope.removeSettingsChoice = function() {
206 var lastItem = $scope.temp.policy.settings.length-1;
207 $scope.temp.policy.settings.splice(lastItem);
210 $scope.addNewBL = function() {
211 $scope.temp.policy.yamlparams.blackList.push('');
213 $scope.removeBL = function() {
214 var lastItem = $scope.temp.policy.yamlparams.blackList.length-1;
215 $scope.temp.policy.yamlparams.blackList.splice(lastItem);
219 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
221 $scope.addNewRuleAlgorithm = function() {
222 if($scope.temp.policy.ruleAlgorithmschoices != null){
223 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
228 var value = newItemNo-1;
229 $scope.attributeDictionaryDatas.push('A'+value);
231 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
234 $scope.removeRuleAlgorithm = function() {
235 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
236 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
239 $scope.providerListener = function(ruleProvider) {
240 if (ruleProvider!="Custom"){
241 $scope.temp.policy.ruleAlgorithmschoices = [];
242 $scope.temp.policy.settings = [];
243 $scope.temp.policy.attributes = [];