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.OneToOne;
14
import javax.persistence.Table;
15
import javax.persistence.Transient;
16
import javax.validation.Valid;
17
import javax.validation.constraints.NotNull;
18
 
19
import org.hibernate.envers.AuditTable;
20
import org.hibernate.envers.Audited;
21
import org.hibernate.envers.RelationTargetAuditMode;
22
 
23
import br.edu.cesmac.core.interfaces.Alterar;
24
import br.edu.cesmac.core.interfaces.Cadastrar;
25
import br.edu.cesmac.core.util.VerificadorUtil;
26
 
27
@Audited
28
@AuditTable(value="sic_aud_arquivo_projeto", schema="admsic001")
29
@Entity
30
@Table(name="sic_arquivo_projeto", schema="admsic001")
31
public class ArquivoProjeto implements Serializable {
32
 
33
        private static final long serialVersionUID = 1L;
34
 
35
        private Long sequencial;
36
        private ProjetoPesquisa projetoPesquisa = new ProjetoPesquisa();
37
        private Arquivo arquivo;
38
        private String tipoDocumentoProjeto;
39
 
40
        @Id
41
        @GeneratedValue(strategy=GenerationType.AUTO)
42
        @Column(name="seq_arquivo_projeto", nullable=false)
43
        public Long getSequencial() {
44
                return sequencial;
45
        }
46
 
47
        public void setSequencial(Long sequencial) {
48
                this.sequencial = sequencial;
49
        }
50
 
51
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
52
        @OneToOne
53
        @JoinColumn(name="seq_projeto_pesquisa", referencedColumnName="seq_projeto_pesquisa", nullable=false)
54
        public ProjetoPesquisa getProjetoPesquisa() {
55
                return projetoPesquisa;
56
        }
57
 
58
        public void setProjetoPesquisa(ProjetoPesquisa projetoPesquisa) {
59
                this.projetoPesquisa = projetoPesquisa;
60
        }
61
 
62
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
63
        @Valid
64
        @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
65
        @NotNull(message="Obrigatório informar o arquivo", groups={Cadastrar.class, Alterar.class})
66
        @JoinColumn(name="seq_arquivo", referencedColumnName="seq_arquivo", nullable=false, insertable=true, updatable=true)
67
        public Arquivo getArquivo() {
68
                return arquivo;
69
        }
70
 
71
        public void setArquivo(Arquivo arquivo) {
72
                this.arquivo = arquivo;
73
        }
74
 
75
        @Column(name="tip_documento_projeto", nullable=false)
76
        public String getTipoDocumentoProjeto() {
77
                return tipoDocumentoProjeto;
78
        }
79
 
80
        public void setTipoDocumentoProjeto(String tipoDocumentoProjeto) {
81
                this.tipoDocumentoProjeto = tipoDocumentoProjeto;
82
        }
83
 
84
        @Override
85
        public int hashCode() {
86
                final int prime = 31;
87
                int result = 1;
88
                result = prime * result + ((arquivo == null) ? 0 : arquivo.hashCode());
89
                result = prime * result + ((projetoPesquisa == null) ? 0 : projetoPesquisa.hashCode());
90
                result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode());
91
                result = prime * result + ((tipoDocumentoProjeto == null) ? 0 : tipoDocumentoProjeto.hashCode());
92
                return result;
93
        }
94
 
95
        @Override
96
        public boolean equals(Object obj) {
97
                if (this == obj)
98
                        return true;
99
                if (obj == null)
100
                        return false;
101
                if (getClass() != obj.getClass())
102
                        return false;
103
                ArquivoProjeto other = (ArquivoProjeto) obj;
104
                if (arquivo == null) {
105
                        if (other.arquivo != null)
106
                                return false;
107
                } else if (!arquivo.equals(other.arquivo))
108
                        return false;
109
                if (projetoPesquisa == null) {
110
                        if (other.projetoPesquisa != null)
111
                                return false;
112
                } else if (!projetoPesquisa.equals(other.projetoPesquisa))
113
                        return false;
114
                if (sequencial == null) {
115
                        if (other.sequencial != null)
116
                                return false;
117
                } else if (!sequencial.equals(other.sequencial))
118
                        return false;
119
                if (tipoDocumentoProjeto == null) {
120
                        if (other.tipoDocumentoProjeto != null)
121
                                return false;
122
                } else if (!tipoDocumentoProjeto.equals(other.tipoDocumentoProjeto))
123
                        return false;
124
                return true;
125
        }
126
 
127
        @Transient
128
        public String getExtensaoDoArquivo() {
129
                return VerificadorUtil.naoEstaNulo(getArquivo())? getArquivo().getExtensao() : null;
130
        }
131
 
132
}