[CLAMP-1] Initial ONAP CLAMP seed code commit
[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         $scope.init = function() {
41         console.log("init");
42                 $scope.schemaLocation = 'svn://svnrepo:3690';
43                 $scope.upgrade_schemaLocation = 'svn://svnrepo:3690';
44                 $scope.userID = 'user_id';
45                 $scope.password = 'password';
46         };
47         
48         $scope.init();
49          
50
51         $scope.close = function(){
52     console.log("close");               
53                 $modalInstance.close("closed");
54         };
55         $rootScope.file_path;
56         
57         
58         $scope.importSchema= function(){
59     console.log("importSchema");                
60                 isImportSchema = true;
61                 var file=$rootScope.file_path; 
62                 //alert("file:"+schemaFile);
63         //console.log('file is ' + JSON.stringify(file)); 
64         var userID = document.getElementById("userID").value;
65         var password = document.getElementById("password").value;        
66         var svnURL = document.getElementById("schemaLocation").value;
67         var schemaLocation = document.getElementById("schemaLocation").value;
68         
69         if( schemaLocation &&  userID && password && document.getElementById("schemaLocation").disabled== false)
70         {
71                 $scope.schemaLocation=schemaLocation;
72                 $scope.userID=userID;
73                 $scope.password=password;
74
75                 document.getElementById("fileUpload").disabled = true;  
76             
77                 var svnUploadURL = "/utm-service/schema_upload/svnUploadWSDL";
78           
79                 svnservice.SVNToUrl(schemaLocation, userID, password,svnURL,svnUploadURL)
80                         .then(function(pars) {
81                     console.log("pars");
82                                 document.getElementById('Upgrade Schema Version').classList.remove('ThisLink');
83                                 document.getElementById('Set Default Values').classList.remove('ThisLink');
84                                 $rootScope.wsdlInfo = angular.fromJson(pars);
85                                 $rootScope.serviceInfo =  $rootScope.wsdlInfo.serviceInfo;
86                                 serviceName = $rootScope.serviceInfo.service.name;
87                                 $rootScope.schemaLocation=$rootScope.wsdlInfo.schemaLocation;
88                                 $rootScope.serviceInput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
89                                 $rootScope.serviceInputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
90                                 
91                                 $rootScope.serviceOutput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
92                         $rootScope.serviceOutputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
93                         
94                         $rootScope.servicefault = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
95                         $rootScope.servicefaultPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
96                                 
97                                 //alert("serviceInputPartInfo :: " + JSON.stringify($rootScope.serviceInputPartInfo));
98                         
99                         $rootScope.inputSchemaServiceInputPartInfo=[];
100                         $rootScope.inputSchemaServiceOutputPartInfo=[];
101                         $rootScope.inputSchemaServicefaultPartInfo=[];
102                         
103                         
104                          
105                      angular.copy($rootScope.serviceInputPartInfo, $rootScope.inputSchemaServiceInputPartInfo);
106                      
107                      angular.copy($rootScope.serviceOutputPartInfo, $rootScope.inputSchemaServiceOutputPartInfo);
108                      
109                      angular.copy($rootScope.servicefaultPartInfo, $rootScope.inputSchemaServicefaultPartInfo);
110                      
111                                 $rootScope.isModel = true;
112                         },
113                         function(data) {
114                     console.log("data");
115                                 //alert("File upload failed and parameters not returned");
116                         });
117         } else  {
118                 var uploadUrl = "/utm-service/schema_upload/uploadWSDL";
119             
120             fileUpload.uploadFileToUrl(file, uploadUrl)
121             .then(function(pars) {
122                 console.log("pars");
123                 document.getElementById('Upgrade Schema Version').classList.remove('ThisLink');
124                 document.getElementById('Set Default Values').classList.remove('ThisLink');
125                 //document.getElementById('Define/Modify Schema').classList.remove('ThisLink');
126                 $rootScope.wsdlInfo = angular.fromJson(pars);
127                 $rootScope.serviceInfo =  $rootScope.wsdlInfo.serviceInfo;
128                 serviceName = $rootScope.serviceInfo.service.name;
129                 
130                 $rootScope.serviceInput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
131                 $rootScope.serviceInputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
132                 
133                 //alert("Input Part Info :: " + JSON.stringify($rootScope.serviceInputPartInfo));
134                 //alert("Input Part 1 Info :: " + JSON.stringify($rootScope.serviceInputPartInfo[1]));
135                 
136                 //alert("Input Element :: " + JSON.stringify($rootScope.serviceInputPartInfo[1].schemaElements[1].elements[0]));
137                 
138                 $rootScope.serviceOutput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
139                 $rootScope.serviceOutputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
140                 
141                 $rootScope.servicefault = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
142                 $rootScope.servicefaultPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
143                 
144                 //alert("servicefaultPartInfo :: " + JSON.stringify($rootScope.servicefaultPartInfo));
145                 
146                 $rootScope.inputSchemaServiceInputPartInfo=[];
147                 $rootScope.inputSchemaServiceOutputPartInfo=[];
148                 $rootScope.inputSchemaServicefaultPartInfo=[];
149                 
150                 
151                  
152                  angular.copy($rootScope.serviceInputPartInfo, $rootScope.inputSchemaServiceInputPartInfo);
153                  
154                  angular.copy($rootScope.serviceOutputPartInfo, $rootScope.inputSchemaServiceOutputPartInfo);
155                  
156                  angular.copy($rootScope.servicefaultPartInfo, $rootScope.inputSchemaServicefaultPartInfo);
157             
158                 $rootScope.isModel = true;              
159                 },
160             function(data) {
161                 console.log("data");
162                 
163             });
164         }
165         
166        
167         
168         
169         
170                 $modalInstance.close("closed");
171         };
172         
173          $scope.setFile = function(element) {
174         console.log("setFile");
175                  
176          $scope.$apply(function($scope) {
177             console.log("apply");
178              $scope.theFile = element.files[0];
179              $rootScope.fileName =$scope.theFile.name;
180             var file =element.files[0]; 
181             $rootScope.file_path = file;
182         
183                 //$modalInstance.close("closed");
184             
185              angular.element(document.getElementById('fileUpload')).val(null);
186                 
187          });
188      };
189      
190      $scope.setUpgradeFile = function(element) {
191                  console.log("setUpgradeFile");
192          $scope.$apply(function($scope) {
193             console.log("apply");
194              $scope.theUpgradeFile = element.files[0];
195              $rootScope.upgradeFileName =$scope.theUpgradeFile.name;
196             //alert("fname1"+$rootScope.upgradeFileName);
197             var file =element.files[0]; 
198             $rootScope.file_path = file;
199         
200                 //$modalInstance.close("closed");
201             
202              angular.element(document.getElementById('fileUpload')).val(null);
203                 
204          });
205      };
206      
207      
208      
209      $scope.reset = function(){
210         console.log("reset");
211          document.getElementById("fileUpload").disabled = false;
212          document.getElementById("schemaLocation").disabled = false;
213          document.getElementById("userID").disabled = false;
214          document.getElementById("password").disabled = false;
215          
216          document.getElementById("schemaLocation").value='';
217          
218          document.getElementById("userID").value='';
219          document.getElementById("password").value='';
220          $scope.theFile = null;
221          angular.element(document.getElementById('fileUpload')).val(null);
222        
223          
224      };
225      
226      $scope.upgradeSchema = function(){
227         console.log("upgradeSchema");
228          //alert("inside upgrade schema");
229                  var file=$rootScope.file_path; 
230                 //alert("file:"+schemaFile);
231          //console.log('file is ' + JSON.stringify(file)); 
232          var userID = document.getElementById("userID").value;
233          var password = document.getElementById("password").value;
234          var schemaLocation = document.getElementById("upgradeSchemaLocation").value;
235          var svnURL = document.getElementById("upgradeSchemaLocation").value;
236          console.log("after");
237          $rootScope.Currentmappedvalues = [];
238          if( schemaLocation &&  userID && password && document.getElementById("upgradeSchemaLocation").disabled== false)
239          {
240                 $scope.schemaLocation=schemaLocation;
241                 $scope.userID=userID;
242                 $scope.password=password;
243                 
244                 document.getElementById("fileUpload").disabled = true;  
245              
246                 var svnUploadURL = "/utm-service/schema_upload/svnUploadWSDL";
247            
248                 svnservice.SVNToUrl(schemaLocation, userID, password,svnURL,svnUploadURL)
249                         .then(function(pars) {
250                     console.log("pars");
251                                 $rootScope.updateWsdlInfo = angular.fromJson(pars);
252                                 $rootScope.updateServiceInfo =  $rootScope.updateWsdlInfo.serviceInfo;
253                                 $rootScope.schemaLocation=$rootScope.updateWsdlInfo.schemaLocation;
254                                 $rootScope.updateServiceInput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
255                                 $rootScope.updateServiceInputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
256                                 
257                                 $rootScope.updateServiceOutput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
258                         $rootScope.updateServiceOutputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
259                         
260                         $rootScope.updateServicefault = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
261                         $rootScope.updateServicefaultPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
262                                 
263                                 //alert("serviceInputPartInfo :: " + JSON.stringify($rootScope.serviceInputPartInfo));
264          
265                                 //$rootScope.isModel = true;
266                         },
267                         function(data) {
268                     console.log("data");
269                                 //alert("File upload failed and parameters not returned");
270                         });
271          } else  {
272                 var uploadUrl = "/utm-service/schema_upload/uploadWSDL";
273              
274              fileUpload.uploadFileToUrl(file, uploadUrl)
275              .then(function(pars) {
276                 console.log("pars");
277                 
278                 $rootScope.updateWsdlInfo = angular.fromJson(pars);
279                //       alert("wsdlinfo:"+$rootScope.updateWsdlInfo);
280                 $rootScope.updateServiceInfo =  $rootScope.updateWsdlInfo.serviceInfo;
281                 
282                 $rootScope.updateServiceInput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
283                 $rootScope.updateServiceInputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
284                 
285                 $rootScope.updateServiceOutput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
286                 $rootScope.updateServiceOutputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
287                 
288                 $rootScope.updateServicefault = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
289                 $rootScope.updateServicefaultPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
290                 
291                 //alert("servicefaultPartInfo :: " + JSON.stringify($rootScope.servicefaultPartInfo));
292                 
293              
294                 //$rootScope.isModel = true;                    
295                 },
296              function(data) {
297                 console.log("data");
298                 
299              });
300          }
301         
302                 $modalInstance.close("closed");
303                 
304                 var dlg = dialogs.create('partials/portfolios/upgrade_schema_dtls.html','UpgradeSchemaCtrl',{},{size:'xlg',keyboard: true,backdrop: true,windowClass: 'my-class'});
305                 dlg.result.then(function(name){
306             console.log("dlg.result");
307                         //$scope.name = name;
308                 },function(){
309                         //if(angular.equals($scope.name,''))
310                                 //$scope.name = 'You did not enter in your name!';
311                 });
312         
313          
314      };
315 }]);