Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | |||
| 5 | import javax.annotation.PostConstruct; |
||
| 6 | import javax.inject.Named; |
||
| 7 | |||
| 8 | import org.springframework.context.annotation.Scope; |
||
| 9 | |||
| 10 | import br.com.ec.domain.dto.MegaCombinacaoDTO; |
||
| 11 | import br.com.ec.domain.dto.MegaDTO; |
||
| 12 | import br.com.ec.domain.service.email.impl.GerenciadorEmailImpl; |
||
| 13 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 14 | import br.edu.cesmac.core.util.DataUtils; |
||
| 15 | import br.edu.cesmac.web.exception.VerificadorLancamentoException; |
||
| 16 | import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 17 | import br.edu.cesmac.web.message.LancadorMensagem; |
||
| 18 | |||
| 19 | @Named |
||
| 20 | @Scope("view") |
||
| 21 | public class MegaBean implements Serializable { |
||
| 22 | |||
| 23 | private static final long serialVersionUID = 1L; |
||
| 24 | |||
| 25 | private Integer limiteEscolhas = 20; |
||
| 26 | private MegaDTO megaDTO; |
||
| 27 | private Integer numero; |
||
| 28 | |||
| 29 | @PostConstruct |
||
| 30 | public void preCarregamento() { |
||
| 31 | megaDTO = new MegaDTO(); |
||
| 32 | } |
||
| 33 | |||
| 34 | public MegaDTO getMegaDTO() { |
||
| 35 | return megaDTO; |
||
| 36 | } |
||
| 37 | public void setMegaDTO(MegaDTO megaDTO) { |
||
| 38 | this.megaDTO = megaDTO; |
||
| 39 | } |
||
| 40 | |||
| 41 | public Integer getNumero() { |
||
| 42 | return numero; |
||
| 43 | } |
||
| 44 | public void setNumero(Integer numero) { |
||
| 45 | this.numero = numero; |
||
| 46 | } |
||
| 47 | |||
| 48 | public Integer getLimiteEscolhas() { |
||
| 49 | return limiteEscolhas; |
||
| 50 | } |
||
| 51 | public void setLimiteEscolhas(Integer limiteEscolhas) { |
||
| 52 | this.limiteEscolhas = limiteEscolhas; |
||
| 53 | } |
||
| 54 | |||
| 55 | /*********************************************/ |
||
| 56 | |||
| 57 | public void adicionarNumero() { |
||
| 58 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 59 | public void execute() { |
||
| 60 | getMegaDTO().adicionarNumero(getNumero()); |
||
| 61 | setNumero(null); |
||
| 62 | LancadorMensagem.lancarSucesso("NÚMERO ADICIONADO COM SUCESSO"); |
||
| 63 | } |
||
| 64 | }); |
||
| 65 | } |
||
| 66 | |||
| 67 | public void retirarNumeroEscolhido(final Integer numero) { |
||
| 68 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 69 | public void execute() { |
||
| 70 | getMegaDTO().retirarNumero(numero); |
||
| 71 | LancadorMensagem.lancarSucesso("NÚMERO RETIRADO COM SUCESSO"); |
||
| 72 | } |
||
| 73 | }); |
||
| 74 | } |
||
| 75 | |||
| 76 | public void gerarCombinacoes() { |
||
| 77 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 78 | public void execute() { |
||
| 79 | getMegaDTO().gerarCombinacoes(); |
||
| 80 | StringBuilder combinacoes = new StringBuilder(); |
||
| 81 | combinacoes.append("COMBINAÇÕES:"); |
||
| 82 | for (MegaCombinacaoDTO combinacao : getMegaDTO().getCombinacoes()) { |
||
| 83 | combinacoes.append(combinacao.getSequencia()); |
||
| 84 | } |
||
| 85 | |||
| 86 | String diaAtual = DataUtils.converterDataParaString(DataUtils.getDataAtual()); |
||
| 87 | new GerenciadorEmailImpl() |
||
| 88 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_DIRECAO) |
||
| 89 | .comAssunto("ESPAÇO CASE - MEGA: " + diaAtual) |
||
| 90 | .comConteudo(combinacoes.toString()) |
||
| 91 | .enviar(); |
||
| 92 | LancadorMensagem.lancarSucesso("COMBINAÇÕES GERADAS COM SUCESSO"); |
||
| 93 | } |
||
| 94 | }); |
||
| 95 | } |
||
| 96 | |||
| 97 | } |