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