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 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
28 $scope.temp.policy = {
29 policyType : "Decision"
33 $scope.refresh = function(){
34 if($scope.refreshCheck){
35 $scope.policyNavigator.refresh();
37 $scope.modal('createNewPolicy', true);
38 $scope.temp.policy = "";
41 $scope.modal = function(id, hide) {
42 return $('#' + id).modal(hide ? 'hide' : 'show');
45 if($scope.temp.policy.ruleProvider==undefined){
46 $scope.temp.policy.ruleProvider="Custom";
49 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
54 console.log($scope.onapNameDictionaryDatas);
56 console.log("failed");
59 PolicyAppService.getData('getDictionary/get_SettingsDictionaryDataByName').then(function (data) {
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.settingsDictionaryDatas = JSON.parse($scope.data.settingsDictionaryDatas);
64 console.log($scope.settingsDictionaryDatas);
66 console.log("failed");
69 PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 console.log($scope.data);
73 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
74 console.log($scope.functionDefinitionDatas);
76 console.log("failed");
79 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
81 $scope.data = JSON.parse(j.data);
82 console.log($scope.data);
83 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
84 console.log($scope.attributeDictionaryDatas);
86 console.log("failed");
89 PolicyAppService.getData('getDictionary/get_RainyDayDictionaryDataByName').then(function (data) {
91 $scope.data = JSON.parse(j.data);
92 console.log($scope.data);
93 $scope.rainyDayDictionaryDatas = JSON.parse($scope.data.rainyDayDictionaryDatas);
94 console.log($scope.rainyDayDictionaryDatas);
96 console.log("failed");
99 PolicyAppService.getData('getDictionary/get_RainyDayDictionaryData').then(function (data) {
101 $scope.data = JSON.parse(j.data);
102 console.log($scope.data);
103 $scope.rainyDayDictionaryDataEntity = JSON.parse($scope.data.rainyDayDictionaryDatas);
104 console.log($scope.rainyDayDictionaryDatasEntity);
105 }, function (error) {
106 console.log("failed");
109 function extend(obj, src) {
110 for (var key in src) {
111 if (src.hasOwnProperty(key)) obj[key] = src[key];
116 $scope.saveDecisionPolicy = function(policy){
117 if(policy.itemContent != undefined){
118 $scope.refreshCheck = true;
119 $scope.policyNavigator = policy.itemContent;
120 policy.itemContent = "";
122 $scope.savebutton = false;
124 var uuu = "policycreation/save_policy";
125 var postData={policyData: policy};
130 contentType: 'application/json',
131 data: JSON.stringify(postData),
132 success : function(data){
133 $scope.$apply(function(){
134 $scope.data=data.policyData;
135 if($scope.data == 'success'){
136 $scope.temp.policy.readOnly = 'true';
137 Notification.success("Policy Saved Successfully.");
138 }else if ($scope.data == 'PolicyExists'){
139 $scope.savebutton = true;
140 Notification.error("Policy Already Exists with Same Name in Scope.");
143 console.log($scope.data);
146 error : function(data){
147 Notification.error("Error Occured while saving Policy.");
152 $scope.validatePolicy = function(policy){
154 document.getElementById("validate").innerHTML = "";
155 var uuu = "policyController/validate_policy.htm";
156 var postData={policyData: policy};
161 contentType: 'application/json',
162 data: JSON.stringify(postData),
163 success : function(data){
164 $scope.$apply(function(){
165 $scope.validateData = data.data.replace(/\"/g, "");
166 $scope.data=data.data;
167 if($scope.data == '"success"'){
168 Notification.success("Validation Success.");
169 $scope.savebutton = false;
171 Notification.error("Validation Failed.");
172 document.getElementById("validate").innerHTML = $scope.validateData;
173 document.getElementById("validate").style.color = "white";
174 document.getElementById("validate").style.backgroundColor = "red";
175 $scope.savebutton = true;
179 console.log($scope.data);
181 error : function(data){
182 Notification.error("Validation Failed.");
183 $scope.savebutton = true;
188 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
189 $scope.temp.policy.attributes = [];
190 $scope.temp.policy.settings = [];
191 $scope.temp.policy.ruleAlgorithmschoices = [];
192 if(!$scope.temp.policy.yamlparams){
193 $scope.temp.policy.yamlparams = {};
195 if(!$scope.temp.policy.yamlparams.targets){
196 $scope.temp.policy.yamlparams.targets = [];
198 if(!$scope.temp.policy.yamlparams.blackList){
199 $scope.temp.policy.yamlparams.blackList = [];
201 if(!$scope.temp.policy.rainyday){
202 $scope.temp.policy.rainyday = {};
204 if(!$scope.temp.policy.rainyday.treatmentTableChoices){
205 $scope.temp.policy.rainyday.treatmentTableChoices = [];
208 }else if($scope.temp.policy.ruleProvider=="Custom"){
209 if($scope.temp.policy.attributes.length == 0){
210 $scope.temp.policy.attributes = [];
212 if($scope.temp.policy.settings.length == 0){
213 $scope.temp.policy.settings = [];
215 if($scope.temp.policy.ruleAlgorithmschoices == null || $scope.temp.policy.ruleAlgorithmschoices.length == 0){
216 $scope.temp.policy.ruleAlgorithmschoices = [];
218 }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){
219 if($scope.temp.policy.yamlparams.blackList.length==0){
220 $scope.temp.policy.yamlparams.blackList = [];
222 }else if($scope.temp.policy.ruleProvider=="GUARD_YAML"){
223 if($scope.temp.policy.yamlparams.targets.length==0){
224 $scope.temp.policy.yamlparams.targets = [];
226 }else if($scope.temp.policy.ruleProvider=="Rainy_Day"){
227 if($scope.temp.policy.rainyday.treatmentTableChoices == null || $scope.temp.policy.rainyday.treatmentTableChoices.length == 0){
228 $scope.temp.policy.rainyday.treatmentTableChoices = [];
231 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
232 $scope.addNewChoice = function() {
233 var newItemNo = $scope.temp.policy.attributes.length+1;
234 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
236 $scope.removeChoice = function() {
237 var lastItem = $scope.temp.policy.attributes.length-1;
238 $scope.temp.policy.attributes.splice(lastItem);
241 $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
242 $scope.addNewSettingsChoice = function() {
243 var newItemNo = $scope.temp.policy.settings.length+1;
244 $scope.temp.policy.settings.push({'id':'choice'+newItemNo});
246 $scope.removeSettingsChoice = function() {
247 var lastItem = $scope.temp.policy.settings.length-1;
248 $scope.temp.policy.settings.splice(lastItem);
251 $scope.addNewTarget = function(){
252 $scope.temp.policy.yamlparams.targets.push('');
254 $scope.removeTarget = function(){
255 var lastItem = $scope.temp.policy.yamlparams.targets.length-1;
256 $scope.temp.policy.yamlparams.targets.splice(lastItem);
259 $scope.addNewBL = function() {
260 $scope.temp.policy.yamlparams.blackList.push('');
262 $scope.removeBL = function() {
263 var lastItem = $scope.temp.policy.yamlparams.blackList.length-1;
264 $scope.temp.policy.yamlparams.blackList.splice(lastItem);
267 $scope.treatmentDatas = [{"treatmentValues" : $scope.temp.policy.rainyday.treatmentTableChoices}];
268 $scope.addNewTreatment = function() {
269 $scope.temp.policy.rainyday.treatmentTableChoices.push({});
271 $scope.removeTreatment = function() {
272 var lastItem = $scope.temp.policy.rainyday.treatmentTableChoices.length-1;
273 $scope.temp.policy.rainyday.treatmentTableChoices.splice(lastItem);
276 $scope.workstepDictionaryDatas = [];
277 $scope.getWorkstepValues = function(bbidValue){
278 for (var i = 0; i < $scope.rainyDayDictionaryDataEntity.length; ++i) {
279 var obj = $scope.rainyDayDictionaryDataEntity[i];
280 if (obj.bbid == bbidValue){
281 $scope.workstepDictionaryDatas.push(obj.workstep);
286 $scope.allowedTreatmentsDatas = [];
287 $scope.getTreatmentValues = function(bbidValue, workstepValue){
288 for (var i = 0; i < $scope.rainyDayDictionaryDataEntity.length; ++i) {
289 var obj = $scope.rainyDayDictionaryDataEntity[i];
290 if (obj.bbid == bbidValue && obj.workstep == workstepValue){
291 var splitAlarm = obj.treatments.split(',');
292 for (var j = 0; j < splitAlarm.length; ++j) {
293 $scope.allowedTreatmentsDatas.push(splitAlarm[j]);
300 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
302 $scope.addNewRuleAlgorithm = function() {
303 if($scope.temp.policy.ruleAlgorithmschoices != null){
304 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
309 var value = newItemNo-1;
310 $scope.attributeDictionaryDatas.push('A'+value);
312 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
315 $scope.removeRuleAlgorithm = function() {
316 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
317 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
320 $scope.providerListener = function(ruleProvider) {
321 if (ruleProvider!="Custom"){
322 $scope.temp.policy.ruleAlgorithmschoices = [];
323 $scope.temp.policy.settings = [];
324 $scope.temp.policy.attributes = [];