1 package ecar.servlet.relatorio.PPA_Orgao;
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 RelatorioPPAOrgaoServlet extends RelatorioServlet {
27
28
29 private static final long serialVersionUID = 5664707298670877576L;
30 private Logger logger = Logger.getLogger(this.getClass());
31
32 public RelatorioPPAOrgaoServlet(){
33 super();
34 }
35
36 public void doRelatorioGet(HttpServletRequest request, HttpServletResponse response) {
37 doRelatorioPost(request,response);
38 }
39
40 public void doRelatorioPost(HttpServletRequest request, HttpServletResponse response) {
41
42 logger.info("Generating relatorio PPA Por Orgao...");
43
44 final ServletContext context = getServletContext();
45
46 byte[] bytes = null;
47 Map parametros = new HashMap();
48 try {
49
50 String titulo = request.getParameter("titulo");
51 String pagina = request.getParameter("pagina");
52 String data = request.getParameter("data");
53 Integer paginaInt = null;
54
55 final RelatorioPPAOrgaoService service = RelatorioPPAOrgaoService.getInstance(request);
56
57
58
59 try {
60 if( pagina ==null || pagina.equals("") ){
61 paginaInt = Integer.valueOf(1);
62 }else{
63 paginaInt = Integer.valueOf( pagina );
64 }
65 } catch (Exception e) {
66 paginaInt = Integer.valueOf( 1 );
67 }
68
69 try {
70 if( data ==null || data.equals("") ){
71 data = "";
72 }
73 } catch (Exception e) {
74 data = "";
75 }
76
77 try {
78 if( titulo ==null || "".equals( titulo ) ){
79 titulo = "ESTADO DO PARANÁ - PLANO PLURIANUAL 2008/2011 - Demonstrativo por Órgão";
80 }
81 } catch (Exception e) {
82 titulo = "ESTADO DO PARANÁ - PLANO PLURIANUAL 2008/2011 - Demonstrativo por Órgão";
83 }
84
85
86 final String pathRelPPA = context.getRealPath( JasperService.PATH_RELATORIO + "/relatorioPPAOrgao.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_OrgaoBean> 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 Orgao",e);
116 }
117
118 }
119
120
121 }