[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / BRMSDependencyDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
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('editBRMSDependencyController', function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21     if(message.brmsDependencyDictionaryDatas==null)
22         $scope.label='Add New BRMS Dependency'
23     else{
24         if(message.disabled){
25                 $scope.label='View BRMS Dependency'
26         }else{
27                 $scope.label='Edit BRMS Dependency'
28         }
29         $scope.disableCd=true;
30     }
31     $scope.editBRMSDependency = message.brmsDependencyDictionaryDatas;
32     $scope.disabled = message.disabled;
33         
34         /*getting user info from session*/
35         var userid = null;
36         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
37                 .then(function (response) {                     
38                         userid = response.userid;               
39          });
40    
41         $scope.saveBRMSDependency = function(brmsDependencyDictionaryData) {
42                 var regex = new RegExp("^[a-zA-Z0-9_]*$");
43                 if(!regex.test(brmsDependencyDictionaryData.dependencyName)) {
44                         Notification.error("Enter Valid Dependency Name without spaces or special characters");
45                 }else{
46                         var uuu = "saveDictionary/brms_dictionary/save_BRMSDependencyData";
47                         var postData={brmsDependencyDictionaryData: brmsDependencyDictionaryData, userid: userid};
48                         if(brmsDependencyDictionaryData && brmsDependencyDictionaryData.dependencyName){
49                                 if(brmsDependencyDictionaryData.dependency){
50                                         $.ajax({
51                                                 type : 'POST',
52                                                 url : uuu,
53                                                 dataType: 'json',
54                                                 contentType: 'application/json',
55                                                 data: JSON.stringify(postData),
56                                                 success : function(data){
57                                                         $scope.$apply(function(){
58                                                                 $scope.brmsDependencyDictionaryDatas=data.brmsDependencyDictionaryDatas;});
59                                                         if($scope.brmsDependencyDictionaryDatas == "Duplicate"){
60                                                                 Notification.error("BRMS Dependency Dictionary exists with Same Dependency Name.")
61                                                         }else if($scope.brmsDependencyDictionaryDatas == "Error"){
62                                                                 Notification.error("BRMS Dependency is not in proper format Maven dependency Format");
63                                                         }else{
64                                                                 console.log($scope.brmsDependencyDictionaryDatas);
65                                                                 $modalInstance.close({brmsDependencyDictionaryDatas:$scope.brmsDependencyDictionaryDatas});
66                                                         }
67                                                 },
68                                                 error : function(data){
69                                                         alert("Error while saving.");
70                                                 }
71                                         });
72                                 }else{
73                                         Notification.error("Dependency Field is Empty.");
74                                 }
75                         }else{
76                                 Notification.error("BRMS Dependency Name should be given.");
77                         }
78                 }
79         };
80
81     $scope.close = function() {
82         $modalInstance.close();
83     };
84 });