bbe2c3b55c7cb44bed0e75b6373d6381e6a17d2c
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / ImportSchemaCtrl.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 app.controller('ImportSchemaCtrl', ['$scope', '$rootScope','$modalInstance','data','svnservice', 'fileUpload','dialogs', function($scope,$rootScope,$modalInstance,data,svnservice,fileUpload,dialogs){
25         console.log("//////ImportSchemaCtrl");
26     $rootScope.serviceInfo;
27         $rootScope.serviceInput;
28         $rootScope.serviceOutput;
29         $rootScope.serviceFault;
30         $rootScope.serviceInputPartInfo;
31         $rootScope.schemElemant1;
32         
33         $rootScope.updateServiceInfo;
34         $rootScope.updateServiceInput;
35         $rootScope.updateServiceOutput;
36         $rootScope.updateServiceFault;
37         $rootScope.updateServiceInputPartInfo;
38         $rootScope.updateSchemElemant1;
39     
40
41 // Below code is added to get the policyNames
42         for ( var polElement in elementMap) {
43                 if (polElement.indexOf('Policy_') === 0) {
44                         var obj = elementMap[polElement];
45                         if (!($.isEmptyObject(obj))) {
46                                 allPolicies = jQuery.extend({}, obj);
47                                 $scope.policyNames = [];
48                                 for ( var policy in allPolicies) {
49                                         $scope.policyNames.push(policy);
50                                 }
51                         }
52                         break;
53                 }
54         }
55      
56     setTimeout(function(){
57     console.log("setTimeout");
58     setMultiSelect(); }, 100);
59         
60         $scope.init = function() {
61         console.log("init");
62         $scope.schemaLocation = 'svn://svnrepo:3690';
63                 $scope.upgrade_schemaLocation = 'svn://svnrepo:3690';
64                 $scope.userID = 'user_id';
65                 $scope.password = 'password';
66         };
67         
68         $scope.init();
69          
70
71         $scope.close = function(){
72     console.log("close");               
73                 $modalInstance.close("closed");
74         };
75         $rootScope.file_path;
76         
77         
78         $scope.importSchema= function(){
79     console.log("importSchema");                
80                 isImportSchema = true;
81                 var file=$rootScope.file_path; 
82                 //alert("file:"+schemaFile);
83         //console.log('file is ' + JSON.stringify(file)); 
84         var userID = document.getElementById("userID").value;
85         var password = document.getElementById("password").value;        
86         var svnURL = document.getElementById("schemaLocation").value;
87         var schemaLocation = document.getElementById("schemaLocation").value;
88         
89         if( schemaLocation &&  userID && password && document.getElementById("schemaLocation").disabled== false)
90         {
91                 $scope.schemaLocation=schemaLocation;
92                 $scope.userID=userID;
93                 $scope.password=password;
94
95                 document.getElementById("fileUpload").disabled = true;  
96             
97                 var svnUploadURL = "/utm-service/schema_upload/svnUploadWSDL";
98           
99                 svnservice.SVNToUrl(schemaLocation, userID, password,svnURL,svnUploadURL)
100                         .then(function(pars) {
101                     console.log("pars");
102                                 document.getElementById('Upgrade Schema Version').classList.remove('ThisLink');
103                                 document.getElementById('Set Default Values').classList.remove('ThisLink');
104                                 $rootScope.wsdlInfo = angular.fromJson(pars);
105                                 $rootScope.serviceInfo =  $rootScope.wsdlInfo.serviceInfo;
106                                 serviceName = $rootScope.serviceInfo.service.name;
107                                 $rootScope.schemaLocation=$rootScope.wsdlInfo.schemaLocation;
108                                 $rootScope.serviceInput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
109                                 $rootScope.serviceInputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
110                                 
111                                 $rootScope.serviceOutput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
112                         $rootScope.serviceOutputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
113                         
114                         $rootScope.servicefault = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
115                         $rootScope.servicefaultPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
116                                 
117                                 //alert("serviceInputPartInfo :: " + JSON.stringify($rootScope.serviceInputPartInfo));
118                         
119                         $rootScope.inputSchemaServiceInputPartInfo=[];
120                         $rootScope.inputSchemaServiceOutputPartInfo=[];
121                         $rootScope.inputSchemaServicefaultPartInfo=[];
122                         
123                         
124                          
125                      angular.copy($rootScope.serviceInputPartInfo, $rootScope.inputSchemaServiceInputPartInfo);
126                      
127                      angular.copy($rootScope.serviceOutputPartInfo, $rootScope.inputSchemaServiceOutputPartInfo);
128                      
129                      angular.copy($rootScope.servicefaultPartInfo, $rootScope.inputSchemaServicefaultPartInfo);
130                      
131                                 $rootScope.isModel = true;
132                         },
133                         function(data) {
134                     console.log("data");
135                                 //alert("File upload failed and parameters not returned");
136                         });
137         } else  {
138                 var uploadUrl = "/utm-service/schema_upload/uploadWSDL";
139             
140             fileUpload.uploadFileToUrl(file, uploadUrl)
141             .then(function(pars) {
142                 console.log("pars");
143                 document.getElementById('Upgrade Schema Version').classList.remove('ThisLink');
144                 document.getElementById('Set Default Values').classList.remove('ThisLink');
145                 //document.getElementById('Define/Modify Schema').classList.remove('ThisLink');
146                 $rootScope.wsdlInfo = angular.fromJson(pars);
147                 $rootScope.serviceInfo =  $rootScope.wsdlInfo.serviceInfo;
148                 serviceName = $rootScope.serviceInfo.service.name;
149                 
150                 $rootScope.serviceInput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
151                 $rootScope.serviceInputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
152                 
153                 //alert("Input Part Info :: " + JSON.stringify($rootScope.serviceInputPartInfo));
154                 //alert("Input Part 1 Info :: " + JSON.stringify($rootScope.serviceInputPartInfo[1]));
155                 
156                 //alert("Input Element :: " + JSON.stringify($rootScope.serviceInputPartInfo[1].schemaElements[1].elements[0]));
157                 
158                 $rootScope.serviceOutput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
159                 $rootScope.serviceOutputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
160                 
161                 $rootScope.servicefault = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
162                 $rootScope.servicefaultPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
163                 
164                 //alert("servicefaultPartInfo :: " + JSON.stringify($rootScope.servicefaultPartInfo));
165                 
166                 $rootScope.inputSchemaServiceInputPartInfo=[];
167                 $rootScope.inputSchemaServiceOutputPartInfo=[];
168                 $rootScope.inputSchemaServicefaultPartInfo=[];
169                 
170                 
171                  
172                  angular.copy($rootScope.serviceInputPartInfo, $rootScope.inputSchemaServiceInputPartInfo);
173                  
174                  angular.copy($rootScope.serviceOutputPartInfo, $rootScope.inputSchemaServiceOutputPartInfo);
175                  
176                  angular.copy($rootScope.servicefaultPartInfo, $rootScope.inputSchemaServicefaultPartInfo);
177             
178                 $rootScope.isModel = true;              
179                 },
180             function(data) {
181                 console.log("data");
182                 
183             });
184         }
185         
186        
187         
188         
189         
190                 $modalInstance.close("closed");
191         };
192         
193          $scope.setFile = function(element) {
194         console.log("setFile");
195                  
196          $scope.$apply(function($scope) {
197             console.log("apply");
198              $scope.theFile = element.files[0];
199              $rootScope.fileName =$scope.theFile.name;
200             var file =element.files[0]; 
201             $rootScope.file_path = file;
202         
203                 //$modalInstance.close("closed");
204             
205              angular.element(document.getElementById('fileUpload')).val(null);
206                 
207          });
208      };
209      
210      $scope.setUpgradeFile = function(element) {
211                  console.log("setUpgradeFile");
212          $scope.$apply(function($scope) {
213             console.log("apply");
214              $scope.theUpgradeFile = element.files[0];
215              $rootScope.upgradeFileName =$scope.theUpgradeFile.name;
216             //alert("fname1"+$rootScope.upgradeFileName);
217             var file =element.files[0]; 
218             $rootScope.file_path = file;
219         
220                 //$modalInstance.close("closed");
221             
222              angular.element(document.getElementById('fileUpload')).val(null);
223                 
224          });
225      };
226      
227      
228      
229      $scope.reset = function(){
230         console.log("reset");
231          document.getElementById("fileUpload").disabled = false;
232          document.getElementById("schemaLocation").disabled = false;
233          document.getElementById("userID").disabled = false;
234          document.getElementById("password").disabled = false;
235          
236          document.getElementById("schemaLocation").value='';
237          
238          document.getElementById("userID").value='';
239          document.getElementById("password").value='';
240          $scope.theFile = null;
241          angular.element(document.getElementById('fileUpload')).val(null);
242        
243          
244      };
245      
246      $scope.upgradeSchema = function(){
247         console.log("upgradeSchema");
248          //alert("inside upgrade schema");
249                  var file=$rootScope.file_path; 
250                 //alert("file:"+schemaFile);
251          //console.log('file is ' + JSON.stringify(file)); 
252          var userID = document.getElementById("userID").value;
253          var password = document.getElementById("password").value;
254          var schemaLocation = document.getElementById("upgradeSchemaLocation").value;
255          var svnURL = document.getElementById("upgradeSchemaLocation").value;
256          console.log("after");
257          $rootScope.Currentmappedvalues = [];
258          if( schemaLocation &&  userID && password && document.getElementById("upgradeSchemaLocation").disabled== false)
259          {
260                 $scope.schemaLocation=schemaLocation;
261                 $scope.userID=userID;
262                 $scope.password=password;
263                 
264                 document.getElementById("fileUpload").disabled = true;  
265              
266                 var svnUploadURL = "/utm-service/schema_upload/svnUploadWSDL";
267            
268                 svnservice.SVNToUrl(schemaLocation, userID, password,svnURL,svnUploadURL)
269                         .then(function(pars) {
270                     console.log("pars");
271                                 $rootScope.updateWsdlInfo = angular.fromJson(pars);
272                                 $rootScope.updateServiceInfo =  $rootScope.updateWsdlInfo.serviceInfo;
273                                 $rootScope.schemaLocation=$rootScope.updateWsdlInfo.schemaLocation;
274                                 $rootScope.updateServiceInput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
275                                 $rootScope.updateServiceInputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
276                                 
277                                 $rootScope.updateServiceOutput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
278                         $rootScope.updateServiceOutputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
279                         
280                         $rootScope.updateServicefault = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
281                         $rootScope.updateServicefaultPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
282                                 
283                                 //alert("serviceInputPartInfo :: " + JSON.stringify($rootScope.serviceInputPartInfo));
284          
285                                 //$rootScope.isModel = true;
286                         },
287                         function(data) {
288                     console.log("data");
289                                 //alert("File upload failed and parameters not returned");
290                         });
291          } else  {
292                 var uploadUrl = "/utm-service/schema_upload/uploadWSDL";
293              
294              fileUpload.uploadFileToUrl(file, uploadUrl)
295              .then(function(pars) {
296                 console.log("pars");
297                 
298                 $rootScope.updateWsdlInfo = angular.fromJson(pars);
299                //       alert("wsdlinfo:"+$rootScope.updateWsdlInfo);
300                 $rootScope.updateServiceInfo =  $rootScope.updateWsdlInfo.serviceInfo;
301                 
302                 $rootScope.updateServiceInput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
303                 $rootScope.updateServiceInputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
304                 
305                 $rootScope.updateServiceOutput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
306                 $rootScope.updateServiceOutputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
307                 
308                 $rootScope.updateServicefault = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
309                 $rootScope.updateServicefaultPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
310                 
311                 //alert("servicefaultPartInfo :: " + JSON.stringify($rootScope.servicefaultPartInfo));
312                 
313              
314                 //$rootScope.isModel = true;                    
315                 },
316              function(data) {
317                 console.log("data");
318                 
319              });
320          }
321         
322                 $modalInstance.close("closed");
323                 
324                 var dlg = dialogs.create('partials/portfolios/upgrade_schema_dtls.html','UpgradeSchemaCtrl',{},{size:'xlg',keyboard: true,backdrop: true,windowClass: 'my-class'});
325                 dlg.result.then(function(name){
326             console.log("dlg.result");
327                         //$scope.name = name;
328                 },function(){
329                         //if(angular.equals($scope.name,''))
330                                 //$scope.name = 'You did not enter in your name!';
331                 });
332         
333          
334      };
335 }]);