Remove unused vars and methods
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / BRMSParamDictController.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('editBRMSParamController' , function ($scope, $modalInstance, message, $http, UserInfoServiceDS2, Notification){
21     if(message.brmsParamDictionaryData==null)
22         $scope.label='Add BRMS Rule'
23     else{
24         $scope.label='Edit BRMS Rule'
25         $scope.disableCd=true;
26     }
27    
28         
29         /*getting user info from session*/
30         var userid = null;
31         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
32                 .then(function (response) {                     
33                         userid = response.userid;               
34          });
35         
36         var valid = true;
37     $scope.editBRMSParam = message.brmsParamDictionaryData;
38     
39     $scope.uploadFile = function(files) {
40         var extn = files[0].name.substr(files[0].name.lastIndexOf('.')+1);
41         if(extn == 'drl'){
42                 valid = true;
43                    var fd = new FormData();
44                 fd.append("file", files[0]);
45                 $http.post("saveDictionary/brms_dictionary/set_BRMSParamData", fd, {
46                     withCredentials: false,
47                     headers: {'Content-Type': undefined },
48                     transformRequest: angular.identity
49                 }).success().error( );
50         }else{
51                 Notification.error("BRMS Dictionary Upload file should ends with .drl extension");
52                 valid = false;
53         }
54     };
55         
56     $scope.MyFile = [];
57     $scope.saveBRMSParam = function(brmsParamDictionaryData) {
58         if(valid){
59                 var regex = new RegExp("^[a-zA-Z0-9_]*$");
60                 if(!regex.test(brmsParamDictionaryData.ruleName)) {
61                         Notification.error("Enter Valid Rule Name without spaces or special characters");
62                 }else{
63                 var uuu = "saveDictionary/brms_dictionary/save_BRMSParam";
64                 var postData={brmsParamDictionaryData: brmsParamDictionaryData, userid: userid};
65                 $.ajax({
66                     type : 'POST',
67                     url : uuu,
68                     dataType: 'json',
69                     contentType: 'application/json',
70                     data: JSON.stringify(postData),
71                     success : function(data){
72                         $scope.$apply(function(){
73                             $scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;});
74                                                 if($scope.brmsParamDictionaryDatas == "Duplicate"){
75                                                         Notification.error("BRMSParan Dictionary exists with Same Name.")
76                                                 }else if($scope.brmsParamDictionaryDatas == "Validation"){
77                                                         Notification.error("BRMSParan Dictionary failed rule Validation.")
78                                                 }else {
79                                                         console.log($scope.brmsParamDictionaryDatas);
80                                                         $modalInstance.close({brmsParamDictionaryDatas:$scope.brmsParamDictionaryDatas});
81                                                 }
82                     },
83                     error : function(data){
84                         Notification.error("Error while saving.");
85                     }
86                 });
87                 }
88         }else{
89                 Notification.error("Please check BRMS Rule Upload file format.");
90         }
91     };
92
93     $scope.close = function() {
94         $modalInstance.close();
95     };
96 });