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 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
41 $scope.data = JSON.parse(j.data);
42 console.log($scope.data);
43 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
44 console.log($scope.onapNameDictionaryDatas);
46 console.log("failed");
49 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
54 console.log($scope.riskTypeDictionaryDatas);
56 console.log("failed");
60 PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
65 if($scope.temp.policy.readOnly && $scope.temp.policy.editPolicy){
66 $scope.temp.policy.verticaMetrics = [];
67 $scope.temp.policy.description = [];
68 $scope.temp.policy.attributes = [];
71 $scope.addDataToFields = function(serviceType){
72 if($scope.PMData == undefined){
73 $scope.temp.policy.verticaMetrics = [];
74 $scope.temp.policy.description = [];
75 $scope.temp.policy.attributes = [];
76 PolicyAppService.getData('app/policyApp/JSONDataFiles/JSONConfig.json').then(function(data){
79 if(serviceType.serviceTypePolicyName == 'Registration Failure(Trinity)'){
80 var myNewData = $scope.PMData[0];
81 }else if(serviceType.serviceTypePolicyName == 'International Fraud(Trinity)'){
82 var myNewData = $scope.PMData[1];
83 }else if(serviceType.serviceTypePolicyName == 'No dial tone(Trinity)'){
84 var myNewData = $scope.PMData[2];
85 }else if(serviceType.serviceTypePolicyName == 'Call storm(Trinity)'){
86 var myNewData = $scope.PMData[3];
87 }else if(serviceType.serviceTypePolicyName == 'Registration storm(Trinity)'){
88 var myNewData = $scope.PMData[4];
91 $scope.temp.policy.verticaMetrics = myNewData;
92 $scope.temp.policy.description = myNewData;
93 $scope.temp.policy.attributeFields = myNewData;
96 $scope.temp.policy.verticaMetrics = serviceType;
97 $scope.temp.policy.description = serviceType;
98 $scope.temp.policy.attributeFields = serviceType;
103 $scope.saveCLPMPolicy = function(policy){
104 if(policy.itemContent != undefined){
105 $scope.refreshCheck = true;
106 $scope.policyNavigator = policy.itemContent;
107 policy.itemContent = "";
109 $scope.savebutton = false;
110 var uuu = "policycreation/save_policy";
111 var postData={policyData: policy};
116 contentType: 'application/json',
117 data: JSON.stringify(postData),
118 success : function(data){
119 $scope.$apply(function(){
120 $scope.data=data.policyData;
121 if($scope.data == 'success'){
122 $scope.temp.policy.readOnly = 'true';
123 Notification.success("Policy Saved Successfully.");
124 }else if ($scope.data == 'PolicyExists'){
125 $scope.savebutton = true;
126 Notification.error("Policy Already Exists with Same Name in Scope.");
129 console.log($scope.data);
131 error : function(data){
132 Notification.error("Error Occured while saving Policy.");
137 $scope.validatePolicy = function(policy){
139 document.getElementById("validate").innerHTML = "";
140 var uuu = "policyController/validate_policy.htm";
141 var postData={policyData: policy};
146 contentType: 'application/json',
147 data: JSON.stringify(postData),
148 success : function(data){
149 $scope.$apply(function(){
150 $scope.validateData = data.data.replace(/\"/g, "");
151 $scope.data=data.data.substring(1,8);
152 var size = data.data.length;
153 if($scope.data == 'success'){
154 Notification.success("Validation Success.");
155 $scope.savebutton = false;
157 var displayWarning = data.data.substring(19,size);
158 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
159 document.getElementById("validate").style.color = "white";
160 document.getElementById("validate").style.backgroundColor = "skyblue";
163 Notification.error("Validation Failed.");
164 document.getElementById("validate").innerHTML = $scope.validateData;
165 document.getElementById("validate").style.color = "white";
166 document.getElementById("validate").style.backgroundColor = "red";
167 $scope.savebutton = true;
171 console.log($scope.data);
173 error : function(data){
174 Notification.error("Validation Failed.");
175 $scope.savebutton = true;