Fixed Sonar issues for Console Logs
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / PSGroupPolicyScopeDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 app.controller('editPSGroupPolicyScopeController' ,  
21     function ($scope, $modalInstance, message, PolicyAppService, UserInfoServiceDS2, Notification){
22     $scope.edit = false;
23     if(message.groupPolicyScopeListData==null)
24         $scope.label='Add New Group Policy Scope'
25     else{
26         $scope.label='Edit Group Policy Scope'
27         $scope.disableCd=true;
28         $scope.edit = true;
29     }
30         
31     PolicyAppService.getData('getDictionary/get_PSServiceDataByName').then(function (data) {
32         var j = data;
33         $scope.data = JSON.parse(j.data);
34         $scope.psServiceDictionaryDatas = JSON.parse($scope.data.psServiceDictionaryDatas);
35     });
36
37     PolicyAppService.getData('getDictionary/get_PSTypeDataByName').then(function (data) {
38         var j = data;
39         $scope.data = JSON.parse(j.data);
40         $scope.psTypeDictionaryDatas = JSON.parse($scope.data.psTypeDictionaryDatas);
41     });
42
43     PolicyAppService.getData('getDictionary/get_PSResourceDataByName').then(function (data) {
44         var j = data;
45         $scope.data = JSON.parse(j.data);
46         $scope.psResourceDictionaryDatas = JSON.parse($scope.data.psResourceDictionaryDatas);
47     });
48
49     PolicyAppService.getData('getDictionary/get_PSClosedLoopDataByName').then(function (data) {
50         var j = data;
51         $scope.data = JSON.parse(j.data);
52         $scope.psClosedLoopDictionaryDatas = JSON.parse($scope.data.psClosedLoopDictionaryDatas);
53     });
54     
55     /*getting user info from session*/
56     var userid = null;
57     UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
58           .then(function (response) {              
59               userid = response.userid;          
60      });
61    
62     $scope.editPSGroupPolicyScope = message.groupPolicyScopeListData;
63     $scope.editPSGroupPolicyScope1 = {resource: [], type:[], service: [], closedloop: []};
64     if($scope.edit){
65         if(message.groupPolicyScopeListData.groupList != null){
66             var splitValue = message.groupPolicyScopeListData.groupList.split(",");
67             $scope.splittedGroupListValues = [];
68             var splitResource = splitValue[0].split("=");
69             $scope.editPSGroupPolicyScope1.resource.push(splitResource[1]);
70             var splitType = splitValue[1].split("=");
71             $scope.editPSGroupPolicyScope1.type.push(splitType[1]);
72             var splitService = splitValue[2].split("=");
73             $scope.editPSGroupPolicyScope1.service.push(splitService[1]);
74             var splitCloop = splitValue[3].split("=");
75             $scope.editPSGroupPolicyScope1.closedloop.push(splitCloop[1]);
76         }    
77     }
78     
79     $scope.savePSGroupPolicyScope = function(groupPolicyScopeListData, groupPolicyScopeListData1) {
80         var regex = new RegExp("^[a-zA-Z0-9_]*$");
81         if(!regex.test(groupPolicyScopeListData.groupName)) {
82             Notification.error("Enter Valid Policy Scope Group Name without spaces or special characters");
83         }else{
84             if(groupPolicyScopeListData1.resource[0] != undefined && groupPolicyScopeListData1.type[0] != undefined && groupPolicyScopeListData1.service[0] != undefined && groupPolicyScopeListData1.closedloop[0] != undefined){
85                 var uuu = "saveDictionary/ps_dictionary/save_psGroupPolicyScope";
86                 var postData={groupPolicyScopeListData: groupPolicyScopeListData,
87                         groupPolicyScopeListData1: groupPolicyScopeListData1, userid: userid};
88                 $.ajax({
89                     type : 'POST',
90                     url : uuu,
91                     dataType: 'json',
92                     contentType: 'application/json',
93                     data: JSON.stringify(postData),
94                     success : function(data){
95                         $scope.$apply(function(){
96                             $scope.groupPolicyScopeListDatas=data.groupPolicyScopeListDatas;});
97                         if($scope.groupPolicyScopeListDatas == "Duplicate"){
98                             Notification.error("GroupPolicyScope Dictionary exists with Same Group Name.")
99                         }else if($scope.groupPolicyScopeListDatas == "DuplicateGroup"){
100                             Notification.error("GroupPolicyScope Dictionary exists with Same Group List.")
101                         }else{      
102                             $modalInstance.close({groupPolicyScopeListDatas:$scope.groupPolicyScopeListDatas});
103                         }
104                     },
105                     error : function(data){
106                         Notification.error("Error while saving.");
107                     }
108                 });
109             }else{
110                 Notification.error("Please Select all the required fields to Save");
111             }
112         }
113     };
114
115     $scope.close = function() {
116         $modalInstance.close();
117     };
118 });