Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.rhd.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.Collection; |
||
| 5 | import java.util.Date; |
||
| 6 | import java.util.HashSet; |
||
| 7 | import java.util.Set; |
||
| 8 | |||
| 9 | import javax.persistence.CascadeType; |
||
| 10 | import javax.persistence.Column; |
||
| 11 | import javax.persistence.Entity; |
||
| 12 | import javax.persistence.FetchType; |
||
| 13 | import javax.persistence.Id; |
||
| 14 | import javax.persistence.OneToMany; |
||
| 15 | import javax.persistence.Table; |
||
| 16 | import javax.persistence.Temporal; |
||
| 17 | import javax.persistence.TemporalType; |
||
| 18 | import javax.persistence.Transient; |
||
| 19 | import javax.validation.Valid; |
||
| 20 | import javax.validation.constraints.NotNull; |
||
| 21 | |||
| 22 | import br.gov.al.saude.framework.core.generic.identidade.Identidade; |
||
| 23 | import br.gov.al.saude.framework.core.interfaces.Cadastrar; |
||
| 24 | |||
| 25 | @Entity |
||
| 26 | @Table(name = "rhd_cronograma", schema = "sc_rhd") |
||
| 27 | public class Cronograma implements Serializable, Identidade { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 31 | private Long numeroAno; |
||
| 32 | private Date dataCadastro; |
||
| 33 | private Set<CronogramaEtapa> cronogramaEtapas; |
||
| 34 | private Set<CronogramaHistorico> cronogramaHistoricos; |
||
| 35 | |||
| 36 | public Cronograma() { |
||
| 37 | inicializarListas(); |
||
| 38 | } |
||
| 39 | |||
| 40 | public Cronograma(Long numeroAno) { |
||
| 41 | this.numeroAno = numeroAno; |
||
| 42 | inicializarListas(); |
||
| 43 | } |
||
| 44 | |||
| 45 | @Transient |
||
| 46 | private void inicializarListas() { |
||
| 47 | this.cronogramaEtapas = new HashSet<CronogramaEtapa>(); |
||
| 48 | this.cronogramaHistoricos = new HashSet<CronogramaHistorico>(); |
||
| 49 | } |
||
| 50 | |||
| 51 | @Id |
||
| 52 | @NotNull(message="Obrigatório informar o ano.", groups={Cadastrar.class}) |
||
| 53 | @Column(name="num_ano", nullable=false) |
||
| 54 | public Long getNumeroAno() { |
||
| 55 | return numeroAno; |
||
| 56 | } |
||
| 57 | |||
| 58 | public void setNumeroAno(Long numeroAno) { |
||
| 59 | this.numeroAno = numeroAno; |
||
| 60 | } |
||
| 61 | |||
| 62 | @Temporal(TemporalType.TIMESTAMP) |
||
| 63 | @Column(name="dth_cadastro", nullable=false, insertable=false) |
||
| 64 | public Date getDataCadastro() { |
||
| 65 | return dataCadastro; |
||
| 66 | } |
||
| 67 | |||
| 68 | public void setDataCadastro(Date dataCadastro) { |
||
| 69 | this.dataCadastro = dataCadastro; |
||
| 70 | } |
||
| 71 | |||
| 72 | @Valid |
||
| 73 | @OneToMany(mappedBy="cronograma", cascade=CascadeType.ALL, fetch=FetchType.LAZY, orphanRemoval=true) |
||
| 74 | public Set<CronogramaEtapa> getCronogramaEtapas() { |
||
| 75 | return cronogramaEtapas; |
||
| 76 | } |
||
| 77 | |||
| 78 | public void setCronogramaEtapas(Set<CronogramaEtapa> cronogramaEtapas) { |
||
| 79 | this.cronogramaEtapas = cronogramaEtapas; |
||
| 80 | } |
||
| 81 | |||
| 82 | @OneToMany(mappedBy="cronograma", cascade=CascadeType.ALL, fetch=FetchType.LAZY) |
||
| 83 | public Set<CronogramaHistorico> getCronogramaHistoricos() { |
||
| 84 | return cronogramaHistoricos; |
||
| 85 | } |
||
| 86 | |||
| 87 | public void setCronogramaHistoricos(Set<CronogramaHistorico> cronogramaHistoricos) { |
||
| 88 | this.cronogramaHistoricos = cronogramaHistoricos; |
||
| 89 | } |
||
| 90 | |||
| 91 | public void adicionarCronogramaEtapa(CronogramaEtapa cronogramaEtapa) { |
||
| 92 | if (cronogramaEtapas == null) { |
||
| 93 | cronogramaEtapas = new HashSet<CronogramaEtapa>(); |
||
| 94 | } |
||
| 95 | cronogramaEtapas.add(cronogramaEtapa); |
||
| 96 | } |
||
| 97 | |||
| 98 | public void adicionarCronogramaEtapas(Collection<CronogramaEtapa> cronogramaEtapas) { |
||
| 99 | if (this.cronogramaEtapas == null) { |
||
| 100 | this.cronogramaEtapas = new HashSet<CronogramaEtapa>(); |
||
| 101 | } |
||
| 102 | this.cronogramaEtapas.addAll(cronogramaEtapas); |
||
| 103 | } |
||
| 104 | |||
| 105 | @Override |
||
| 106 | @Transient |
||
| 107 | public Object getId() { |
||
| 108 | return numeroAno; |
||
| 109 | } |
||
| 110 | |||
| 111 | @Override |
||
| 112 | public void setId(Object id) { |
||
| 113 | this.numeroAno = (Long) id; |
||
| 114 | } |
||
| 115 | |||
| 116 | @Override |
||
| 117 | public int hashCode() { |
||
| 118 | final int prime = 31; |
||
| 119 | int result = 1; |
||
| 120 | result = prime * result |
||
| 121 | + ((numeroAno == null) ? 0 : numeroAno.hashCode()); |
||
| 122 | return result; |
||
| 123 | } |
||
| 124 | |||
| 125 | @Override |
||
| 126 | public boolean equals(Object obj) { |
||
| 127 | if (this == obj) |
||
| 128 | return true; |
||
| 129 | if (obj == null) |
||
| 130 | return false; |
||
| 131 | if (getClass() != obj.getClass()) |
||
| 132 | return false; |
||
| 133 | Cronograma other = (Cronograma) obj; |
||
| 134 | if (numeroAno == null) { |
||
| 135 | if (other.numeroAno != null) |
||
| 136 | return false; |
||
| 137 | } else if (!numeroAno.equals(other.numeroAno)) |
||
| 138 | return false; |
||
| 139 | return true; |
||
| 140 | } |
||
| 141 | |||
| 142 | } |