Rev 302 | Rev 323 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 299 | espaco | 1 | package br.com.ec.controller; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | |||
| 5 | import javax.inject.Inject; |
||
| 6 | import javax.inject.Named; |
||
| 7 | |||
| 8 | import org.primefaces.event.FlowEvent; |
||
| 9 | import org.springframework.context.annotation.Scope; |
||
| 10 | |||
| 11 | import br.com.ec.core.generic.GenericService; |
||
| 12 | import br.com.ec.core.util.VerificadorUtil; |
||
| 13 | import br.com.ec.domain.dto.PessoaDTO; |
||
| 302 | espaco | 14 | import br.com.ec.domain.model.Endereco; |
| 303 | espaco | 15 | import br.com.ec.domain.model.Funcionario; |
| 299 | espaco | 16 | import br.com.ec.domain.model.Pessoa; |
| 302 | espaco | 17 | import br.com.ec.domain.model.tipos.TipoDependentes; |
| 299 | espaco | 18 | import br.com.ec.domain.model.tipos.TipoEscolaridade; |
| 19 | import br.com.ec.domain.model.tipos.TipoEstadoCivil; |
||
| 20 | import br.com.ec.domain.model.tipos.TipoPessoa; |
||
| 21 | import br.com.ec.domain.model.tipos.TipoRacaCor; |
||
| 22 | import br.com.ec.domain.service.PessoaService; |
||
| 303 | espaco | 23 | import br.com.ec.domain.shared.ConstantesSEC; |
| 24 | import br.com.ec.domain.shared.GerenciadorEmailImpl; |
||
| 299 | espaco | 25 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 26 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 27 | import br.com.ec.web.generic.AbstractBean; |
||
| 28 | import br.com.ec.web.message.LancadorMensagem; |
||
| 29 | import br.com.ec.web.util.TipoOperacao; |
||
| 30 | |||
| 31 | @Named |
||
| 32 | @Scope("view") |
||
| 33 | public class CadastroExternoBean extends AbstractBean<PessoaDTO> implements Serializable { |
||
| 34 | |||
| 35 | private static final long serialVersionUID = 1L; |
||
| 36 | |||
| 37 | private Pessoa pessoaSelecionada; |
||
| 303 | espaco | 38 | private Funcionario funcionarioSelecionado; |
| 302 | espaco | 39 | private Endereco enderecoSelecionado; |
| 40 | private String proximoPasso; |
||
| 299 | espaco | 41 | private PessoaService pessoaService; |
| 42 | |||
| 43 | @Inject |
||
| 44 | public CadastroExternoBean(PessoaService pessoaService) { |
||
| 45 | this.pessoaService = pessoaService; |
||
| 46 | } |
||
| 47 | |||
| 48 | @Override |
||
| 49 | public void preCarregamento() { |
||
| 50 | limparEntidade(); |
||
| 51 | } |
||
| 52 | |||
| 53 | @Override |
||
| 54 | public void limparEntidade() { |
||
| 55 | PessoaDTO pessoaDTO = new PessoaDTO(); |
||
| 56 | pessoaDTO.setTipoPessoa(TipoPessoa.FISICA_F.getValor()); |
||
| 302 | espaco | 57 | pessoaDTO.setNome("NOVATO"); |
| 299 | espaco | 58 | setEntidade(pessoaDTO); |
| 59 | } |
||
| 60 | |||
| 61 | @Override |
||
| 62 | public GenericService<PessoaDTO> getService() { |
||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | @Override |
||
| 67 | public PessoaDTO getEntidade() { |
||
| 68 | return entidade; |
||
| 69 | } |
||
| 70 | |||
| 71 | @Override |
||
| 72 | public void preConsultar() { |
||
| 73 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 74 | } |
||
| 75 | |||
| 76 | @Override |
||
| 77 | public PessoaDTO getId() { |
||
| 78 | return getEntidade(); |
||
| 79 | } |
||
| 80 | |||
| 81 | public TipoEstadoCivil[] getTiposEstadoCivil() { |
||
| 82 | return TipoEstadoCivil.values(); |
||
| 83 | } |
||
| 84 | |||
| 85 | public TipoRacaCor[] getTiposRacaCor() { |
||
| 86 | return TipoRacaCor.values(); |
||
| 87 | } |
||
| 88 | |||
| 89 | public TipoEscolaridade[] getTiposEscolaridade() { |
||
| 90 | return TipoEscolaridade.values(); |
||
| 91 | } |
||
| 92 | |||
| 302 | espaco | 93 | public TipoDependentes[] getTiposDependentes() { |
| 94 | return TipoDependentes.values(); |
||
| 95 | } |
||
| 96 | |||
| 299 | espaco | 97 | public Pessoa getPessoaSelecionada() { |
| 98 | return pessoaSelecionada; |
||
| 99 | } |
||
| 100 | public void setPessoaSelecionada(Pessoa pessoaSelecionada) { |
||
| 101 | this.pessoaSelecionada = pessoaSelecionada; |
||
| 102 | } |
||
| 103 | |||
| 303 | espaco | 104 | public Funcionario getFuncionarioSelecionado() { |
| 105 | return funcionarioSelecionado; |
||
| 106 | } |
||
| 107 | public void setFuncionarioSelecionado(Funcionario funcionarioSelecionado) { |
||
| 108 | this.funcionarioSelecionado = funcionarioSelecionado; |
||
| 109 | } |
||
| 110 | |||
| 302 | espaco | 111 | public Endereco getEnderecoSelecionado() { |
| 112 | return enderecoSelecionado; |
||
| 113 | } |
||
| 114 | public void setEnderecoSelecionado(Endereco enderecoSelecionado) { |
||
| 115 | this.enderecoSelecionado = enderecoSelecionado; |
||
| 116 | } |
||
| 117 | |||
| 118 | public String getProximoPasso() { |
||
| 119 | return proximoPasso; |
||
| 120 | } |
||
| 121 | public void setProximoPasso(String proximoPasso) { |
||
| 122 | this.proximoPasso = proximoPasso; |
||
| 123 | } |
||
| 124 | |||
| 299 | espaco | 125 | /*********************************************************/ |
| 126 | |||
| 127 | public void iniciarCadastroExterno() { |
||
| 128 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 129 | public void execute() { |
||
| 303 | espaco | 130 | setPessoaSelecionada(pessoaService.cadastroExterno(null, new Pessoa(getEntidade()), null, null)); |
| 131 | if (getPessoaSelecionada().getNome().equals("NOVATO")) { |
||
| 132 | getPessoaSelecionada().setNome(""); |
||
| 133 | } |
||
| 134 | setFuncionarioSelecionado(getPessoaSelecionada().getFuncionario()); |
||
| 302 | espaco | 135 | setEnderecoSelecionado(getPessoaSelecionada().primeiroEndereco()); |
| 136 | if (VerificadorUtil.estaNulo(getEnderecoSelecionado())) { |
||
| 137 | setEnderecoSelecionado(new Endereco(true)); |
||
| 138 | } |
||
| 299 | espaco | 139 | } |
| 140 | }); |
||
| 141 | } |
||
| 142 | |||
| 143 | public String seguir(FlowEvent evento) { |
||
| 302 | espaco | 144 | setProximoPasso(evento.getOldStep()); |
| 145 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 146 | public void execute() { |
||
| 303 | espaco | 147 | pessoaService.cadastroExterno(evento, getPessoaSelecionada(), getFuncionarioSelecionado(), getEnderecoSelecionado()); |
| 148 | setFuncionarioSelecionado(getPessoaSelecionada().getFuncionario()); |
||
| 302 | espaco | 149 | setProximoPasso(evento.getNewStep()); |
| 150 | } |
||
| 151 | }); |
||
| 152 | return getProximoPasso(); |
||
| 299 | espaco | 153 | } |
| 154 | |||
| 302 | espaco | 155 | public void finalizarCadastro() { |
| 156 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 157 | public void execute() { |
||
| 303 | espaco | 158 | new GerenciadorEmailImpl() |
| 159 | .comEmailsDestino(ConstantesSEC.DESTINATARIOS_EMAIL_RH) |
||
| 160 | .comAssunto("NOVO COLABORADOR CADASTRADO [ESPAÇO CASE]") |
||
| 161 | .comConteudoHtml("COLABORADOR: " + getPessoaSelecionada().getNome()) |
||
| 162 | .enviar(); |
||
| 302 | espaco | 163 | setPessoaSelecionada(null); |
| 164 | setEnderecoSelecionado(null); |
||
| 165 | limparEntidade(); |
||
| 166 | LancadorMensagem.lancarSucesso("CADASTRO REALIZADO COM SUCESSO"); |
||
| 167 | } |
||
| 168 | }); |
||
| 299 | espaco | 169 | } |
| 170 | |||
| 171 | } |