Rev 106 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.InputStream; |
||
| 4 | import java.io.Serializable; |
||
| 5 | |||
| 6 | import javax.faces.context.FacesContext; |
||
| 7 | import javax.inject.Inject; |
||
| 8 | import javax.inject.Named; |
||
| 9 | import javax.servlet.ServletContext; |
||
| 10 | |||
| 11 | import org.primefaces.event.FileUploadEvent; |
||
| 12 | import org.primefaces.model.DefaultStreamedContent; |
||
| 13 | import org.primefaces.model.StreamedContent; |
||
| 14 | import org.primefaces.model.UploadedFile; |
||
| 15 | import org.springframework.context.annotation.Scope; |
||
| 16 | |||
| 195 | espaco | 17 | import br.com.ec.core.util.TipoExtensao; |
| 106 | espaco | 18 | import br.com.ec.domain.dto.ArquivoDTO; |
| 19 | import br.com.ec.domain.dto.ArquivoFuncionarioDTO; |
||
| 20 | import br.com.ec.domain.model.tipos.TipoComissionamento; |
||
| 21 | import br.com.ec.domain.service.arquivo.ArquivoService; |
||
| 195 | espaco | 22 | import br.com.ec.relatorio.util.RelatorioUtils; |
| 23 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 24 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 25 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandRelatorioStreamedContent; |
||
| 26 | import br.com.ec.web.message.LancadorMensagem; |
||
| 106 | espaco | 27 | |
| 28 | @Named |
||
| 29 | @Scope("view") |
||
| 30 | public class ArquivoBean implements Serializable { |
||
| 31 | |||
| 32 | private static final long serialVersionUID = 1L; |
||
| 33 | |||
| 34 | private ArquivoDTO arquivo; |
||
| 35 | private String tipoComissionamentoSelecionado; |
||
| 36 | |||
| 37 | private UploadedFile arquivoParaUpload; |
||
| 38 | |||
| 39 | private ArquivoService arquivoService; |
||
| 40 | |||
| 41 | @Inject |
||
| 42 | public ArquivoBean(ArquivoService arquivoService) { |
||
| 43 | this.arquivoService = arquivoService; |
||
| 44 | } |
||
| 45 | |||
| 46 | public ArquivoDTO getArquivo() { |
||
| 47 | return arquivo; |
||
| 48 | } |
||
| 49 | public void setArquivo(ArquivoDTO arquivo) { |
||
| 50 | this.arquivo = arquivo; |
||
| 51 | } |
||
| 52 | |||
| 53 | public String getTipoComissionamentoSelecionado() { |
||
| 54 | return tipoComissionamentoSelecionado; |
||
| 55 | } |
||
| 56 | public void setTipoComissionamentoSelecionado(String tipoComissionamentoSelecionado) { |
||
| 57 | this.tipoComissionamentoSelecionado = tipoComissionamentoSelecionado; |
||
| 58 | } |
||
| 59 | |||
| 60 | public UploadedFile getArquivoParaUpload() { |
||
| 61 | return arquivoParaUpload; |
||
| 62 | } |
||
| 63 | public void setArquivoParaUpload(UploadedFile arquivoParaUpload) { |
||
| 64 | this.arquivoParaUpload = arquivoParaUpload; |
||
| 65 | } |
||
| 66 | |||
| 67 | public void uploadArquivoEspacoCase(final FileUploadEvent e) { |
||
| 68 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 69 | public void execute() { |
||
| 70 | setTipoComissionamentoSelecionado(TipoComissionamento.COMISSSIONAMENTO_ESPACO_CASE.getValor()); |
||
| 71 | setArquivo(arquivoService.separarRecibos(new ArquivoDTO(e.getFile()), getTipoComissionamentoSelecionado(), ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()))); |
||
| 72 | } |
||
| 73 | }); |
||
| 74 | } |
||
| 75 | |||
| 76 | public void uploadArquivoCasaDasCapas(final FileUploadEvent e) { |
||
| 77 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 78 | public void execute() { |
||
| 79 | setTipoComissionamentoSelecionado(TipoComissionamento.COMISSSIONAMENTO_CASA_DAS_CAPAS.getValor()); |
||
| 80 | setArquivo(arquivoService.separarRecibos(new ArquivoDTO(e.getFile()), getTipoComissionamentoSelecionado(), ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()))); |
||
| 81 | } |
||
| 82 | }); |
||
| 83 | } |
||
| 84 | |||
| 85 | public void uploadArquivoVivo(final FileUploadEvent e) { |
||
| 86 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 87 | public void execute() { |
||
| 88 | setTipoComissionamentoSelecionado(TipoComissionamento.COMISSSIONAMENTO_VIVO.getValor()); |
||
| 89 | setArquivo(arquivoService.separarRecibos(new ArquivoDTO(e.getFile()), getTipoComissionamentoSelecionado(), ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()))); |
||
| 90 | } |
||
| 91 | }); |
||
| 92 | } |
||
| 93 | |||
| 94 | public void uploadArquivoFarmacia(final FileUploadEvent e) { |
||
| 95 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 96 | public void execute() { |
||
| 97 | setTipoComissionamentoSelecionado(TipoComissionamento.COMISSSIONAMENTO_FARMACIA.getValor()); |
||
| 98 | setArquivo(arquivoService.separarRecibos(new ArquivoDTO(e.getFile()), getTipoComissionamentoSelecionado(), ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()))); |
||
| 99 | } |
||
| 100 | }); |
||
| 101 | } |
||
| 102 | |||
| 103 | public StreamedContent downloadArquivo(final ArquivoDTO arquivoDTO) { |
||
| 104 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 105 | @Override |
||
| 106 | public StreamedContent execute() { |
||
| 107 | return RelatorioUtils.gerarArquivo(arquivoDTO.getArquivo(), "arquivo", TipoExtensao.parse(arquivoDTO.getExtensao()).getValue()); |
||
| 108 | } |
||
| 109 | }); |
||
| 110 | } |
||
| 111 | |||
| 112 | public StreamedContent downloadArquivo(final byte[] arquivo, final String extensao) { |
||
| 113 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 114 | @Override |
||
| 115 | public StreamedContent execute() { |
||
| 116 | return RelatorioUtils.gerarArquivo(arquivo, "recibo", TipoExtensao.parse(extensao).getValue()); |
||
| 117 | } |
||
| 118 | }); |
||
| 119 | } |
||
| 120 | |||
| 121 | public void retirarArquivo() { |
||
| 122 | setArquivo(null); |
||
| 123 | } |
||
| 124 | |||
| 125 | public StreamedContent emitirRecibos(final ArquivoDTO arquivoDTO) throws Exception { |
||
| 126 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 127 | @Override |
||
| 128 | public StreamedContent execute() { |
||
| 129 | return arquivoService.gerarRecibos(arquivoDTO, ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext())); |
||
| 130 | } |
||
| 131 | }); |
||
| 132 | } |
||
| 133 | |||
| 134 | public void enviarRecibos(final ArquivoDTO arquivoDTO) throws Exception { |
||
| 135 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 136 | public void execute() { |
||
| 137 | arquivoService.enviarRecibos(arquivoDTO, getTipoComissionamentoSelecionado(), ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext())); |
||
| 138 | LancadorMensagem.lancarSucesso("RECIBOS ENVIADOS COM SUCESSO!"); |
||
| 139 | } |
||
| 140 | }); |
||
| 141 | } |
||
| 142 | |||
| 143 | public StreamedContent processarRecibos(final ArquivoDTO arquivoDTO) throws Exception { |
||
| 144 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 145 | @Override |
||
| 146 | public StreamedContent execute() { |
||
| 147 | arquivoService.separarEnviarRecibos(arquivoDTO, getTipoComissionamentoSelecionado(), ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext())); |
||
| 148 | return arquivoService.gerarRecibos(arquivoDTO, ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext())); |
||
| 149 | } |
||
| 150 | }); |
||
| 151 | } |
||
| 152 | |||
| 153 | public StreamedContent downloadPastaArquivos(final String nomeArquivo, final String extensao) { |
||
| 154 | return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() { |
||
| 155 | @Override |
||
| 156 | public StreamedContent execute() { |
||
| 157 | InputStream arquivo = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/arquivos/" + nomeArquivo + "." + extensao); |
||
| 158 | return new DefaultStreamedContent(arquivo, TipoExtensao.parse(extensao).getDescricao(), nomeArquivo + "." + extensao); |
||
| 159 | // return new DefaultStreamedContent(arquivo, TipoExtensao.PDF.getDescricao(), nomeArquivo + "." + extensao); |
||
| 160 | } |
||
| 161 | }); |
||
| 162 | } |
||
| 163 | |||
| 164 | public void selecionarTodosParaEnviarEmail() { |
||
| 165 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 166 | public void execute() { |
||
| 167 | for (ArquivoFuncionarioDTO arquivoFuncionario : getArquivo().getArquivosFuncionarios()) { |
||
| 168 | if (arquivoFuncionario.getEnviarEmail()) { |
||
| 169 | arquivoFuncionario.setEnviarEmail(false); |
||
| 170 | } else { |
||
| 171 | arquivoFuncionario.setEnviarEmail(true); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 175 | }); |
||
| 176 | } |
||
| 177 | |||
| 178 | } |