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('brmsRawPolicyController', function ($scope, $window, PolicyAppService, modalService, $modal, Notification) {
23 $scope.savebutton = true;
24 $scope.finalPath = null;
26 PolicyAppService.getData('getDictionary/get_BRMSControllerDataByName').then(function (data) {
28 $scope.data = JSON.parse(j.data);
29 console.log($scope.data);
30 $scope.brmsControllerDatas = JSON.parse($scope.data.brmsControllerDictionaryDatas);
31 console.log($scope.brmsControllerDatas);
33 console.log("failed");
36 PolicyAppService.getData('getDictionary/get_BRMSDependencyDataByName').then(function (data) {
38 $scope.data = JSON.parse(j.data);
39 console.log($scope.data);
40 $scope.brmsDependencyDatas = JSON.parse($scope.data.brmsDependencyDictionaryDatas);
41 console.log($scope.brmsDependencyDatas);
43 console.log("failed");
46 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
48 $scope.data = JSON.parse(j.data);
49 console.log($scope.data);
50 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
51 console.log($scope.riskTypeDictionaryDatas);
53 console.log("failed");
56 $scope.saveBrmsRawPolicy = function(policy){
58 $scope.savebutton = false;
59 var uuu = "policycreation/save_policy";
60 var postData={policyData: policy};
65 contentType: 'application/json',
66 data: JSON.stringify(postData),
67 success : function(data){
68 $scope.$apply(function(){
69 $scope.data=data.policyData;
70 if($scope.data == 'success'){
71 $scope.temp.policy.readOnly = 'true';
72 Notification.success("Policy Saved Successfully.");
73 }else if ($scope.data == 'PolicyExists'){
74 $scope.savebutton = true;
75 Notification.error("Policy Already Exists with Same Name in Scope.");
78 console.log($scope.data);
80 error : function(data){
81 Notification.error("Error Occured while saving Policy.");
82 $scope.savebutton = true;
87 $scope.validatePolicy = function(policy){
89 document.getElementById("validate").innerHTML = "";
90 var uuu = "policyController/validate_policy.htm";
91 var postData={policyData: policy};
96 contentType: 'application/json',
97 data: JSON.stringify(postData),
98 success : function(data){
99 $scope.$apply(function(){
100 $scope.validateData = data.data.replace(/\"/g, "");
101 $scope.data=data.data.substring(1,8);
102 var size = data.data.length;
103 if($scope.data == 'success'){
104 Notification.success("Validation Success.");
105 $scope.savebutton = false;
107 var displayWarning = data.data.substring(19,size);
108 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
109 document.getElementById("validate").style.color = "white";
110 document.getElementById("validate").style.backgroundColor = "skyblue";
113 Notification.error("Validation Failed.");
114 document.getElementById("validate").innerHTML = $scope.validateData;
115 document.getElementById("validate").style.color = "white";
116 document.getElementById("validate").style.backgroundColor = "red";
117 $scope.savebutton = true;
121 console.log($scope.data);
123 error : function(data){
124 Notification.error("Validation Failed.");
129 function extend(obj, src) {
130 for (var key in src) {
131 if (src.hasOwnProperty(key)) obj[key] = src[key];
136 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
137 $scope.temp.policy.attributes = [];
139 if($scope.temp.policy.attributes.length == 0){
140 $scope.temp.policy.attributes = [];
143 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
144 $scope.addNewChoice = function() {
145 var newItemNo = $scope.temp.policy.attributes.length+1;
146 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
148 $scope.removeChoice = function() {
149 var lastItem = $scope.temp.policy.attributes.length-1;
150 $scope.temp.policy.attributes.splice(lastItem);