Subversion Repositories Integrator Subversion

Rev

Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed

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