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('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 $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 $('#ttlDate').datepicker({
40 dateFormat: 'dd/mm/yy',
43 onSelect: function(date) {
44 angular.element($('#ttlDate')).triggerHandler('input');
48 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
50 $scope.data = JSON.parse(j.data);
51 console.log($scope.data);
52 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
53 console.log($scope.onapNameDictionaryDatas);
55 console.log("failed");
58 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
60 $scope.data = JSON.parse(j.data);
61 console.log($scope.data);
62 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
63 console.log($scope.riskTypeDictionaryDatas);
65 console.log("failed");
69 PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
74 if($scope.temp.policy.readOnly && $scope.temp.policy.editPolicy){
75 $scope.temp.policy.verticaMetrics = [];
76 $scope.temp.policy.description = [];
77 $scope.temp.policy.attributes = [];
80 $scope.addDataToFields = function(serviceType){
81 if($scope.PMData == undefined){
82 $scope.temp.policy.verticaMetrics = [];
83 $scope.temp.policy.description = [];
84 $scope.temp.policy.attributes = [];
85 PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
88 if(serviceType.serviceTypePolicyName == 'Registration Failure(Trinity)'){
89 var myNewData = $scope.PMData[0];
90 }else if(serviceType.serviceTypePolicyName == 'International Fraud(Trinity)'){
91 var myNewData = $scope.PMData[1];
92 }else if(serviceType.serviceTypePolicyName == 'No dial tone(Trinity)'){
93 var myNewData = $scope.PMData[2];
94 }else if(serviceType.serviceTypePolicyName == 'Call storm(Trinity)'){
95 var myNewData = $scope.PMData[3];
96 }else if(serviceType.serviceTypePolicyName == 'Registration storm(Trinity)'){
97 var myNewData = $scope.PMData[4];
100 $scope.temp.policy.verticaMetrics = myNewData;
101 $scope.temp.policy.description = myNewData;
102 $scope.temp.policy.attributeFields = myNewData;
105 $scope.temp.policy.verticaMetrics = serviceType;
106 $scope.temp.policy.description = serviceType;
107 $scope.temp.policy.attributeFields = serviceType;
112 $scope.saveCLPMPolicy = function(policy){
113 if(policy.itemContent != undefined){
114 $scope.refreshCheck = true;
115 $scope.policyNavigator = policy.itemContent;
116 policy.itemContent = "";
118 $scope.savebutton = false;
119 var uuu = "policycreation/save_policy";
120 var postData={policyData: policy};
125 contentType: 'application/json',
126 data: JSON.stringify(postData),
127 success : function(data){
128 $scope.$apply(function(){
129 $scope.data=data.policyData;
130 if($scope.data == 'success'){
131 $scope.temp.policy.readOnly = 'true';
132 Notification.success("Policy Saved Successfully.");
133 }else if ($scope.data == 'PolicyExists'){
134 $scope.savebutton = true;
135 Notification.error("Policy Already Exists with Same Name in Scope.");
138 console.log($scope.data);
140 error : function(data){
141 Notification.error("Error Occured while saving Policy.");
146 $scope.validatePolicy = function(policy){
148 document.getElementById("validate").innerHTML = "";
149 var uuu = "policyController/validate_policy.htm";
150 var postData={policyData: policy};
155 contentType: 'application/json',
156 data: JSON.stringify(postData),
157 success : function(data){
158 $scope.$apply(function(){
159 $scope.validateData = data.data.replace(/\"/g, "");
160 $scope.data=data.data.substring(1,8);
161 var size = data.data.length;
162 if($scope.data == 'success'){
163 Notification.success("Validation Success.");
164 $scope.savebutton = false;
166 var displayWarning = data.data.substring(19,size);
167 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
168 document.getElementById("validate").style.color = "white";
169 document.getElementById("validate").style.backgroundColor = "skyblue";
172 Notification.error("Validation Failed.");
173 document.getElementById("validate").innerHTML = $scope.validateData;
174 document.getElementById("validate").style.color = "white";
175 document.getElementById("validate").style.backgroundColor = "red";
176 $scope.savebutton = true;
180 console.log($scope.data);
182 error : function(data){
183 Notification.error("Validation Failed.");
184 $scope.savebutton = true;