8492a96d311c9d94f0386d49ef9d509a8df316b8
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / MSHeaderDefaultValuesDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2018, 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('editMSHeaderDefaultValuesController' ,  function ($scope, $modalInstance, message, PolicyAppService, UserInfoServiceDS2, Notification){
21            if(message.modelAttributeDictionaryData==null)
22                 $scope.label='Set Header Default Values'
23             else{
24                 $scope.label='Edit Header Default Values'
25                 $scope.disableCd=true;
26             }
27
28             PolicyAppService.getData('getDictionary/get_MicroServiceHeaderDefaultsData').then(function (data) {
29                 var j = data;
30                 $scope.data = JSON.parse(j.data);
31                 console.log($scope.data);
32                 $scope.microServiceHeaderDefaultDatas = JSON.parse($scope.data.microServiceHeaderDefaultDatas);
33                 console.log("microServiceHeaderDefaultDatas:" + $scope.microServiceHeaderDefaultDatas);
34             }, function (error) {
35                 console.log("failed");
36             });
37
38             PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataServiceVersion').then(function (data) {
39                 var j = data;
40                 $scope.data = JSON.parse(j.data);
41                 console.log($scope.data);
42                 $scope.microServiceModelsDictionaryDatas = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
43                 console.log($scope.microServiceModelsDictionaryDatas);
44             }, function (error) {
45                 console.log("failed");
46             });
47             
48                 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
49                         var j = data;
50                         $scope.data = JSON.parse(j.data);
51                         console.log("riskTypeDictionaryDatas = " + $scope.data);
52                         $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
53                         console.log($scope.riskTypeDictionaryDatas);
54                 }, function (error) {
55                         console.log("failed");
56                 });
57
58                 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
59                         var j = data;
60                         $scope.data = JSON.parse(j.data);
61                         console.log("riskTypeDictionaryDatas: " + $scope.data);
62                         $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
63                         console.log($scope.riskTypeDictionaryDatas);
64                 }, function (error) {
65                         console.log("failed");
66                 });
67                 
68                 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
69                         var j = data;
70                         $scope.data = JSON.parse(j.data);
71                         console.log($scope.data);
72                         $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
73                         console.log($scope.onapNameDictionaryDatas);
74                 }, function (error) {
75                         console.log("failed");
76                 });
77
78                 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
79                         var j = data;
80                         $scope.data = JSON.parse(j.data);
81                         console.log($scope.data);
82                         $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
83                         console.log($scope.priorityDatas);
84                 }, function (error) {
85                         console.log("failed");
86                 });
87                                 
88                 /*getting user info from session*/
89                 var userid = null;
90                 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
91                         .then(function (response) {                     
92                                 userid = response.userid;               
93                  });
94                 
95             $scope.editHeaderDefaults = message.modelAttributeDictionaryData;
96             $scope.editModelAttribute1 = {microservice: []};
97             if($scope.edit){
98                 if(message.modelAttributeDictionaryData.groupList != null){
99                         var splitValue = message.modelAttributeDictionaryData.groupList.split(",");
100                         console.log(splitValue);
101                 }       
102             }
103             $scope.saveHeaderDefaults = function(editHeaderDefaultsData) {
104                 console.log("editHeaderDefaultsData :" + editHeaderDefaultsData);
105                 var uuu = "saveDictionary/ms_dictionary/save_headerDefaults";
106                 var postData={modelAttributeDictionaryData: editHeaderDefaultsData, userid: userid};
107                 $.ajax({
108                                 type : 'POST',
109                                 url : uuu,
110                                 dataType: 'json',
111                                 contentType: 'application/json',
112                                 data: JSON.stringify(postData),
113                                 success : function(data){
114                                         $scope.$apply(function(){
115                                                 $scope.microServiceHeaderDefaultDatas=data.microServiceHeaderDefaultDatas;});
116                                             console.log("microServiceHeaderDefaultDatas returned after saved: " + $scope.microServiceHeaderDefaultDatas);
117                                         if($scope.microServiceAttributeDictionaryDatas == "Duplicate"){
118                                                 Notification.error("Model Attribute Dictionary exists with Same Attribute Name.")
119                                         }else{      
120                                                 console.log($scope.microServiceHeaderDefaultDatas);
121                                                 $modalInstance.close({microServiceHeaderDefaultDatas:$scope.microServiceHeaderDefaultDatas});
122                                         }
123                                 },
124                                 error : function(data){
125                                         Notification.error("Error while saving.");
126                                 }
127                 });
128                 
129             };
130
131             $scope.close = function() {
132                 $modalInstance.close();
133             };
134         });