Upgrade angular to 1.3.2
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / ImportSchemaCtrl.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 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  * 
22  */
23 app
24 .controller(
25 'ImportSchemaCtrl',
26 [
27 '$scope',
28 '$rootScope',
29 '$uibModalInstance',
30 'data',
31 'svnservice',
32 'fileUpload',
33 'dialogs',
34 function($scope, $rootScope, $uibModalInstance, data, svnservice, fileUpload,
35          dialogs) {
36         console.log("//////ImportSchemaCtrl");
37         $rootScope.serviceInfo;
38         $rootScope.serviceInput;
39         $rootScope.serviceOutput;
40         $rootScope.serviceFault;
41         $rootScope.serviceInputPartInfo;
42         $rootScope.schemElemant1;
43         $rootScope.updateServiceInfo;
44         $rootScope.updateServiceInput;
45         $rootScope.updateServiceOutput;
46         $rootScope.updateServiceFault;
47         $rootScope.updateServiceInputPartInfo;
48         $rootScope.updateSchemElemant1;
49         // Below code is added to get the policyNames
50         for ( var polElement in elementMap) {
51                 if (polElement.indexOf('Policy_') === 0) {
52                         var obj = elementMap[polElement];
53                         if (!($.isEmptyObject(obj))) {
54                                 allPolicies = jQuery.extend({}, obj);
55                                 $scope.policyNames = [];
56                                 for ( var policy in allPolicies) {
57                                         $scope.policyNames.push(policy);
58                                 }
59                         }
60                         break;
61                 }
62         }
63         setTimeout(function() {
64                 console.log("setTimeout");
65                 setMultiSelect();
66         }, 100);
67         $scope.close = function() {
68                 console.log("close");
69                 $uibModalInstance.close("closed");
70         };
71         $rootScope.file_path;
72         $scope.importSchema = function() {
73                 console.log("importSchema");
74                 isImportSchema = true;
75                 var file = $rootScope.file_path;
76                 // alert("file:"+schemaFile);
77                 // console.log('file is ' + JSON.stringify(file));
78                 var userID = document.getElementById("userID").value;
79                 var password = document.getElementById("password").value;
80                 var svnURL = document.getElementById("schemaLocation").value;
81                 var schemaLocation = document.getElementById("schemaLocation").value;
82                 if (schemaLocation && userID && password
83                 && document.getElementById("schemaLocation").disabled == false) {
84                         $scope.schemaLocation = schemaLocation;
85                         $scope.userID = userID;
86                         $scope.password = password;
87                         document.getElementById("fileUpload").disabled = true;
88                         var svnUploadURL = "/utm-service/schema_upload/svnUploadWSDL";
89                         svnservice
90                         .SVNToUrl(schemaLocation, userID, password, svnURL, svnUploadURL)
91                         .then(
92                         function(pars) {
93                                 console.log("pars");
94                                 document.getElementById('Upgrade Schema Version').classList
95                                 .remove('ThisLink');
96                                 document.getElementById('Set Default Values').classList
97                                 .remove('ThisLink');
98                                 $rootScope.wsdlInfo = angular.fromJson(pars);
99                                 $rootScope.serviceInfo = $rootScope.wsdlInfo.serviceInfo;
100                                 serviceName = $rootScope.serviceInfo.service.name;
101                                 $rootScope.schemaLocation = $rootScope.wsdlInfo.schemaLocation;
102                                 $rootScope.serviceInput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
103                                 $rootScope.serviceInputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
104                                 $rootScope.serviceOutput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
105                                 $rootScope.serviceOutputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
106                                 $rootScope.servicefault = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
107                                 $rootScope.servicefaultPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
108                                 // alert("serviceInputPartInfo :: " +
109                                 // JSON.stringify($rootScope.serviceInputPartInfo));
110                                 $rootScope.inputSchemaServiceInputPartInfo = [];
111                                 $rootScope.inputSchemaServiceOutputPartInfo = [];
112                                 $rootScope.inputSchemaServicefaultPartInfo = [];
113                                 angular.copy($rootScope.serviceInputPartInfo,
114                                 $rootScope.inputSchemaServiceInputPartInfo);
115                                 angular.copy($rootScope.serviceOutputPartInfo,
116                                 $rootScope.inputSchemaServiceOutputPartInfo);
117                                 angular.copy($rootScope.servicefaultPartInfo,
118                                 $rootScope.inputSchemaServicefaultPartInfo);
119                                 $rootScope.isModel = true;
120                         }, function(data) {
121                                 console.log("data");
122                                 // alert("File upload failed and parameters not returned");
123                         });
124                 } else {
125                         var uploadUrl = "/utm-service/schema_upload/uploadWSDL";
126                         fileUpload
127                         .uploadFileToUrl(file, uploadUrl)
128                         .then(
129                         function(pars) {
130                                 console.log("pars");
131                                 document.getElementById('Upgrade Schema Version').classList
132                                 .remove('ThisLink');
133                                 document.getElementById('Set Default Values').classList
134                                 .remove('ThisLink');
135                                 // document.getElementById('Define/Modify
136                                 // Schema').classList.remove('ThisLink');
137                                 $rootScope.wsdlInfo = angular.fromJson(pars);
138                                 $rootScope.serviceInfo = $rootScope.wsdlInfo.serviceInfo;
139                                 serviceName = $rootScope.serviceInfo.service.name;
140                                 $rootScope.serviceInput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
141                                 $rootScope.serviceInputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
142                                 // alert("Input Part Info :: " +
143                                 // JSON.stringify($rootScope.serviceInputPartInfo));
144                                 // alert("Input Part 1 Info :: " +
145                                 // JSON.stringify($rootScope.serviceInputPartInfo[1]));
146                                 // alert("Input Element :: " +
147                                 // JSON.stringify($rootScope.serviceInputPartInfo[1].schemaElements[1].elements[0]));
148                                 $rootScope.serviceOutput = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
149                                 $rootScope.serviceOutputPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
150                                 $rootScope.servicefault = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
151                                 $rootScope.servicefaultPartInfo = $rootScope.serviceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
152                                 // alert("servicefaultPartInfo :: " +
153                                 // JSON.stringify($rootScope.servicefaultPartInfo));
154                                 $rootScope.inputSchemaServiceInputPartInfo = [];
155                                 $rootScope.inputSchemaServiceOutputPartInfo = [];
156                                 $rootScope.inputSchemaServicefaultPartInfo = [];
157                                 angular.copy($rootScope.serviceInputPartInfo,
158                                 $rootScope.inputSchemaServiceInputPartInfo);
159                                 angular.copy($rootScope.serviceOutputPartInfo,
160                                 $rootScope.inputSchemaServiceOutputPartInfo);
161                                 angular.copy($rootScope.servicefaultPartInfo,
162                                 $rootScope.inputSchemaServicefaultPartInfo);
163                                 $rootScope.isModel = true;
164                         }, function(data) {
165                                 console.log("data");
166                         });
167                 }
168                 $uibModalInstance.close("closed");
169         };
170         $scope.setFile = function(element) {
171                 console.log("setFile");
172                 $scope.$apply(function($scope) {
173                         console.log("apply");
174                         $scope.theFile = element.files[0];
175                         $rootScope.fileName = $scope.theFile.name;
176                         var file = element.files[0];
177                         $rootScope.file_path = file;
178                         // $uibModalInstance.close("closed");
179                         angular.element(document.getElementById('fileUpload')).val(null);
180                 });
181         };
182         $scope.setUpgradeFile = function(element) {
183                 console.log("setUpgradeFile");
184                 $scope.$apply(function($scope) {
185                         console.log("apply");
186                         $scope.theUpgradeFile = element.files[0];
187                         $rootScope.upgradeFileName = $scope.theUpgradeFile.name;
188                         // alert("fname1"+$rootScope.upgradeFileName);
189                         var file = element.files[0];
190                         $rootScope.file_path = file;
191                         // $uibModalInstance.close("closed");
192                         angular.element(document.getElementById('fileUpload')).val(null);
193                 });
194         };
195         $scope.reset = function() {
196                 console.log("reset");
197                 document.getElementById("fileUpload").disabled = false;
198                 document.getElementById("schemaLocation").disabled = false;
199                 document.getElementById("userID").disabled = false;
200                 document.getElementById("password").disabled = false;
201                 document.getElementById("schemaLocation").value = '';
202                 document.getElementById("userID").value = '';
203                 document.getElementById("password").value = '';
204                 $scope.theFile = null;
205                 angular.element(document.getElementById('fileUpload')).val(null);
206         };
207         $scope.upgradeSchema = function() {
208                 console.log("upgradeSchema");
209                 // alert("inside upgrade schema");
210                 var file = $rootScope.file_path;
211                 // alert("file:"+schemaFile);
212                 // console.log('file is ' + JSON.stringify(file));
213                 var userID = document.getElementById("userID").value;
214                 var password = document.getElementById("password").value;
215                 var schemaLocation = document.getElementById("upgradeSchemaLocation").value;
216                 var svnURL = document.getElementById("upgradeSchemaLocation").value;
217                 console.log("after");
218                 $rootScope.Currentmappedvalues = [];
219                 if (schemaLocation && userID && password
220                 && document.getElementById("upgradeSchemaLocation").disabled == false) {
221                         $scope.schemaLocation = schemaLocation;
222                         $scope.userID = userID;
223                         $scope.password = password;
224                         document.getElementById("fileUpload").disabled = true;
225                         var svnUploadURL = "/utm-service/schema_upload/svnUploadWSDL";
226                         svnservice
227                         .SVNToUrl(schemaLocation, userID, password, svnURL, svnUploadURL)
228                         .then(
229                         function(pars) {
230                                 console.log("pars");
231                                 $rootScope.updateWsdlInfo = angular.fromJson(pars);
232                                 $rootScope.updateServiceInfo = $rootScope.updateWsdlInfo.serviceInfo;
233                                 $rootScope.schemaLocation = $rootScope.updateWsdlInfo.schemaLocation;
234                                 $rootScope.updateServiceInput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
235                                 $rootScope.updateServiceInputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
236                                 $rootScope.updateServiceOutput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
237                                 $rootScope.updateServiceOutputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
238                                 $rootScope.updateServicefault = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
239                                 $rootScope.updateServicefaultPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
240                                 // alert("serviceInputPartInfo :: " +
241                                 // JSON.stringify($rootScope.serviceInputPartInfo));
242                                 // $rootScope.isModel = true;
243                         }, function(data) {
244                                 console.log("data");
245                                 // alert("File upload failed and parameters not returned");
246                         });
247                 } else {
248                         var uploadUrl = "/utm-service/schema_upload/uploadWSDL";
249                         fileUpload
250                         .uploadFileToUrl(file, uploadUrl)
251                         .then(
252                         function(pars) {
253                                 console.log("pars");
254                                 $rootScope.updateWsdlInfo = angular.fromJson(pars);
255                                 // alert("wsdlinfo:"+$rootScope.updateWsdlInfo);
256                                 $rootScope.updateServiceInfo = $rootScope.updateWsdlInfo.serviceInfo;
257                                 $rootScope.updateServiceInput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage;
258                                 $rootScope.updateServiceInputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].inputMessage.partInfo;
259                                 $rootScope.updateServiceOutput = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage;
260                                 $rootScope.updateServiceOutputPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].outputMessage.partInfo;
261                                 $rootScope.updateServicefault = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage;
262                                 $rootScope.updateServicefaultPartInfo = $rootScope.updateServiceInfo.bindingInfo.portTypeInfo.operationInfo[0].faultMessage.partInfo;
263                                 // alert("servicefaultPartInfo :: " +
264                                 // JSON.stringify($rootScope.servicefaultPartInfo));
265                                 // $rootScope.isModel = true;
266                         }, function(data) {
267                                 console.log("data");
268                         });
269                 }
270                 $uibModalInstance.close("closed");
271                 var dlg = dialogs.create(
272                 'partials/portfolios/upgrade_schema_dtls.html', 'UpgradeSchemaCtrl',
273                 {}, {
274                 size : 'xlg',
275                 keyboard : true,
276                 backdrop : true,
277                 windowClass : 'my-class'
278                 });
279                 dlg.result.then(function(name) {
280                         console.log("dlg.result");
281                         // $scope.name = name;
282                 }, function() {
283                         // if(angular.equals($scope.name,''))
284                         // $scope.name = 'You did not enter in your name!';
285                 });
286         };
287 } ]);