Rev 474 | Rev 478 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 353 | espaco | 1 | package br.com.ec.controller; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 468 | blopes | 4 | import java.util.List; |
| 353 | espaco | 5 | |
| 6 | import javax.inject.Inject; |
||
| 7 | import javax.inject.Named; |
||
| 8 | |||
| 414 | espaco | 9 | import org.primefaces.model.StreamedContent; |
| 353 | espaco | 10 | import org.springframework.context.annotation.Scope; |
| 11 | |||
| 12 | import br.com.ec.controller.consultademanda.NotaFiscalConsultaPorDemanda; |
||
| 13 | import br.com.ec.core.generic.GenericService; |
||
| 474 | blopes | 14 | import br.com.ec.core.util.VerificadorUtil; |
| 468 | blopes | 15 | import br.com.ec.domain.dto.CompraProdutoDTO; |
| 462 | blopes | 16 | import br.com.ec.domain.dto.NotaFiscalDTO; |
| 17 | import br.com.ec.domain.dto.NotaFiscalProdutoDTO; |
||
| 18 | import br.com.ec.domain.dto.ProdutoDTO; |
||
| 353 | espaco | 19 | import br.com.ec.domain.dto.consulta.ParametrosConsultaNotaFiscal; |
| 20 | import br.com.ec.domain.model.NotaFiscal; |
||
| 449 | blopes | 21 | import br.com.ec.domain.model.Pessoa; |
| 477 | blopes | 22 | import br.com.ec.domain.model.Transportadora; |
| 474 | blopes | 23 | import br.com.ec.domain.model.Transporte; |
| 413 | espaco | 24 | import br.com.ec.domain.model.Venda; |
| 465 | blopes | 25 | import br.com.ec.domain.model.nfe.TipoModeloNotaFiscal; |
| 353 | espaco | 26 | import br.com.ec.domain.model.nfe.TipoNotaFiscal; |
| 474 | blopes | 27 | import br.com.ec.domain.model.tipos.TipoModalidadeFrete; |
| 468 | blopes | 28 | import br.com.ec.domain.service.CompraProdutoService; |
| 414 | espaco | 29 | import br.com.ec.domain.service.EmissorRelatorioService; |
| 462 | blopes | 30 | import br.com.ec.domain.service.NotaFiscalProdutoService; |
| 353 | espaco | 31 | import br.com.ec.domain.service.NotaFiscalService; |
| 462 | blopes | 32 | import br.com.ec.domain.service.ProdutoService; |
| 353 | espaco | 33 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 34 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 446 | blopes | 35 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandRelatorioStreamedContent; |
| 353 | espaco | 36 | import br.com.ec.web.generic.AbstractBean; |
| 37 | import br.com.ec.web.message.LancadorMensagem; |
||
| 38 | import br.com.ec.web.util.TipoOperacao; |
||
| 39 | |||
| 40 | @Named |
||
| 41 | @Scope("view") |
||
| 42 | public class NotaFiscalBean extends AbstractBean<NotaFiscal> implements Serializable { |
||
| 43 | |||
| 44 | private static final long serialVersionUID = 1L; |
||
| 45 | |||
| 467 | blopes | 46 | private String statusSefaz = ""; |
| 353 | espaco | 47 | |
| 48 | private ParametrosConsultaNotaFiscal parametrosConsultaNotaFiscal; |
||
| 49 | private NotaFiscalConsultaPorDemanda lazy; |
||
| 50 | |||
| 51 | private Long sequencialVendaParaVinculo; |
||
| 446 | blopes | 52 | private StreamedContent danfeNfePreVisualizacao; |
| 414 | espaco | 53 | private StreamedContent danfeNfe; |
| 449 | blopes | 54 | |
| 462 | blopes | 55 | private String codigoProdutoParaVinculoNotaFiscal = ""; |
| 56 | private Integer quantidadeProdutoParaVinculoNotaFiscal = 0; |
||
| 57 | private ProdutoDTO produtoDTOParaVinculoNotaFiscal; |
||
| 468 | blopes | 58 | private CompraProdutoDTO compraProdutoDTOParaVinculoNotaFiscal; |
| 59 | private List<CompraProdutoDTO> listaCompraProdutoDTOParaVinculoNotaFiscal; |
||
| 462 | blopes | 60 | |
| 61 | private String chaveNotaFiscalParaReferenciaNotaFiscal = ""; |
||
| 62 | private NotaFiscalDTO notaFiscalDTOParaReferenciaNotaFiscal; |
||
| 63 | |||
| 467 | blopes | 64 | private NotaFiscalService notaFiscalService; |
| 65 | private NotaFiscalProdutoService notaFiscalProdutoService; |
||
| 66 | private ProdutoService produtoService; |
||
| 468 | blopes | 67 | private CompraProdutoService compraProdutoService; |
| 467 | blopes | 68 | private EmissorRelatorioService emissorRelatorioService; |
| 69 | |||
| 353 | espaco | 70 | @Inject |
| 462 | blopes | 71 | public NotaFiscalBean(NotaFiscalConsultaPorDemanda lazy, NotaFiscalService notaFiscalService, NotaFiscalProdutoService notaFiscalProdutoService, |
| 472 | blopes | 72 | ProdutoService produtoService, CompraProdutoService compraProdutoService, |
| 468 | blopes | 73 | EmissorRelatorioService emissorRelatorioService) { |
| 353 | espaco | 74 | this.lazy = lazy; |
| 75 | this.notaFiscalService = notaFiscalService; |
||
| 462 | blopes | 76 | this.notaFiscalProdutoService = notaFiscalProdutoService; |
| 77 | this.produtoService = produtoService; |
||
| 468 | blopes | 78 | this.compraProdutoService = compraProdutoService; |
| 414 | espaco | 79 | this.emissorRelatorioService = emissorRelatorioService; |
| 353 | espaco | 80 | } |
| 81 | |||
| 82 | @Override |
||
| 83 | public void preCarregamento() { |
||
| 84 | parametrosConsultaNotaFiscal = new ParametrosConsultaNotaFiscal(); |
||
| 85 | prepararConsultaDemanda(); |
||
| 86 | limparEntidade(); |
||
| 87 | } |
||
| 88 | |||
| 89 | @Override |
||
| 90 | public void limparEntidade() { |
||
| 91 | setEntidade(new NotaFiscal()); |
||
| 92 | } |
||
| 93 | |||
| 94 | @Override |
||
| 95 | public GenericService<NotaFiscal> getService() { |
||
| 96 | return notaFiscalService; |
||
| 97 | } |
||
| 98 | |||
| 99 | @Override |
||
| 100 | public NotaFiscal getEntidade() { |
||
| 101 | return entidade; |
||
| 102 | } |
||
| 103 | |||
| 104 | @Override |
||
| 105 | public void preConsultar() { |
||
| 106 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 107 | } |
||
| 449 | blopes | 108 | |
| 474 | blopes | 109 | @Override |
| 110 | public void preAlterar(NotaFiscal notaFiscal) { |
||
| 111 | if (VerificadorUtil.estaNulo(notaFiscal.getTransporte())) { |
||
| 112 | notaFiscal.setTransporte(new Transporte()); |
||
| 113 | } |
||
| 114 | super.preAlterar(notaFiscal); |
||
| 115 | } |
||
| 116 | |||
| 449 | blopes | 117 | /* |
| 353 | espaco | 118 | @Override |
| 449 | blopes | 119 | public void preAlterar(NotaFiscal notaFiscal) { |
| 120 | NotaFiscal notaFiscalDetalhada = notaFiscalService.detalhar(notaFiscal.getSequencial()); |
||
| 121 | super.preAlterar(notaFiscalDetalhada); |
||
| 122 | } |
||
| 123 | */ |
||
| 124 | |||
| 125 | @Override |
||
| 353 | espaco | 126 | public NotaFiscal getId() { |
| 127 | return getEntidade(); |
||
| 128 | } |
||
| 129 | |||
| 130 | public ParametrosConsultaNotaFiscal getParametrosConsultaNotaFiscal() { |
||
| 131 | return parametrosConsultaNotaFiscal; |
||
| 132 | } |
||
| 133 | public void setParametrosConsultaNotaFiscal(ParametrosConsultaNotaFiscal parametrosConsultaNotaFiscal) { |
||
| 134 | this.parametrosConsultaNotaFiscal = parametrosConsultaNotaFiscal; |
||
| 135 | } |
||
| 136 | |||
| 137 | public NotaFiscalConsultaPorDemanda getLazy() { |
||
| 138 | return lazy; |
||
| 139 | } |
||
| 140 | public void setLazy(NotaFiscalConsultaPorDemanda lazy) { |
||
| 141 | this.lazy = lazy; |
||
| 142 | } |
||
| 143 | public void prepararConsultaDemanda() { |
||
| 144 | lazy.setarParametrosConsulta(getParametrosConsultaNotaFiscal()); |
||
| 145 | } |
||
| 146 | |||
| 147 | public TipoNotaFiscal[] getTiposNotaFiscal() { |
||
| 148 | return TipoNotaFiscal.values(); |
||
| 149 | } |
||
| 150 | |||
| 474 | blopes | 151 | public TipoModalidadeFrete[] getTiposModalidadeFrete() { |
| 152 | return TipoModalidadeFrete.values(); |
||
| 153 | } |
||
| 154 | |||
| 353 | espaco | 155 | public Long getSequencialVendaParaVinculo() { |
| 156 | return sequencialVendaParaVinculo; |
||
| 157 | } |
||
| 158 | public void setSequencialVendaParaVinculo(Long sequencialVendaParaVinculo) { |
||
| 159 | this.sequencialVendaParaVinculo = sequencialVendaParaVinculo; |
||
| 160 | } |
||
| 161 | |||
| 446 | blopes | 162 | public StreamedContent getDanfeNfePreVisualizacao() { |
| 163 | return danfeNfePreVisualizacao; |
||
| 164 | } |
||
| 165 | public void setDanfeNfePreVisualizacao(StreamedContent danfeNfePreVisualizacao) { |
||
| 166 | this.danfeNfePreVisualizacao = danfeNfePreVisualizacao; |
||
| 167 | } |
||
| 168 | |||
| 414 | espaco | 169 | public StreamedContent getDanfeNfe() { |
| 170 | return danfeNfe; |
||
| 171 | } |
||
| 172 | public void setDanfeNfe(StreamedContent danfeNfe) { |
||
| 173 | this.danfeNfe = danfeNfe; |
||
| 174 | } |
||
| 175 | |||
| 462 | blopes | 176 | public String getCodigoProdutoParaVinculoNotaFiscal() { |
| 177 | return codigoProdutoParaVinculoNotaFiscal; |
||
| 178 | } |
||
| 179 | public void setCodigoProdutoParaVinculoNotaFiscal(String codigoProdutoParaVinculoNotaFiscal) { |
||
| 180 | this.codigoProdutoParaVinculoNotaFiscal = codigoProdutoParaVinculoNotaFiscal; |
||
| 181 | } |
||
| 182 | |||
| 183 | public Integer getQuantidadeProdutoParaVinculoNotaFiscal() { |
||
| 184 | return quantidadeProdutoParaVinculoNotaFiscal; |
||
| 185 | } |
||
| 186 | public void setQuantidadeProdutoParaVinculoNotaFiscal(Integer quantidadeProdutoParaVinculoNotaFiscal) { |
||
| 187 | this.quantidadeProdutoParaVinculoNotaFiscal = quantidadeProdutoParaVinculoNotaFiscal; |
||
| 188 | } |
||
| 189 | |||
| 190 | public ProdutoDTO getProdutoDTOParaVinculoNotaFiscal() { |
||
| 191 | return produtoDTOParaVinculoNotaFiscal; |
||
| 192 | } |
||
| 193 | public void setProdutoDTOParaVinculoNotaFiscal(ProdutoDTO produtoDTOParaVinculoNotaFiscal) { |
||
| 194 | this.produtoDTOParaVinculoNotaFiscal = produtoDTOParaVinculoNotaFiscal; |
||
| 195 | } |
||
| 196 | |||
| 468 | blopes | 197 | public CompraProdutoDTO getCompraProdutoDTOParaVinculoNotaFiscal() { |
| 198 | return compraProdutoDTOParaVinculoNotaFiscal; |
||
| 199 | } |
||
| 200 | public void setCompraProdutoDTOParaVinculoNotaFiscal(CompraProdutoDTO compraProdutoDTOParaVinculoNotaFiscal) { |
||
| 201 | this.compraProdutoDTOParaVinculoNotaFiscal = compraProdutoDTOParaVinculoNotaFiscal; |
||
| 202 | } |
||
| 203 | |||
| 204 | public List<CompraProdutoDTO> getListaCompraProdutoDTOParaVinculoNotaFiscal() { |
||
| 205 | return listaCompraProdutoDTOParaVinculoNotaFiscal; |
||
| 206 | } |
||
| 207 | public void setListaCompraProdutoDTOParaVinculoNotaFiscal(List<CompraProdutoDTO> listaCompraProdutoDTOParaVinculoNotaFiscal) { |
||
| 208 | this.listaCompraProdutoDTOParaVinculoNotaFiscal = listaCompraProdutoDTOParaVinculoNotaFiscal; |
||
| 209 | } |
||
| 210 | |||
| 462 | blopes | 211 | public String getChaveNotaFiscalParaReferenciaNotaFiscal() { |
| 212 | return chaveNotaFiscalParaReferenciaNotaFiscal; |
||
| 213 | } |
||
| 214 | public void setChaveNotaFiscalParaReferenciaNotaFiscal(String chaveNotaFiscalParaReferenciaNotaFiscal) { |
||
| 215 | this.chaveNotaFiscalParaReferenciaNotaFiscal = chaveNotaFiscalParaReferenciaNotaFiscal; |
||
| 216 | } |
||
| 217 | |||
| 218 | public NotaFiscalDTO getNotaFiscalDTOParaReferenciaNotaFiscal() { |
||
| 219 | return notaFiscalDTOParaReferenciaNotaFiscal; |
||
| 220 | } |
||
| 221 | public void setNotaFiscalDTOParaReferenciaNotaFiscal(NotaFiscalDTO notaFiscalDTOParaReferenciaNotaFiscal) { |
||
| 222 | this.notaFiscalDTOParaReferenciaNotaFiscal = notaFiscalDTOParaReferenciaNotaFiscal; |
||
| 223 | } |
||
| 224 | |||
| 467 | blopes | 225 | public String getStatusSefaz() { |
| 226 | return statusSefaz; |
||
| 227 | } |
||
| 228 | public void setStatusSefaz(String statusSefaz) { |
||
| 229 | this.statusSefaz = statusSefaz; |
||
| 230 | } |
||
| 231 | |||
| 353 | espaco | 232 | /**************************************************/ |
| 233 | |||
| 467 | blopes | 234 | public void atualizarStatusSefaz() { |
| 235 | setStatusSefaz(notaFiscalService.retornarStatusSefaz()); |
||
| 236 | } |
||
| 237 | |||
| 353 | espaco | 238 | public void desvincularVenda() { |
| 239 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 240 | public void execute() { |
||
| 413 | espaco | 241 | notaFiscalService.desvincularVenda(getEntidade().getSequencial()); |
| 242 | getEntidade().setVenda(null); |
||
| 353 | espaco | 243 | LancadorMensagem.lancarSucesso("VENDA DESVINCULADA COM SUCESSO"); |
| 244 | } |
||
| 245 | }); |
||
| 246 | } |
||
| 247 | |||
| 248 | public void vincularVenda() { |
||
| 249 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 250 | public void execute() { |
||
| 413 | espaco | 251 | Venda vendaVinculada = notaFiscalService.vincularVenda(getEntidade().getSequencial(), getSequencialVendaParaVinculo()); |
| 252 | getEntidade().setVenda(vendaVinculada); |
||
| 353 | espaco | 253 | LancadorMensagem.lancarSucesso("VENDA VINCULADA COM SUCESSO"); |
| 254 | } |
||
| 255 | }); |
||
| 256 | } |
||
| 257 | |||
| 414 | espaco | 258 | public void emitirDanfeNfe(Long sequencialNotaFiscal) { |
| 447 | blopes | 259 | setDanfeNfePreVisualizacao(notaFiscalService.gerarDanfeNfePreVisualizacao(sequencialNotaFiscal)); |
| 414 | espaco | 260 | setDanfeNfe(notaFiscalService.gerarDanfeNfe(sequencialNotaFiscal)); |
| 446 | blopes | 261 | } |
| 262 | |||
| 263 | public void emitirDanfeNfePreVisualizacao(Long sequencialNotaFiscal) { |
||
| 264 | setDanfeNfePreVisualizacao(notaFiscalService.gerarDanfeNfePreVisualizacao(sequencialNotaFiscal)); |
||
| 265 | setDanfeNfe(notaFiscalService.gerarDanfeNfe(sequencialNotaFiscal)); |
||
| 414 | espaco | 266 | /* |
| 267 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 268 | @Override |
||
| 269 | public StreamedContent execute() { |
||
| 270 | return notaFiscalService.gerarDanfeNfe(getEntidade().getSequencial()); |
||
| 271 | } |
||
| 272 | }); |
||
| 273 | */ |
||
| 274 | } |
||
| 275 | |||
| 446 | blopes | 276 | public StreamedContent downloadNotaFiscal() { |
| 277 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 278 | @Override |
||
| 279 | public StreamedContent execute() { |
||
| 280 | return getDanfeNfe(); |
||
| 281 | } |
||
| 282 | }); |
||
| 283 | } |
||
| 284 | |||
| 425 | espaco | 285 | public void emitirDanfeNfeTeste() { |
| 286 | Long sequencialNotaFiscal = new Long(168722); |
||
| 446 | blopes | 287 | setDanfeNfePreVisualizacao(notaFiscalService.gerarDanfeNfePreVisualizacao(sequencialNotaFiscal)); |
| 425 | espaco | 288 | setDanfeNfe(notaFiscalService.gerarDanfeNfe(sequencialNotaFiscal)); |
| 289 | } |
||
| 290 | |||
| 449 | blopes | 291 | public void selecionarEmitente(final Pessoa pessoa) { |
| 292 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 293 | public void execute() { |
||
| 294 | getEntidade().setPessoaEmitente(pessoa); |
||
| 295 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 296 | } |
||
| 297 | }); |
||
| 298 | } |
||
| 299 | |||
| 300 | public void retirarEmitente() { |
||
| 301 | getEntidade().setPessoaEmitente(null); |
||
| 302 | } |
||
| 303 | |||
| 304 | public void selecionarDestinatario(final Pessoa pessoa) { |
||
| 305 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 306 | public void execute() { |
||
| 307 | getEntidade().setPessoaDestinatario(pessoa); |
||
| 308 | adicionandoParametroArgsConfirmandoAcao(true); |
||
| 309 | } |
||
| 310 | }); |
||
| 311 | } |
||
| 312 | |||
| 313 | public void retirarDestinatario() { |
||
| 314 | getEntidade().setPessoaDestinatario(null); |
||
| 315 | } |
||
| 316 | |||
| 465 | blopes | 317 | /************************************/ |
| 318 | /** REMESSA **/ |
||
| 319 | /************************************/ |
||
| 320 | |||
| 321 | public void prepararNotaFiscalRemessa() { |
||
| 322 | preCadastrar(); |
||
| 323 | getEntidade().setTipoModeloNotaFiscal(TipoModeloNotaFiscal.MODELO_NFE_55.getValor()); |
||
| 324 | getEntidade().setTipoNotaFiscal(TipoNotaFiscal.NFE_REMESSA.getValor()); |
||
| 325 | } |
||
| 326 | |||
| 327 | public void emitirNotaFiscalRemessa() { |
||
| 328 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 329 | public void execute() { |
||
| 330 | notaFiscalService.emitirNotaFiscalRemessa(getEntidade()); |
||
| 331 | limparEntidade(); |
||
| 332 | LancadorMensagem.lancarSucesso("NOTA DE REMESSA EMITIDA COM SUCESSO"); |
||
| 333 | } |
||
| 334 | }); |
||
| 335 | } |
||
| 336 | |||
| 449 | blopes | 337 | public void consultarProdutosVinculados() { |
| 338 | getEntidade().setListaProdutosVinculadosDTO(notaFiscalService.consultarProdutosVinculados(getEntidade().getSequencial())); |
||
| 339 | } |
||
| 340 | |||
| 468 | blopes | 341 | public void selecionarCompraProdutoParaVinculoNotaFiscal(CompraProdutoDTO compraProdutoDTO) { |
| 342 | setCompraProdutoDTOParaVinculoNotaFiscal(compraProdutoDTO); |
||
| 343 | } |
||
| 344 | |||
| 345 | |||
| 346 | |||
| 347 | |||
| 462 | blopes | 348 | public void excluirVinculoNotaFiscalProduto(NotaFiscalProdutoDTO notaFiscalProdutoDTO) { |
| 349 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 350 | public void execute() { |
||
| 351 | notaFiscalProdutoService.excluirNotaFiscalProduto(notaFiscalProdutoDTO); |
||
| 352 | consultarProdutosVinculados(); |
||
| 353 | LancadorMensagem.lancarSucesso("VÍNCULO EXCLUÍDO COM SUCESSO"); |
||
| 354 | } |
||
| 355 | }); |
||
| 356 | } |
||
| 357 | |||
| 358 | public void consultarProdutoParaVinculoNotaFiscal() { |
||
| 359 | setProdutoDTOParaVinculoNotaFiscal(produtoService.consultarProdutoDTOPorCodigoOuCodigoEAN(getCodigoProdutoParaVinculoNotaFiscal())); |
||
| 468 | blopes | 360 | setListaCompraProdutoDTOParaVinculoNotaFiscal(produtoService.consultarComprasDoProduto(getProdutoDTOParaVinculoNotaFiscal().getSequencial())); |
| 462 | blopes | 361 | } |
| 362 | |||
| 363 | public void vinculoProdutoNaNotaFiscal() { |
||
| 364 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 365 | public void execute() { |
||
| 366 | notaFiscalProdutoService.vinculoProdutoNaNotaFiscal(getEntidade().getSequencial(), |
||
| 468 | blopes | 367 | getProdutoDTOParaVinculoNotaFiscal().getSequencial(), |
| 368 | getCompraProdutoDTOParaVinculoNotaFiscal().getSequencial(), |
||
| 462 | blopes | 369 | getQuantidadeProdutoParaVinculoNotaFiscal()); |
| 370 | setCodigoProdutoParaVinculoNotaFiscal(""); |
||
| 371 | setProdutoDTOParaVinculoNotaFiscal(null); |
||
| 468 | blopes | 372 | setCompraProdutoDTOParaVinculoNotaFiscal(null); |
| 462 | blopes | 373 | setQuantidadeProdutoParaVinculoNotaFiscal(0); |
| 374 | consultarProdutosVinculados(); |
||
| 375 | LancadorMensagem.lancarSucesso("PRODUTO VINCULADO COM SUCESSO"); |
||
| 376 | } |
||
| 377 | }); |
||
| 378 | } |
||
| 379 | |||
| 380 | public void consultarNotaFiscalParaReferenciarNotaFiscal() { |
||
| 381 | setNotaFiscalDTOParaReferenciaNotaFiscal(notaFiscalService.consultarPorChave(getChaveNotaFiscalParaReferenciaNotaFiscal())); |
||
| 382 | } |
||
| 383 | |||
| 413 | espaco | 384 | /* |
| 385 | private StreamedContent chart; |
||
| 386 | public StreamedContent getChart() { |
||
| 387 | return chart; |
||
| 388 | } |
||
| 389 | private PieDataset createDataset() { |
||
| 390 | DefaultPieDataset dataset = new DefaultPieDataset(); |
||
| 391 | dataset.setValue("New York", new Double(45.0)); |
||
| 392 | dataset.setValue("London", new Double(15.0)); |
||
| 393 | dataset.setValue("Paris", new Double(25.2)); |
||
| 394 | dataset.setValue("Berlin", new Double(14.8)); |
||
| 395 | return dataset; |
||
| 396 | } |
||
| 397 | |||
| 398 | private StreamedContent escala; |
||
| 399 | public StreamedContent getEscala() { |
||
| 400 | return escala; |
||
| 401 | } |
||
| 402 | |||
| 403 | private StreamedContent escalaPdf; |
||
| 404 | public StreamedContent getEscalaPdf() { |
||
| 405 | return escalaPdf; |
||
| 406 | } |
||
| 407 | public String generateRandomIdForNotCaching() { |
||
| 408 | return java.util.UUID.randomUUID().toString(); |
||
| 409 | } |
||
| 410 | |||
| 411 | private void criarImagens() { |
||
| 412 | try { |
||
| 413 | InputStream arquivoPdf = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/imagens/escala-202310.pdf"); |
||
| 414 | byte[] bytePdf = ArquivoUtil.retornarBytesPassandoInputStream(arquivoPdf); |
||
| 415 | ByteArrayOutputStream osPdf = new ByteArrayOutputStream(); |
||
| 416 | PdfReader reader = new PdfReader(bytePdf); |
||
| 417 | escalaPdf = DefaultStreamedContent.builder() |
||
| 418 | .contentType("application/pdf") |
||
| 419 | .name("escala-202310.pdf") |
||
| 420 | .stream(() -> { |
||
| 421 | try { |
||
| 422 | return ArquivoUtil.gerarInputStreamDeArquivo(bytePdf); |
||
| 423 | } catch (IOException e1) { |
||
| 424 | e1.printStackTrace(); |
||
| 425 | } |
||
| 426 | return arquivoPdf; |
||
| 427 | }) |
||
| 428 | .build(); |
||
| 429 | |||
| 430 | |||
| 431 | InputStream arquivo = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/imagens/escala-202310.png"); |
||
| 432 | BufferedImage imagem = ImageIO.read(arquivo); |
||
| 433 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
||
| 434 | ImageIO.write(imagem, "png", os); |
||
| 435 | escala = DefaultStreamedContent.builder() |
||
| 436 | .contentType("image/png") |
||
| 437 | .stream(() -> new ByteArrayInputStream(os.toByteArray())) |
||
| 438 | .build(); |
||
| 439 | |||
| 440 | |||
| 441 | chart = DefaultStreamedContent.builder() |
||
| 442 | .contentType("image/png") |
||
| 443 | .stream(() -> { |
||
| 444 | try { |
||
| 445 | JFreeChart jfreechart = ChartFactory.createPieChart("Cities", createDataset(), true, true, false); |
||
| 446 | File chartFile = new File("dynamichart"); |
||
| 447 | ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 375, 300); |
||
| 448 | return new FileInputStream(chartFile); |
||
| 449 | } |
||
| 450 | catch (Exception e) { |
||
| 451 | e.printStackTrace(); |
||
| 452 | return null; |
||
| 453 | } |
||
| 454 | }) |
||
| 455 | .build(); |
||
| 456 | } catch (IOException e1) { |
||
| 457 | // TODO Auto-generated catch block |
||
| 458 | e1.printStackTrace(); |
||
| 459 | } |
||
| 460 | } |
||
| 461 | */ |
||
| 353 | espaco | 462 | } |