Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
package br.edu.cesmac.sic.core.domain.model;
2
 
3
import java.io.Serializable;
4
 
5
import javax.persistence.CascadeType;
6
import javax.persistence.Column;
7
import javax.persistence.Entity;
8
import javax.persistence.FetchType;
9
import javax.persistence.GeneratedValue;
10
import javax.persistence.GenerationType;
11
import javax.persistence.Id;
12
import javax.persistence.JoinColumn;
13
import javax.persistence.JoinColumns;
14
import javax.persistence.ManyToOne;
15
import javax.persistence.OneToOne;
16
import javax.persistence.Table;
17
import javax.persistence.Transient;
18
import javax.validation.Valid;
19
import javax.validation.constraints.NotNull;
20
 
21
import org.hibernate.envers.AuditTable;
22
import org.hibernate.envers.Audited;
23
import org.hibernate.envers.RelationTargetAuditMode;
24
 
25
import br.edu.cesmac.core.interfaces.Alterar;
26
import br.edu.cesmac.core.interfaces.Cadastrar;
27
import br.edu.cesmac.core.util.VerificadorUtil;
28
 
29
@Audited
30
@AuditTable(value="sic_aud_documento_aluno", schema="admsic001")
31
@Entity
32
@Table(name="sic_documento_aluno", schema="admsic001")
33
public class DocumentoAluno implements Serializable {
34
 
35
        private static final long serialVersionUID = 1L;
36
 
37
        private Long sequencial;
38
        private ProjetoPesquisaAluno projetoPesquisaAluno;
39
        private Arquivo arquivo;
40
        private String tipoDocumentoAluno;
41
 
42
        @Id
43
        @GeneratedValue(strategy=GenerationType.AUTO)
44
        @Column(name="seq_documento_aluno", nullable=false)
45
        public Long getSequencial() {
46
                return sequencial;
47
        }
48
 
49
        public void setSequencial(Long sequencial) {
50
                this.sequencial = sequencial;
51
        }
52
 
53
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
54
        @ManyToOne
55
        @JoinColumns(value={
56
                @JoinColumn(name="num_matricula", referencedColumnName="num_matricula", nullable=false),
57
                @JoinColumn(name="seq_projeto_pesquisa", referencedColumnName="seq_projeto_pesquisa", nullable=false),
58
        })
59
        public ProjetoPesquisaAluno getProjetoPesquisaAluno() {
60
                return projetoPesquisaAluno;
61
        }
62
 
63
        public void setProjetoPesquisaAluno(ProjetoPesquisaAluno projetoPesquisaAluno) {
64
                this.projetoPesquisaAluno = projetoPesquisaAluno;
65
        }
66
 
67
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
68
        @Valid
69
        @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
70
        @NotNull(message="Obrigatório informar o arquivo", groups={Cadastrar.class, Alterar.class})
71
        @JoinColumn(name="seq_arquivo", referencedColumnName="seq_arquivo", nullable=false, insertable=true, updatable=true)
72
        public Arquivo getArquivo() {
73
                return arquivo;
74
        }
75
 
76
        public void setArquivo(Arquivo arquivo) {
77
                this.arquivo = arquivo;
78
        }
79
 
80
        @Column(name="tip_documento_aluno", nullable=false)
81
        public String getTipoDocumentoAluno() {
82
                return tipoDocumentoAluno;
83
        }
84
 
85
        public void setTipoDocumentoAluno(String tipoDocumentoAluno) {
86
                this.tipoDocumentoAluno = tipoDocumentoAluno;
87
        }
88
 
89
        @Override
90
        public int hashCode() {
91
                final int prime = 31;
92
                int result = 1;
93
                result = prime * result + ((arquivo == null) ? 0 : arquivo.hashCode());
94
                result = prime * result + ((projetoPesquisaAluno == null) ? 0 : projetoPesquisaAluno.hashCode());
95
                result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode());
96
                result = prime * result + ((tipoDocumentoAluno == null) ? 0 : tipoDocumentoAluno.hashCode());
97
                return result;
98
        }
99
 
100
        @Override
101
        public boolean equals(Object obj) {
102
                if (this == obj)
103
                        return true;
104
                if (obj == null)
105
                        return false;
106
                if (getClass() != obj.getClass())
107
                        return false;
108
                DocumentoAluno other = (DocumentoAluno) obj;
109
                if (arquivo == null) {
110
                        if (other.arquivo != null)
111
                                return false;
112
                } else if (!arquivo.equals(other.arquivo))
113
                        return false;
114
                if (projetoPesquisaAluno == null) {
115
                        if (other.projetoPesquisaAluno != null)
116
                                return false;
117
                } else if (!projetoPesquisaAluno.equals(other.projetoPesquisaAluno))
118
                        return false;
119
                if (sequencial == null) {
120
                        if (other.sequencial != null)
121
                                return false;
122
                } else if (!sequencial.equals(other.sequencial))
123
                        return false;
124
                if (tipoDocumentoAluno == null) {
125
                        if (other.tipoDocumentoAluno != null)
126
                                return false;
127
                } else if (!tipoDocumentoAluno.equals(other.tipoDocumentoAluno))
128
                        return false;
129
                return true;
130
        }
131
 
132
        @Transient
133
        public String getExtensaoDoArquivo() {
134
                return VerificadorUtil.naoEstaNulo(getArquivo())? getArquivo().getExtensao() : null;
135
        }
136
 
137
}