1 package ecar.servlet.relatorio.PPA_LinhaPrograma;
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.servlet.relatorio.PPA_LinhaAcao.PPA_LinhaAcaoBean;
19 import ecar.util.jasper.JasperService;
20 import ecar.util.jasper.servlet.RelatorioServlet;
21
22
23
24
25
26
27 public class RelatorioPPALinhaProgramaServlet extends RelatorioServlet {
28
29
30 private static final long serialVersionUID = -4656806634943646057L;
31 private Logger logger = Logger.getLogger(this.getClass());
32
33 public RelatorioPPALinhaProgramaServlet(){
34 super();
35 }
36
37 public void doRelatorioGet(HttpServletRequest request, HttpServletResponse response) {
38 doRelatorioPost(request,response);
39 }
40
41 public void doRelatorioPost(HttpServletRequest request, HttpServletResponse response) {
42
43 logger.info("Generating relatorio PPA Por Linha de Ação e Programa...");
44
45 final ServletContext context = getServletContext();
46
47 byte[] bytes = null;
48 Map parametros = new HashMap();
49 try {
50
51 String titulo = request.getParameter("titulo");
52 String pagina = request.getParameter("pagina");
53 String data = request.getParameter("data");
54 Integer paginaInt = null;
55
56 final RelatorioPPALinhaProgramaService service = RelatorioPPALinhaProgramaService.getInstance(request);
57
58 try {
59 if( pagina ==null || pagina.equals("") ){
60 paginaInt = Integer.valueOf(1);
61 }else{
62 paginaInt = Integer.valueOf( pagina );
63 }
64 } catch (Exception e) {
65 paginaInt = Integer.valueOf( 1 );
66 }
67
68 try {
69 if( data ==null || data.equals("") ){
70 data = "";
71 }
72 } catch (Exception e) {
73 data = "";
74 }
75
76 try {
77 if( titulo ==null || "".equals( titulo ) ){
78 titulo = "ESTADO DO PARANÁ - PLANO PLURIANUAL 2008/2011 - Demonstrativo por Órgão";
79 }
80 } catch (Exception e) {
81 titulo = "ESTADO DO PARANÁ - PLANO PLURIANUAL 2008/2011 - Demonstrativo por Órgão";
82 }
83
84
85
86 final String pathRelPPA = context.getRealPath( JasperService.PATH_RELATORIO + "/relatorioPPALinhaAcaoPrograma.jasper" );
87 final String pathRelPPACapa = context.getRealPath( JasperService.PATH_RELATORIO + "/relatorioPPA_Demonstrativos_capa.jasper" );
88
89 JasperReport relatorioJasper = JasperService.loadReport( pathRelPPA );
90 JasperReport relatorioCapaJasper = JasperService.loadReport( pathRelPPACapa );
91 this.redirectDefaultErrorIfNull(request, response, relatorioJasper);
92
93 ArrayList<PPA_LinhaAcaoBean> relatorioDS = service.generatePPA();
94 this.redirectDefaultErrorIfNull(request, response, relatorioDS);
95
96 parametros.put("pagina", paginaInt );
97 parametros.put( "data" , data );
98 parametros.put( "titulo" , titulo );
99 parametros.put("totalExer1", service.getTotalGeral1() );
100 parametros.put("totalExer2", service.getTotalGeral2() );
101 parametros.put("totalExer3", service.getTotalGeral3() );
102 parametros.put("totalExer4", service.getTotalGeral4() );
103 parametros.put("totalGeral", service.getTotalGeral() );
104
105 JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(relatorioDS);
106
107 JasperPrint capa = JasperService.fillReport(relatorioCapaJasper,parametros );
108 JasperPrint rel = JasperService.fillReport(relatorioJasper,parametros, ds);
109
110 ByteArrayOutputStream out = new ByteArrayOutputStream();
111 JasperService.addRelatorio( capa, rel, out );
112 this.responseToPDF(response, out.toByteArray());
113
114 } catch (Exception e) {
115 logger.error( "Nao foi possivel gerar relatorio PPA por Linha de Ação e Programa",e);
116 }
117
118 }
119
120
121
122
123 }