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