1 package ecar.servlet.relatorio.PPA_Programa;
2
3 import java.io.ByteArrayOutputStream;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.Map;
7
8 import javax.servlet.ServletContext;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 import net.sf.jasperreports.engine.JasperPrint;
13 import net.sf.jasperreports.engine.JasperReport;
14 import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
15
16 import org.apache.log4j.Logger;
17
18 import ecar.util.jasper.JasperService;
19 import ecar.util.jasper.servlet.RelatorioServlet;
20
21
22
23
24
25
26 public class RelatorioPPAProgramaServlet extends RelatorioServlet {
27
28 private static final long serialVersionUID = 7044746259478772547L;
29 private Logger logger = Logger.getLogger(this.getClass());
30
31 public RelatorioPPAProgramaServlet(){
32 super();
33 }
34
35 public void doRelatorioGet(HttpServletRequest request, HttpServletResponse response) {
36 doRelatorioPost(request,response);
37 }
38
39 public void doRelatorioPost(HttpServletRequest request, HttpServletResponse response) {
40
41 logger.info("Generating relatorio PPA Por Programa...");
42
43 final ServletContext context = getServletContext();
44
45 byte[] bytes = null;
46 Map parametros = new HashMap();
47 try {
48
49 String titulo = request.getParameter("titulo");
50 String pagina = request.getParameter("pagina");
51 String data = request.getParameter("data");
52
53 Integer paginaInt = null;
54
55 try {
56 if( pagina ==null || pagina.equals("") ){
57 paginaInt = Integer.valueOf(1);
58 }else{
59 paginaInt = Integer.valueOf( pagina );
60 }
61 } catch (Exception e) {
62 paginaInt = Integer.valueOf( 1 );
63 }
64
65 try {
66 if( data ==null || data.equals("") ){
67 data = "";
68 }
69 } catch (Exception e) {
70 data = "";
71 }
72
73 try {
74 if( titulo ==null || "".equals( titulo ) ){
75 titulo = "ESTADO DO PARANÁ - PLANO PLURIANUAL 2008/2011 - Demonstrativo por Programa";
76 }
77 } catch (Exception e) {
78 titulo = "ESTADO DO PARANÁ - PLANO PLURIANUAL 2008/2011 - Demonstrativo por Programa";
79 }
80
81
82 final RelatorioPPAProgramaService service = RelatorioPPAProgramaService.getInstance(request);
83
84
85 final String pathRelPPA = context.getRealPath( JasperService.PATH_RELATORIO + "/relatorioPPAPrograma.jasper" );
86 final String pathRelPPACapa = context.getRealPath( JasperService.PATH_RELATORIO + "/relatorioPPA_Demonstrativos_capa.jasper" );
87
88 JasperReport relatorioJasper = JasperService.loadReport( pathRelPPA );
89 JasperReport relatorioCapaJasper = JasperService.loadReport( pathRelPPACapa );
90 this.redirectDefaultErrorIfNull(request, response, relatorioJasper);
91
92 ArrayList<PPA_ProgramaBean> relatorioDS = service.generatePPA();
93 this.redirectDefaultErrorIfNull(request, response, relatorioDS);
94
95 parametros.put("pagina", paginaInt );
96 parametros.put( "data" , data );
97 parametros.put( "titulo" , titulo );
98
99 JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(relatorioDS);
100
101 JasperPrint capa = JasperService.fillReport(relatorioCapaJasper,parametros );
102 JasperPrint rel = JasperService.fillReport(relatorioJasper,parametros, ds);
103
104 ByteArrayOutputStream out = new ByteArrayOutputStream();
105 JasperService.addRelatorio( capa, rel, out );
106 this.responseToPDF(response, out.toByteArray());
107
108 } catch (Exception e) {
109 logger.error( "Nao foi possivel gerar relatorio PPA por Programa",e);
110 }
111
112 }
113
114
115
116
117 }