[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / ExportFileService.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.service('exportService', ['$http', '$q', function ($http, $q) {
25     console.log("/////////exportService");
26     this.exportToUrl = function(testsetValue, formatValue, exporturl){
27         console.log("exportToUrl");
28                 
29         var def = $q.defer();
30         var sets = [];
31         var testExportRequest = {testSet: testsetValue, format: formatValue};
32                 
33         if (angular.equals(formatValue,"Excel")) {
34        
35         $http({
36             url: exporturl,     method: "POST",     data: testExportRequest, //this is your json data string     headers: {
37              responseType: 'arraybuffer' }).success(function (data, status, headers, config) {
38                 console.log("success");
39                 /*sets = data;
40                 def.resolve(data);*/
41                  
42                  var results = [];
43                  results.data = data;
44                  results.headers = headers();
45                  results.status = status;
46                  results.config = config;
47                  def.resolve(results); 
48         })
49         .error(function(data){
50             console.log("data");
51                       
52                 def.reject("Export file not successful");
53         });
54         }
55         else {
56                   $http.post(exporturl, testExportRequest)
57             .success(function(data, status, headers, config){
58                 console.log("function");
59                                 
60                 var results = [];
61                 results.data = data;
62                 results.headers = headers();
63                 results.status = status;
64                 results.config = config;
65
66                 def.resolve(results); 
67                 //alert("Data in success without scope and q_def for scope parametes :: " + parameters);'Content-type': 'application/json',
68             }) 
69             .error(function(data){
70                 console.log("data");
71                         //alert("Data in error :: " + data);      
72                         def.reject("Export file not successful");
73             });
74         }
75         return def.promise;
76     };
77     
78     this.exportToUTMTestSet = function(almqcExport, exporturl){
79     console.log("exportToUTMTestSet");          
80         var def = $q.defer();
81         var sets = [];
82         //var almqcExport =  almqcExport;       
83         $http({
84             url: exporturl,     method: "POST",     data: almqcExport,
85              responseType: 'arraybuffer' }).success(function (data, status, headers, config) {
86              console.log("success");                     
87                  var results = [];
88                  results.data = data;
89                  results.headers = headers();
90                  results.status = status;
91                  results.config = config;
92                  def.resolve(results); 
93         })
94         .error(function(data){
95             console.log("data");
96                       
97                 def.reject("Export file not successful");
98         });        
99         
100         return def.promise;
101     };
102 }]);