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");
83 PolicyAppService.getData('getDictionary/get_RainyDayDictionaryDataByName').then(function (data) {
85 $scope.data = JSON.parse(j.data);
86 console.log($scope.data);
87 $scope.rainyDayDictionaryDatas = JSON.parse($scope.data.rainyDayDictionaryDatas);
88 console.log($scope.rainyDayDictionaryDatas);
90 console.log("failed");
93 PolicyAppService.getData('getDictionary/get_RainyDayDictionaryData').then(function (data) {
95 $scope.data = JSON.parse(j.data);
96 console.log($scope.data);
97 $scope.rainyDayDictionaryDataEntity = JSON.parse($scope.data.rainyDayDictionaryDatas);
98 console.log($scope.rainyDayDictionaryDatasEntity);
100 console.log("failed");
103 function extend(obj, src) {
104 for (var key in src) {
105 if (src.hasOwnProperty(key)) obj[key] = src[key];
110 $scope.saveDecisionPolicy = function(policy){
111 if(policy.itemContent != undefined){
112 $scope.refreshCheck = true;
113 $scope.policyNavigator = policy.itemContent;
114 policy.itemContent = "";
116 $scope.savebutton = false;
118 var uuu = "policycreation/save_policy";
119 var postData={policyData: policy};
124 contentType: 'application/json',
125 data: JSON.stringify(postData),
126 success : function(data){
127 $scope.$apply(function(){
128 $scope.data=data.policyData;
129 if($scope.data == 'success'){
130 $scope.temp.policy.readOnly = 'true';
131 Notification.success("Policy Saved Successfully.");
132 }else if ($scope.data == 'PolicyExists'){
133 $scope.savebutton = true;
134 Notification.error("Policy Already Exists with Same Name in Scope.");
137 console.log($scope.data);
140 error : function(data){
141 Notification.error("Error Occured while saving Policy.");
146 $scope.validatePolicy = function(policy){
148 document.getElementById("validate").innerHTML = "";
149 var uuu = "policyController/validate_policy.htm";
150 var postData={policyData: policy};
155 contentType: 'application/json',
156 data: JSON.stringify(postData),
157 success : function(data){
158 $scope.$apply(function(){
159 $scope.validateData = data.data.replace(/\"/g, "");
160 $scope.data=data.data;
161 if($scope.data == '"success"'){
162 Notification.success("Validation Success.");
163 $scope.savebutton = false;
165 Notification.error("Validation Failed.");
166 document.getElementById("validate").innerHTML = $scope.validateData;
167 document.getElementById("validate").style.color = "white";
168 document.getElementById("validate").style.backgroundColor = "red";
169 $scope.savebutton = true;
173 console.log($scope.data);
175 error : function(data){
176 Notification.error("Validation Failed.");
177 $scope.savebutton = true;
182 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
183 $scope.temp.policy.attributes = [];
184 $scope.temp.policy.settings = [];
185 $scope.temp.policy.ruleAlgorithmschoices = [];
186 if(!$scope.temp.policy.yamlparams){
187 $scope.temp.policy.yamlparams = {};
189 if(!$scope.temp.policy.yamlparams.targets){
190 $scope.temp.policy.yamlparams.targets = [];
192 if(!$scope.temp.policy.yamlparams.blackList){
193 $scope.temp.policy.yamlparams.blackList = [];
195 if(!$scope.temp.policy.rainyday){
196 $scope.temp.policy.rainyday = {};
198 if(!$scope.temp.policy.rainyday.treatmentTableChoices){
199 $scope.temp.policy.rainyday.treatmentTableChoices = [];
202 }else if($scope.temp.policy.ruleProvider=="Custom"){
203 if($scope.temp.policy.attributes.length == 0){
204 $scope.temp.policy.attributes = [];
206 if($scope.temp.policy.settings.length == 0){
207 $scope.temp.policy.settings = [];
209 if($scope.temp.policy.ruleAlgorithmschoices == null || $scope.temp.policy.ruleAlgorithmschoices.length == 0){
210 $scope.temp.policy.ruleAlgorithmschoices = [];
212 }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){
213 if($scope.temp.policy.yamlparams.blackList.length==0){
214 $scope.temp.policy.yamlparams.blackList = [];
216 }else if($scope.temp.policy.ruleProvider=="GUARD_YAML"){
217 if($scope.temp.policy.yamlparams.targets.length==0){
218 $scope.temp.policy.yamlparams.targets = [];
220 }else if($scope.temp.policy.ruleProvider=="Rainy_Day"){
221 if($scope.temp.policy.rainyday.treatmentTableChoices == null || $scope.temp.policy.rainyday.treatmentTableChoices.length == 0){
222 $scope.temp.policy.rainyday.treatmentTableChoices = [];
225 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
226 $scope.addNewChoice = function() {
227 var newItemNo = $scope.temp.policy.attributes.length+1;
228 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
230 $scope.removeChoice = function() {
231 var lastItem = $scope.temp.policy.attributes.length-1;
232 $scope.temp.policy.attributes.splice(lastItem);
235 $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
236 $scope.addNewSettingsChoice = function() {
237 var newItemNo = $scope.temp.policy.settings.length+1;
238 $scope.temp.policy.settings.push({'id':'choice'+newItemNo});
240 $scope.removeSettingsChoice = function() {
241 var lastItem = $scope.temp.policy.settings.length-1;
242 $scope.temp.policy.settings.splice(lastItem);
245 $scope.addNewTarget = function(){
246 $scope.temp.policy.yamlparams.targets.push('');
248 $scope.removeTarget = function(){
249 var lastItem = $scope.temp.policy.yamlparams.targets.length-1;
250 $scope.temp.policy.yamlparams.targets.splice(lastItem);
253 $scope.addNewBL = function() {
254 $scope.temp.policy.yamlparams.blackList.push('');
256 $scope.removeBL = function() {
257 var lastItem = $scope.temp.policy.yamlparams.blackList.length-1;
258 $scope.temp.policy.yamlparams.blackList.splice(lastItem);
261 $scope.treatmentDatas = [{"treatmentValues" : $scope.temp.policy.rainyday.treatmentTableChoices}];
262 $scope.addNewTreatment = function() {
263 $scope.temp.policy.rainyday.treatmentTableChoices.push({});
265 $scope.removeTreatment = function() {
266 var lastItem = $scope.temp.policy.rainyday.treatmentTableChoices.length-1;
267 $scope.temp.policy.rainyday.treatmentTableChoices.splice(lastItem);
270 $scope.workstepDictionaryDatas = [];
271 $scope.getWorkstepValues = function(bbidValue){
272 for (var i = 0; i < $scope.rainyDayDictionaryDataEntity.length; ++i) {
273 var obj = $scope.rainyDayDictionaryDataEntity[i];
274 if (obj.bbid == bbidValue){
275 $scope.workstepDictionaryDatas.push(obj.workstep);
280 $scope.allowedTreatmentsDatas = [];
281 $scope.getTreatmentValues = function(bbidValue, workstepValue){
282 for (var i = 0; i < $scope.rainyDayDictionaryDataEntity.length; ++i) {
283 var obj = $scope.rainyDayDictionaryDataEntity[i];
284 if (obj.bbid == bbidValue && obj.workstep == workstepValue){
285 var splitAlarm = obj.treatments.split(',');
286 for (var j = 0; j < splitAlarm.length; ++j) {
287 $scope.allowedTreatmentsDatas.push(splitAlarm[j]);
294 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
296 $scope.addNewRuleAlgorithm = function() {
297 if($scope.temp.policy.ruleAlgorithmschoices != null){
298 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
303 var value = newItemNo-1;
304 $scope.attributeDictionaryDatas.push('A'+value);
306 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
309 $scope.removeRuleAlgorithm = function() {
310 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
311 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
314 $scope.providerListener = function(ruleProvider) {
315 if (ruleProvider!="Custom"){
316 $scope.temp.policy.ruleAlgorithmschoices = [];
317 $scope.temp.policy.settings = [];
318 $scope.temp.policy.attributes = [];