Rev 325 | Rev 530 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 325 | espaco | 1 | package br.com.ec.controller; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.List; |
||
| 5 | |||
| 6 | import javax.inject.Inject; |
||
| 7 | import javax.inject.Named; |
||
| 8 | |||
| 528 | blopes | 9 | import org.primefaces.event.FileUploadEvent; |
| 325 | espaco | 10 | import org.springframework.context.annotation.Scope; |
| 11 | |||
| 12 | import br.com.ec.controller.consultademanda.EstampaConsultaPorDemanda; |
||
| 13 | import br.com.ec.core.generic.GenericService; |
||
| 14 | import br.com.ec.domain.dto.EstampaDTO; |
||
| 528 | blopes | 15 | import br.com.ec.domain.dto.ImagemDTO; |
| 325 | espaco | 16 | import br.com.ec.domain.dto.TemaEstampaDTO; |
| 17 | import br.com.ec.domain.dto.consulta.ParametrosConsultaEstampaDTO; |
||
| 18 | import br.com.ec.domain.model.Estampa; |
||
| 19 | import br.com.ec.domain.model.TemaEstampa; |
||
| 20 | import br.com.ec.domain.service.EstampaService; |
||
| 21 | import br.com.ec.domain.service.TemaEstampaService; |
||
| 528 | blopes | 22 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 23 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 325 | espaco | 24 | import br.com.ec.web.generic.AbstractBean; |
| 528 | blopes | 25 | import br.com.ec.web.message.LancadorMensagem; |
| 325 | espaco | 26 | import br.com.ec.web.util.TipoOperacao; |
| 27 | |||
| 28 | @Named |
||
| 29 | @Scope("view") |
||
| 30 | public class EstampaBean extends AbstractBean<Estampa> implements Serializable { |
||
| 31 | |||
| 32 | private static final long serialVersionUID = 1L; |
||
| 33 | |||
| 34 | private EstampaService estampaService; |
||
| 35 | private EstampaDTO entidadeParaConsulta; |
||
| 36 | private List<EstampaDTO> estampas; |
||
| 37 | |||
| 38 | private ParametrosConsultaEstampaDTO parametrosConsultaEstampaDTO; |
||
| 39 | private EstampaConsultaPorDemanda lazy; |
||
| 40 | |||
| 41 | @Inject |
||
| 42 | public EstampaBean(EstampaService estampaService, EstampaConsultaPorDemanda lazy) { |
||
| 43 | this.estampaService = estampaService; |
||
| 44 | this.lazy = lazy; |
||
| 45 | } |
||
| 46 | |||
| 47 | @Override |
||
| 48 | public void preCarregamento() { |
||
| 49 | parametrosConsultaEstampaDTO = new ParametrosConsultaEstampaDTO(); |
||
| 50 | prepararConsultaDemanda(); |
||
| 51 | limparEntidade(); |
||
| 52 | } |
||
| 53 | |||
| 54 | @Override |
||
| 55 | public void limparEntidade() { |
||
| 56 | setEntidade(new Estampa()); |
||
| 57 | getEntidade().setTemaEstampa(new TemaEstampa(new Long(1))); |
||
| 58 | setEntidadeParaConsulta(new EstampaDTO()); |
||
| 59 | } |
||
| 60 | |||
| 61 | @Override |
||
| 62 | public GenericService<Estampa> getService() { |
||
| 63 | return estampaService; |
||
| 64 | } |
||
| 65 | |||
| 66 | @Override |
||
| 67 | public Estampa getEntidade() { |
||
| 68 | return entidade; |
||
| 69 | } |
||
| 70 | |||
| 71 | @Override |
||
| 72 | public void preConsultar() { |
||
| 73 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 74 | } |
||
| 75 | |||
| 76 | @Override |
||
| 77 | public Estampa getId() { |
||
| 78 | return getEntidade(); |
||
| 79 | } |
||
| 80 | |||
| 528 | blopes | 81 | @Override |
| 82 | public void cadastrar(final Estampa entidade) { |
||
| 83 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 84 | public void execute() { |
||
| 85 | modificarEntidadeAntesDaOperacao(); |
||
| 86 | getService().cadastrar(entidade); |
||
| 87 | modificarEntidadeDepoisDaOperacao(); |
||
| 88 | LancadorMensagem.lancarSucesso(getMensagens().get(IDENTIFICADOR_MENSAGEM_CADASTRADO_COM_SUCESSO)); |
||
| 89 | preAlterar(entidade); |
||
| 90 | } |
||
| 91 | }); |
||
| 92 | } |
||
| 93 | |||
| 325 | espaco | 94 | /*********************************************************/ |
| 95 | |||
| 96 | public EstampaDTO getEntidadeParaConsulta() { |
||
| 97 | return entidadeParaConsulta; |
||
| 98 | } |
||
| 99 | public void setEntidadeParaConsulta(EstampaDTO entidadeParaConsulta) { |
||
| 100 | this.entidadeParaConsulta = entidadeParaConsulta; |
||
| 101 | } |
||
| 102 | |||
| 103 | public List<EstampaDTO> getEstampas() { |
||
| 104 | return estampas; |
||
| 105 | } |
||
| 106 | public void setEstampas(List<EstampaDTO> estampas) { |
||
| 107 | this.estampas = estampas; |
||
| 108 | } |
||
| 109 | |||
| 110 | public ParametrosConsultaEstampaDTO getParametrosConsultaEstampaDTO() { |
||
| 111 | return parametrosConsultaEstampaDTO; |
||
| 112 | } |
||
| 113 | public void setParametrosConsultaEstampaDTO(ParametrosConsultaEstampaDTO parametrosConsultaEstampaDTO) { |
||
| 114 | this.parametrosConsultaEstampaDTO = parametrosConsultaEstampaDTO; |
||
| 115 | } |
||
| 116 | |||
| 117 | public EstampaConsultaPorDemanda getLazy() { |
||
| 118 | return lazy; |
||
| 119 | } |
||
| 120 | public void setLazy(EstampaConsultaPorDemanda lazy) { |
||
| 121 | this.lazy = lazy; |
||
| 122 | } |
||
| 123 | public void prepararConsultaDemanda() { |
||
| 124 | lazy.setarParametrosConsulta(getParametrosConsultaEstampaDTO()); |
||
| 125 | } |
||
| 126 | |||
| 127 | /*********************************************************/ |
||
| 128 | |||
| 129 | public void prepararDetalhar(TemaEstampaDTO temaEstampaDTO) { |
||
| 130 | // super.preDetalhar(temaEstampaService.consultarPorId(new TemaEstampa(temaEstampaDTO.getSequencial()))); |
||
| 131 | } |
||
| 132 | |||
| 133 | public void prepararAlterar(TemaEstampaDTO temaEstampaDTO) { |
||
| 134 | // super.preAlterar(temaEstampaService.consultarPorId(new TemaEstampa(temaEstampaDTO.getSequencial()))); |
||
| 135 | } |
||
| 136 | |||
| 137 | private void consultarEstampas() { |
||
| 138 | setEstampas(estampaService.consultarEstampas(getEntidadeParaConsulta().getTemaEstampa())); |
||
| 139 | } |
||
| 140 | |||
| 528 | blopes | 141 | public void uploadImagem(final FileUploadEvent e) { |
| 142 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 143 | public void execute() { |
||
| 144 | |||
| 145 | /* |
||
| 146 | EstampaDTO imagemAdicionada = gerarArquivo(e.getFile()); |
||
| 147 | imagemAdicionada.setDescricao("promocoes_" + getEntidade().getVigencia().getSequencial()); |
||
| 148 | lancarExcecaoCasoArquivoExcedeuLimite(imagemAdicionada); |
||
| 149 | // imagemAdicionada.compactarImagem(); |
||
| 150 | // imagemAdicionada.converterPngParaJpg(); |
||
| 151 | setImagemParaUpload(e.getFile()); |
||
| 152 | uploadFisico(imagemAdicionada); |
||
| 153 | LancadorMensagem.lancarSucessoRedirecionandoTela("IMAGEM ADICIONADA COM SUCESSO", "/sistema/metas/metas.xhtml"); |
||
| 154 | */ |
||
| 155 | } |
||
| 156 | }); |
||
| 157 | } |
||
| 158 | |||
| 325 | espaco | 159 | } |