Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryController / MSModelsDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP 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('editMSModelController' ,  function ($scope, $modalInstance, message, $http, UserInfoServiceDS2, Notification){
21     if(message.microServiceModelsDictionaryData==null)
22         $scope.label='Add Micro Service Model'
23     else{
24         $scope.label='Edit Micro Service Model'
25         $scope.disableCd=true;
26     }
27         
28         /*getting user info from session*/
29         var userid = null;
30         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
31                 .then(function (response) {                     
32                         userid = response.userid;               
33          });
34         
35         var valid = true;
36     $scope.editMSmodelName = message.microServiceModelsDictionaryData;
37
38     $scope.uploadFile = function(files) {
39         var extn = files[0].name.substr(files[0].name.lastIndexOf('.')+1);
40         if(extn == 'zip' || extn == 'xmi'){
41                 valid = true;
42                 var fd = new FormData();
43                 fd.append("file", files[0]);
44                 $http.post("ms_dictionary/set_MSModelData", fd, {
45                         withCredentials: false,
46                         headers: {'Content-Type': undefined },
47                         transformRequest: angular.identity
48                 }).success(function(data){
49                 if(data.classListDatas  == "EMPTY"){
50                         Notification.error("No Micro Services Avaialble.")
51                 }else{      
52                         $scope.classListDatas=data.classListDatas;
53                         $scope.modalDatas = data.modelDatas;
54                         console.log($scope.classListDatas);
55                 }
56             }).error( );
57         }else{
58                 Notification.error("Micro Service Model Upload file should ends with .zip or .xmi extension");
59                 valid = false;
60         }
61
62     };
63     
64     $scope.saveMSModel = function(microServiceModelsDictionaryData) {
65         if(valid){
66                  var uuu = "saveDictionary/ms_dictionary/save_model";
67                 var postData={microServiceModelsDictionaryData: microServiceModelsDictionaryData, userid: userid, classMap: $scope.modalDatas};
68                 $.ajax({
69                     type : 'POST',
70                     url : uuu,
71                     dataType: 'json',
72                     contentType: 'application/json',
73                     data: JSON.stringify(postData),
74                     success : function(data){
75                         $scope.$apply(function(){
76                             $scope.microServiceModelsDictionaryDatas=data.microServiceModelsDictionaryDatas;});
77                         if($scope.microServiceModelsDictionaryDatas == "Duplicate"){
78                                 Notification.error("MS Models Dictionary exists with Same Model Name.")
79                         }else{      
80                                 console.log($scope.microServiceModelsDictionaryDatas);
81                             $modalInstance.close({microServiceModelsDictionaryDatas:$scope.microServiceModelsDictionaryDatas});
82                         }
83                     },
84                     error : function(data){
85                         Notification.error("Error while saving.");
86                     }
87                 });
88         }else{
89                 Notification.error("Please check Micro Service Model Upload file format.");
90         }
91        
92     };
93
94     $scope.close = function() {
95         $modalInstance.close();
96     };
97 });