2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 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('clPMController', ['$scope', '$window', '$timeout', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function($scope, $window, $timeout, 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 : "Config",
30 configPolicyType : "ClosedLoop_PM"
34 $scope.refresh = function(){
35 if($scope.refreshCheck){
36 $scope.policyNavigator.refresh();
38 $scope.modal('createNewPolicy', true);
39 $scope.temp.policy = "";
42 $scope.modal = function(id, hide) {
43 return $('#' + id).modal(hide ? 'hide' : 'show');
46 $('#ttlDate').datepicker({
47 dateFormat: 'dd/mm/yy',
50 onSelect: function(date) {
51 angular.element($('#ttlDate')).triggerHandler('input');
55 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
60 console.log($scope.onapNameDictionaryDatas);
62 console.log("failed");
65 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
67 $scope.data = JSON.parse(j.data);
68 console.log($scope.data);
69 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
70 console.log($scope.riskTypeDictionaryDatas);
72 console.log("failed");
76 PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
81 if($scope.temp.policy.readOnly && $scope.temp.policy.editPolicy){
82 $scope.temp.policy.verticaMetrics = [];
83 $scope.temp.policy.description = [];
84 $scope.temp.policy.attributes = [];
87 $scope.addDataToFields = function(serviceType){
88 if($scope.PMData == undefined){
89 $scope.temp.policy.verticaMetrics = [];
90 $scope.temp.policy.description = [];
91 $scope.temp.policy.attributes = [];
92 PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
95 if(serviceType.serviceTypePolicyName == 'Registration Failure(Trinity)'){
96 var myNewData = $scope.PMData[0];
97 }else if(serviceType.serviceTypePolicyName == 'International Fraud(Trinity)'){
98 var myNewData = $scope.PMData[1];
99 }else if(serviceType.serviceTypePolicyName == 'No dial tone(Trinity)'){
100 var myNewData = $scope.PMData[2];
101 }else if(serviceType.serviceTypePolicyName == 'Call storm(Trinity)'){
102 var myNewData = $scope.PMData[3];
103 }else if(serviceType.serviceTypePolicyName == 'Registration storm(Trinity)'){
104 var myNewData = $scope.PMData[4];
107 $scope.temp.policy.verticaMetrics = myNewData;
108 $scope.temp.policy.description = myNewData;
109 $scope.temp.policy.attributeFields = myNewData;
112 $scope.temp.policy.verticaMetrics = serviceType;
113 $scope.temp.policy.description = serviceType;
114 $scope.temp.policy.attributeFields = serviceType;
119 $scope.saveCLPMPolicy = function(policy){
120 if(policy.itemContent != undefined){
121 $scope.refreshCheck = true;
122 $scope.policyNavigator = policy.itemContent;
123 policy.itemContent = "";
125 $scope.savebutton = false;
126 var uuu = "policycreation/save_policy";
127 var postData={policyData: policy};
132 contentType: 'application/json',
133 data: JSON.stringify(postData),
134 success : function(data){
135 $scope.$apply(function(){
136 $scope.data=data.policyData;
137 if($scope.data == 'success'){
138 $scope.temp.policy.readOnly = 'true';
139 Notification.success("Policy Saved Successfully.");
140 }else if ($scope.data == 'PolicyExists'){
141 $scope.savebutton = true;
142 Notification.error("Policy Already Exists with Same Name in Scope.");
145 console.log($scope.data);
147 error : function(data){
148 Notification.error("Error Occured while saving Policy.");
153 $scope.validatePolicy = function(policy){
155 document.getElementById("validate").innerHTML = "";
156 var uuu = "policyController/validate_policy.htm";
157 var postData={policyData: policy};
162 contentType: 'application/json',
163 data: JSON.stringify(postData),
164 success : function(data){
165 $scope.$apply(function(){
166 $scope.validateData = data.data.replace(/\"/g, "");
167 $scope.data=data.data.substring(1,8);
168 var size = data.data.length;
169 if($scope.data == 'success'){
170 Notification.success("Validation Success.");
171 $scope.savebutton = false;
173 var displayWarning = data.data.substring(19,size);
174 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
175 document.getElementById("validate").style.color = "white";
176 document.getElementById("validate").style.backgroundColor = "skyblue";
179 Notification.error("Validation Failed.");
180 document.getElementById("validate").innerHTML = $scope.validateData;
181 document.getElementById("validate").style.color = "white";
182 document.getElementById("validate").style.backgroundColor = "red";
183 $scope.savebutton = true;
187 console.log($scope.data);
189 error : function(data){
190 Notification.error("Validation Failed.");
191 $scope.savebutton = true;