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     }else if($scope.temp.policy.ruleProvider=="Custom"){
 
 169            if($scope.temp.policy.attributes.length == 0){
 
 170                    $scope.temp.policy.attributes = [];
 
 172            if($scope.temp.policy.settings.length == 0){
 
 173                    $scope.temp.policy.settings = [];
 
 175            if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
 
 176                    $scope.temp.policy.ruleAlgorithmschoices = [];
 
 179     $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
 
 180     $scope.addNewChoice = function() {
 
 181       var newItemNo = $scope.temp.policy.attributes.length+1;
 
 182       $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
 
 184     $scope.removeChoice = function() {
 
 185       var lastItem = $scope.temp.policy.attributes.length-1;
 
 186       $scope.temp.policy.attributes.splice(lastItem);
 
 190     $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
 
 191     $scope.addNewSettingsChoice = function() {
 
 192       var newItemNo = $scope.temp.policy.settings.length+1;
 
 193       $scope.temp.policy.settings.push({'id':'choice'+newItemNo});
 
 195     $scope.removeSettingsChoice = function() {
 
 196       var lastItem = $scope.temp.policy.settings.length-1;
 
 197       $scope.temp.policy.settings.splice(lastItem);
 
 201     $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
 
 203     $scope.addNewRuleAlgorithm = function() {
 
 204         if($scope.temp.policy.ruleAlgorithmschoices != null){
 
 205                 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
 
 210                 var value = newItemNo-1;
 
 211                 $scope.attributeDictionaryDatas.push('A'+value);
 
 213         $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
 
 216     $scope.removeRuleAlgorithm = function() {
 
 217       var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
 
 218       $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
 
 221     $scope.providerListener = function(ruleProvider) {
 
 222         if (ruleProvider!="Custom"){
 
 223                 $scope.temp.policy.ruleAlgorithmschoices  = [];
 
 224                 $scope.temp.policy.settings = [];
 
 225                 $scope.temp.policy.attributes = [];