EventoAditivoController.java
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package br.com.centralit.controller;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import br.com.centralit.api.model.EventoAditivo;
import br.com.centralit.api.service.DominioService;
import br.com.centralit.api.service.EventoAditivoService;
import br.com.centralit.api.service.InternacionalizacaoService;
import br.com.centralit.api.viewHelper.ViewsContrato;
import br.com.centralit.framework.controller.GenericController;
import br.com.centralit.framework.controller.ReportController;
import br.com.centralit.framework.exception.BusinessException;
import br.com.centralit.framework.json.ResponseBodyWrapper;
import br.com.centralit.framework.model.Dominio;
import br.com.centralit.framework.model.Usuario;
import br.com.centralit.framework.util.UtilDataBase;
/**
*
* <p><img src="http://centralit.com.br/images/logo_central.png"></p>
*
* <p><b>Company: </b> Central IT - Governança Corporativa - </p>
*
* <p><b>Title: </b></p>
*
* <p><b>Description: </b></p>
*
* <p><b>Iniciativa(s):</b> <a href="LINK_PORTAL">NUMERO_INICIATIVA</a></p>
*
* <p><b>Regra(s) de negócio:</b> <a href="LINK_PORTAL">NUMERO_REGRA_DE_NEGOCIO</a></p>
*
* @since 15/03/2016 - 18:30:22
*
* @version 1.0.0
*
* @author geovane.filho
*
*/
@Controller
@RequestMapping("/rest/eventoAditivo")
public class EventoAditivoController extends GenericController<EventoAditivo>{
private EventoAditivoService eventoAditivoService;
@Autowired
private DominioService dominioService;
@Autowired
private InternacionalizacaoService internacionalizacaoService;
@Autowired
private ReportController reportController;
public EventoAditivoController() {
super();
}
@Autowired
public EventoAditivoController(EventoAditivoService eventoAditivoService) {
super(eventoAditivoService);
this.eventoAditivoService = eventoAditivoService;
}
@Override
public Class<ViewsContrato.EventoAditivoEditView> getEditView() {
return ViewsContrato.EventoAditivoEditView.class;
}
@RequestMapping(value = "/findAllByContrato", method = RequestMethod.POST)
@ResponseBody
public ResponseBodyWrapper findAllByContrato(@RequestBody Long contratoId) {
Collection<EventoAditivo> aditivos = this.eventoAditivoService.findAllByContrato(contratoId);
ResponseBodyWrapper responseBody = new ResponseBodyWrapper(aditivos, ViewsContrato.EventoAditivoEditView.class);
return responseBody;
}
@RequestMapping(method = RequestMethod.GET, value = "/gerarAditivo")
@ResponseBody
public void generatePdfRMB(@RequestParam(value="idAditivo") Long idAditivo, @RequestParam(value="download") boolean download, HttpServletResponse response,
HttpServletRequest request) throws SQLException, JRException, IOException {
Dominio idioma = this.dominioService.findByChaveAndCodigo(Dominio.TIPO_IDIOMA, Dominio.TIPO_IDIOMA_PT_BR_CODIGO);
Usuario user = (Usuario) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Connection conn = null;
ByteArrayOutputStream baos = null;
try {
conn = reportController.getConnection();
String titulo = this.internacionalizacaoService.getTranslate("CONTRATOS.LABEL.TITULO_RELATORIO_ADITIVO", idioma);
JasperPrint jasperPrint = this.eventoAditivoService.getJasperPrintAditivo(idAditivo, conn, user, titulo);
// Responsavel por verificar a presenca de dados no relatorio
reportController.gerarRelatorio(download, "pdf", jasperPrint, response, baos, titulo);
} catch (JRException jre) {
throw new RuntimeException(jre);
} catch (Exception e) {
throw new BusinessException();
}finally {
UtilDataBase.closeResources(conn, baos);
}
}
}