Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / WEB-INF / fusion / raptor / report_download_csv.jsp
1 <%--
2   ================================================================================
3   eCOMP Portal SDK
4   ================================================================================
5   Copyright (C) 2017 AT&T Intellectual Property
6   ================================================================================
7   Licensed under the Apache License, Version 2.0 (the "License");
8   you may not use this file except in compliance with the License.
9   You may obtain a copy of the License at
10   
11        http://www.apache.org/licenses/LICENSE-2.0
12   
13   Unless required by applicable law or agreed to in writing, software
14   distributed under the License is distributed on an "AS IS" BASIS,
15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   See the License for the specific language governing permissions and
17   limitations under the License.
18   ================================================================================
19   --%>
20 <%@ page trimDirectiveWhitespaces="true" %>
21 <%@ page import="java.util.*" %><%@ page import="java.text.*" %><%@ page import="java.io.*" %><%@ page import="org.openecomp.portalsdk.analytics.model.*" %><%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %><%@ page import="org.openecomp.portalsdk.analytics.view.*" %><%@ page import="org.openecomp.portalsdk.analytics.system.*" %><%@ page import="org.openecomp.portalsdk.analytics.util.*" %><%
22         ReportRuntime rr = null;
23         ReportData    rd = null;
24         String parent = "";
25         int parentFlag = 0;
26         if(!nvl(request.getParameter("parent"), "").equals("N")) parent = nvl(request.getParameter("parent"), "");
27         if(parent.startsWith("parent_")) parentFlag = 1;
28         if(parentFlag == 1) {
29                 rr = (ReportRuntime) request.getSession().getAttribute(parent+"_rr");
30                 rd = (ReportData) request.getSession().getAttribute(parent+"_rd");
31         }
32         if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
33         if(rd==null) rd = (ReportData)    request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
34     String formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName());
35     String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date());
36         String fName = formattedReportName+formattedDate+AppUtils.getUserID(request);
37         boolean raw = AppUtils.getRequestFlag(request, "raw");
38         if(true && !raw) 
39                 response.setContentType("application/octet-stream");
40         else
41                 response.setContentType("application/csv");
42         String fileName = fName+".csv";
43         String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
44         if(true && !raw) 
45                 response.setHeader("Content-disposition","attachment;filename="+fName+".zip");
46         else
47                  response.setHeader("Content-disposition","attachment;filename="+fName+".csv");
48         try {(new ReportHandler()).createCSVFileContent(out, rd, rr, sql_whole, request,fName);
49         //out.flush();
50         //out.close();
51             if(true) {
52             //  response.reset();
53                 ServletOutputStream outS = response.getOutputStream();
54                         java.io.File file = null;
55                         if(true && !raw) {
56                                 response.setContentType("application/octet-stream");
57                                 response.setHeader("Content-disposition","attachment;filename="+fName+".zip");
58                                 file = new java.io.File(AppUtils.getTempFolderPath()+""+fName+".zip");
59                         } else {
60                                 response.setContentType("application/csv");
61                                 response.setHeader("Content-disposition","attachment;filename="+fName+".csv");
62                                 file = new java.io.File(AppUtils.getTempFolderPath()+""+fName+".csv");
63                         }
64                 FileInputStream fileIn = new FileInputStream(file);
65                 int c;
66                         while((c=fileIn.read()) != -1){
67                         outS.write(c);
68                         }
69                         outS.flush();
70                         outS.close();
71                         fileIn.close();
72
73                  
74                 /*byte[] outputByte = new byte[4096];
75                 //copy binary contect to output stream
76                 while(fileIn.read(outputByte, 0, 4096) != -1) {
77                         outS.write(outputByte, 0, 4096);
78                 }
79                 fileIn.close();
80                 outS.flush();
81                 outS.close();*/
82             }
83         } catch(Exception e) {
84                 e.printStackTrace();
85                 Log.write("Fatal error [report_download_csv.jsp]: "+e.getMessage());
86         }
87 %>
88 <%!     private String nvl(String s)                  { return (s==null)?"":s; }
89         private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %>