Blame |
Last modification |
View Log
| Download
| RSS feed
package br.gov.al.saude.rhd.model;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import br.gov.al.saude.framework.core.generic.identidade.Identidade;
import br.gov.al.saude.framework.core.interfaces.Cadastrar;
@
Entity
@Table
(name =
"rhd_cronograma", schema =
"sc_rhd")
public class Cronograma
implements Serializable, Identidade
{
private static final long serialVersionUID = 1L
;
private Long numeroAno
;
private Date dataCadastro
;
private Set<CronogramaEtapa
> cronogramaEtapas
;
private Set<CronogramaHistorico
> cronogramaHistoricos
;
public Cronograma
() {
inicializarListas
();
}
public Cronograma
(Long numeroAno
) {
this.
numeroAno = numeroAno
;
inicializarListas
();
}
@Transient
private void inicializarListas
() {
this.
cronogramaEtapas =
new HashSet<CronogramaEtapa
>();
this.
cronogramaHistoricos =
new HashSet<CronogramaHistorico
>();
}
@Id
@NotNull
(message=
"Obrigatório informar o ano.", groups=
{Cadastrar.
class})
@Column
(name=
"num_ano", nullable=
false)
public Long getNumeroAno
() {
return numeroAno
;
}
public void setNumeroAno
(Long numeroAno
) {
this.
numeroAno = numeroAno
;
}
@Temporal
(TemporalType.
TIMESTAMP)
@Column
(name=
"dth_cadastro", nullable=
false, insertable=
false)
public Date getDataCadastro
() {
return dataCadastro
;
}
public void setDataCadastro
(Date dataCadastro
) {
this.
dataCadastro = dataCadastro
;
}
@Valid
@OneToMany
(mappedBy=
"cronograma", cascade=CascadeType.
ALL, fetch=FetchType.
LAZY, orphanRemoval=
true)
public Set<CronogramaEtapa
> getCronogramaEtapas
() {
return cronogramaEtapas
;
}
public void setCronogramaEtapas
(Set<CronogramaEtapa
> cronogramaEtapas
) {
this.
cronogramaEtapas = cronogramaEtapas
;
}
@OneToMany
(mappedBy=
"cronograma", cascade=CascadeType.
ALL, fetch=FetchType.
LAZY)
public Set<CronogramaHistorico
> getCronogramaHistoricos
() {
return cronogramaHistoricos
;
}
public void setCronogramaHistoricos
(Set<CronogramaHistorico
> cronogramaHistoricos
) {
this.
cronogramaHistoricos = cronogramaHistoricos
;
}
public void adicionarCronogramaEtapa
(CronogramaEtapa cronogramaEtapa
) {
if (cronogramaEtapas ==
null) {
cronogramaEtapas =
new HashSet<CronogramaEtapa
>();
}
cronogramaEtapas.
add(cronogramaEtapa
);
}
public void adicionarCronogramaEtapas
(Collection<CronogramaEtapa
> cronogramaEtapas
) {
if (this.
cronogramaEtapas ==
null) {
this.
cronogramaEtapas =
new HashSet<CronogramaEtapa
>();
}
this.
cronogramaEtapas.
addAll(cronogramaEtapas
);
}
@
Override
@Transient
public Object getId
() {
return numeroAno
;
}
@
Override
public void setId
(Object id
) {
this.
numeroAno =
(Long) id
;
}
@
Override
public int hashCode
() {
final int prime =
31;
int result =
1;
result = prime
* result
+
((numeroAno ==
null) ? 0 : numeroAno.
hashCode());
return result
;
}
@
Override
public boolean equals
(Object obj
) {
if (this == obj
)
return true;
if (obj ==
null)
return false;
if (getClass
() != obj.
getClass())
return false;
Cronograma other =
(Cronograma
) obj
;
if (numeroAno ==
null) {
if (other.
numeroAno !=
null)
return false;
} else if (!numeroAno.
equals(other.
numeroAno))
return false;
return true;
}
}