Subversion Repositories Integrator Subversion

Rev

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