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