Rev 325 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 259 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.File; |
||
| 4 | import java.io.Serializable; |
||
| 5 | import java.util.Date; |
||
| 6 | import java.util.List; |
||
| 7 | |||
| 8 | import javax.faces.context.FacesContext; |
||
| 9 | import javax.persistence.CascadeType; |
||
| 10 | import javax.persistence.Column; |
||
| 11 | import javax.persistence.Entity; |
||
| 12 | import javax.persistence.GeneratedValue; |
||
| 13 | import javax.persistence.GenerationType; |
||
| 14 | import javax.persistence.Id; |
||
| 15 | import javax.persistence.JoinColumn; |
||
| 16 | import javax.persistence.OneToMany; |
||
| 17 | import javax.persistence.OneToOne; |
||
| 18 | import javax.persistence.SequenceGenerator; |
||
| 19 | import javax.persistence.Table; |
||
| 20 | import javax.persistence.Transient; |
||
| 21 | import javax.servlet.ServletContext; |
||
| 22 | import javax.validation.constraints.NotNull; |
||
| 23 | import javax.validation.constraints.Size; |
||
| 24 | |||
| 25 | import org.hibernate.annotations.ForeignKey; |
||
| 26 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 27 | |||
| 28 | import br.com.ec.core.interfaces.Alterar; |
||
| 29 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 30 | import br.com.ec.core.util.StringUtil; |
||
| 31 | import br.com.ec.core.util.VerificadorUtil; |
||
| 409 | espaco | 32 | import br.com.ec.domain.dto.FuncionarioDTO; |
| 325 | espaco | 33 | import br.com.ec.domain.dto.UsuarioDTO; |
| 259 | espaco | 34 | |
| 35 | @Entity |
||
| 36 | @Table(name="sec_usuario", schema="sc_sec") |
||
| 37 | public class Usuario implements Serializable { |
||
| 38 | |||
| 39 | private static final long serialVersionUID = 1L; |
||
| 40 | |||
| 41 | private Long sequencial; |
||
| 42 | private Pessoa pessoa; |
||
| 43 | private String nome; |
||
| 44 | private String login; |
||
| 45 | private String senha; |
||
| 46 | private Date ultimoAcesso; |
||
| 47 | private boolean ativo; |
||
| 48 | |||
| 49 | private List<UsuarioPerfil> perfis; |
||
| 50 | private List<UsuarioLoja> lojas; |
||
| 51 | |||
| 52 | // private List<Parametro> parametros; |
||
| 53 | |||
| 325 | espaco | 54 | public Usuario() {} |
| 55 | |||
| 56 | public Usuario(Long sequencial) { |
||
| 57 | this.sequencial = sequencial; |
||
| 58 | } |
||
| 59 | |||
| 409 | espaco | 60 | public Usuario(UsuarioDTO usuarioDTO) { |
| 61 | this.sequencial = usuarioDTO.getSequencial(); |
||
| 62 | } |
||
| 63 | |||
| 259 | espaco | 64 | @Id |
| 65 | @SequenceGenerator(name = "sq_usuario") |
||
| 66 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 67 | @Column(name="seq_usuario", nullable=false) |
||
| 68 | public Long getSequencial() { |
||
| 69 | return sequencial; |
||
| 70 | } |
||
| 71 | public void setSequencial(Long sequencial) { |
||
| 72 | this.sequencial = sequencial; |
||
| 73 | } |
||
| 74 | |||
| 75 | @OneToOne |
||
| 76 | @ForeignKey(name="fk_usuario_pessoa") |
||
| 77 | @NotNull(message="Obrigatório informar a pessoa", groups={Cadastrar.class, Alterar.class}) |
||
| 78 | @JoinColumn(name="seq_pessoa", referencedColumnName="seq_pessoa", nullable=false) |
||
| 79 | public Pessoa getPessoa() { |
||
| 80 | return pessoa; |
||
| 81 | } |
||
| 82 | public void setPessoa(Pessoa pessoa) { |
||
| 83 | this.pessoa = pessoa; |
||
| 84 | } |
||
| 85 | |||
| 86 | @Column(name="dsc_nome") |
||
| 87 | @Size(max = 120, message = "Limite de caracteres ultrapassado: Nome") |
||
| 88 | public String getNome() { |
||
| 89 | return nome; |
||
| 90 | } |
||
| 91 | public void setNome(String nome) { |
||
| 92 | this.nome = StringUtil.setarUpperCaseComTrim(nome); |
||
| 93 | } |
||
| 94 | |||
| 95 | @Column(name="dsc_login", nullable=false) |
||
| 96 | @Size(max = 32, message = "Limite de caracteres ultrapassado: Login") |
||
| 97 | @NotEmpty(message="Obrigatório informar o login", groups={Cadastrar.class, Alterar.class}) |
||
| 98 | public String getLogin() { |
||
| 99 | return login; |
||
| 100 | } |
||
| 101 | public void setLogin(String login) { |
||
| 102 | this.login = login; |
||
| 103 | } |
||
| 104 | |||
| 105 | @Column(name="dsc_senha", nullable=false) |
||
| 106 | @Size(max = 32, message = "Limite de caracteres ultrapassado: Senha") |
||
| 107 | @NotEmpty(message="Obrigatório informar a senha", groups={Cadastrar.class, Alterar.class}) |
||
| 108 | public String getSenha() { |
||
| 109 | return senha; |
||
| 110 | } |
||
| 111 | public void setSenha(String senha) { |
||
| 112 | this.senha = senha; |
||
| 113 | } |
||
| 114 | |||
| 115 | @Column(name="dth_ultimo_acesso") |
||
| 116 | public Date getUltimoAcesso() { |
||
| 117 | return ultimoAcesso; |
||
| 118 | } |
||
| 119 | public void setUltimoAcesso(Date ultimoAcesso) { |
||
| 120 | this.ultimoAcesso = ultimoAcesso; |
||
| 121 | } |
||
| 122 | |||
| 123 | @Column(name="ind_ativo", nullable=false) |
||
| 124 | public Boolean getAtivo() { |
||
| 125 | return ativo; |
||
| 126 | } |
||
| 127 | public void setAtivo(Boolean ativo) { |
||
| 128 | this.ativo = ativo; |
||
| 129 | } |
||
| 130 | |||
| 131 | @OneToMany(mappedBy="usuario", cascade=CascadeType.ALL, orphanRemoval=true) |
||
| 132 | public List<UsuarioPerfil> getPerfis() { |
||
| 133 | return perfis; |
||
| 134 | } |
||
| 135 | public void setPerfis(List<UsuarioPerfil> perfis) { |
||
| 136 | this.perfis = perfis; |
||
| 137 | } |
||
| 138 | |||
| 139 | @OneToMany(mappedBy="usuario", cascade=CascadeType.ALL, orphanRemoval=true) |
||
| 140 | public List<UsuarioLoja> getLojas() { |
||
| 141 | return lojas; |
||
| 142 | } |
||
| 143 | public void setLojas(List<UsuarioLoja> lojas) { |
||
| 144 | this.lojas = lojas; |
||
| 145 | } |
||
| 146 | /* |
||
| 147 | @Transient |
||
| 148 | public List<Parametro> getParametros() { |
||
| 149 | return parametros; |
||
| 150 | } |
||
| 151 | public void setParametros(List<Parametro> parametros) { |
||
| 152 | this.parametros = parametros; |
||
| 153 | } |
||
| 154 | */ |
||
| 155 | @Transient |
||
| 156 | public String getNomeDaPessoa() { |
||
| 157 | return VerificadorUtil.naoEstaNulo(pessoa)? pessoa.getNome() : null; |
||
| 158 | } |
||
| 159 | |||
| 160 | @Transient |
||
| 161 | public Long getSequencialDaPessoa() { |
||
| 162 | return VerificadorUtil.naoEstaNulo(pessoa)? pessoa.getSequencial() : null; |
||
| 163 | } |
||
| 164 | |||
| 165 | @Transient |
||
| 166 | public Boolean verificarSeTemFoto() { |
||
| 167 | File foto = new File(getCaminhoPastaFotos() + "user" + getSequencial() + ".jpg"); |
||
| 168 | return foto.exists(); |
||
| 169 | } |
||
| 170 | |||
| 171 | @Transient |
||
| 172 | public String getCaminhoPastaFotos() { |
||
| 173 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
||
| 174 | return servletContext.getRealPath("") + File.separator + "imagens" + File.separator + "usuarios" + File.separator; |
||
| 175 | } |
||
| 325 | espaco | 176 | |
| 177 | public void atualizarDados(UsuarioDTO usuarioDTO) { |
||
| 178 | this.nome = usuarioDTO.getNome(); |
||
| 179 | this.login = usuarioDTO.getLogin(); |
||
| 180 | // this.senha = usuarioDTO.getSenha(); |
||
| 181 | } |
||
| 259 | espaco | 182 | |
| 183 | } |