[POLICY-67] Add new Rainy Day Decision Policy
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / DecisionPolicyController.js
index ce27e04..4b5a990 100644 (file)
@@ -80,8 +80,6 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA
                console.log("failed");
        });
 
-       
-
     function extend(obj, src) {
         for (var key in src) {
             if (src.hasOwnProperty(key)) obj[key] = src[key];
@@ -163,8 +161,21 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA
    
     if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
        $scope.temp.policy.attributes = [];
-         $scope.temp.policy.settings = [];
-        $scope.temp.policy.ruleAlgorithmschoices = [];
+       $scope.temp.policy.settings = [];
+       $scope.temp.policy.ruleAlgorithmschoices = [];
+       if(!$scope.temp.policy.yamlparams){
+               $scope.temp.policy.yamlparams = {};
+       }
+       if(!$scope.temp.policy.yamlparams.blackList){
+               $scope.temp.policy.yamlparams.blackList = [];
+       }
+       if(!$scope.temp.policy.rainyday){
+               $scope.temp.policy.rainyday = {};
+       }
+       if(!$scope.temp.policy.rainyday.treatmentTableChoices){
+               $scope.temp.policy.rainyday.treatmentTableChoices = [];
+       }
+    
     }else if($scope.temp.policy.ruleProvider=="Custom"){
           if($scope.temp.policy.attributes.length == 0){
                   $scope.temp.policy.attributes = [];
@@ -172,10 +183,18 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA
           if($scope.temp.policy.settings.length == 0){
                   $scope.temp.policy.settings = [];
           }
-          if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
+          if($scope.temp.policy.ruleAlgorithmschoices == null || $scope.temp.policy.ruleAlgorithmschoices.length == 0){
                   $scope.temp.policy.ruleAlgorithmschoices = [];
           }
-   }
+    }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){
+          if($scope.temp.policy.yamlparams.blackList.length==0){
+                  $scope.temp.policy.yamlparams.blackList = [];
+          }
+    }else if($scope.temp.policy.ruleProvider=="Rainy_Day"){
+       if($scope.temp.policy.rainyday.treatmentTableChoices == null || $scope.temp.policy.rainyday.treatmentTableChoices.length == 0){
+               $scope.temp.policy.rainyday.treatmentTableChoices = [];
+       }
+    }
     $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
     $scope.addNewChoice = function() {
       var newItemNo = $scope.temp.policy.attributes.length+1;
@@ -186,7 +205,6 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA
       $scope.temp.policy.attributes.splice(lastItem);
     };
     
-  
     $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
     $scope.addNewSettingsChoice = function() {
       var newItemNo = $scope.temp.policy.settings.length+1;
@@ -197,6 +215,23 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA
       $scope.temp.policy.settings.splice(lastItem);
     };
     
+    $scope.addNewBL = function() {
+       $scope.temp.policy.yamlparams.blackList.push('');
+    };
+    $scope.removeBL = function() {
+       var lastItem = $scope.temp.policy.yamlparams.blackList.length-1;
+       $scope.temp.policy.yamlparams.blackList.splice(lastItem);
+    };
+    
+    $scope.treatmentDatas = [{"treatmentValues" : $scope.temp.policy.rainyday.treatmentTableChoices}];
+    $scope.addNewTreatment = function() {
+       $scope.temp.policy.rainyday.treatmentTableChoices.push({});
+    };
+    $scope.removeTreatment = function() {
+       var lastItem = $scope.temp.policy.rainyday.treatmentTableChoices.length-1;
+       $scope.temp.policy.rainyday.treatmentTableChoices.splice(lastItem);
+    };
+    
     $scope.ItemNo = 0;
     $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];