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.Date; |
||
| 5 | |||
| 6 | import javax.persistence.Column; |
||
| 7 | import javax.persistence.EmbeddedId; |
||
| 8 | import javax.persistence.Entity; |
||
| 9 | import javax.persistence.JoinColumn; |
||
| 10 | import javax.persistence.ManyToOne; |
||
| 11 | import javax.persistence.Table; |
||
| 12 | import javax.persistence.Temporal; |
||
| 13 | import javax.persistence.TemporalType; |
||
| 14 | import javax.persistence.Transient; |
||
| 15 | import javax.validation.Valid; |
||
| 16 | import javax.validation.constraints.NotNull; |
||
| 17 | |||
| 18 | import br.gov.al.saude.framework.core.generic.identidade.Identidade; |
||
| 19 | import br.gov.al.saude.framework.core.interfaces.Alterar; |
||
| 20 | import br.gov.al.saude.framework.core.interfaces.Cadastrar; |
||
| 21 | import br.gov.al.saude.framework.core.util.DataUtils; |
||
| 22 | |||
| 23 | @Entity |
||
| 24 | @Table(name = "rhd_cronograma_etapa", schema = "sc_rhd") |
||
| 25 | public class CronogramaEtapa implements Serializable, Identidade, Comparable<CronogramaEtapa> { |
||
| 26 | |||
| 27 | private static final long serialVersionUID = 1L; |
||
| 28 | |||
| 29 | private CronogramaEtapaId cronogramaEtapaId = new CronogramaEtapaId(); |
||
| 30 | private Etapa etapa = new Etapa(); |
||
| 31 | private Cronograma cronograma = new Cronograma(); |
||
| 32 | private Date dataInicialEtapa; |
||
| 33 | private Date dataFinalEtapa; |
||
| 34 | |||
| 35 | @Valid |
||
| 36 | @EmbeddedId |
||
| 37 | public CronogramaEtapaId getCronogramaEtapaId() { |
||
| 38 | return cronogramaEtapaId; |
||
| 39 | } |
||
| 40 | |||
| 41 | public void setCronogramaEtapaId(CronogramaEtapaId cronogramaEtapaId) { |
||
| 42 | this.cronogramaEtapaId = cronogramaEtapaId; |
||
| 43 | } |
||
| 44 | |||
| 45 | @ManyToOne |
||
| 46 | @JoinColumn(name = "cod_etapa", referencedColumnName = "cod_etapa", insertable = false, updatable = false, nullable = false) |
||
| 47 | public Etapa getEtapa() { |
||
| 48 | return etapa; |
||
| 49 | } |
||
| 50 | |||
| 51 | public void setEtapa(Etapa etapa) { |
||
| 52 | this.etapa = etapa; |
||
| 53 | } |
||
| 54 | |||
| 55 | @ManyToOne |
||
| 56 | @JoinColumn(name = "num_ano", referencedColumnName = "num_ano", insertable = false, updatable = false, nullable = false) |
||
| 57 | public Cronograma getCronograma() { |
||
| 58 | return cronograma; |
||
| 59 | } |
||
| 60 | |||
| 61 | public void setCronograma(Cronograma cronograma) { |
||
| 62 | this.cronograma = cronograma; |
||
| 63 | } |
||
| 64 | |||
| 65 | @Temporal(TemporalType.DATE) |
||
| 66 | @NotNull(message="Obrigatório informar a data inicial da etapa.", groups={Cadastrar.class, Alterar.class}) |
||
| 67 | @Column(name="dat_inicial_etapa", nullable=false) |
||
| 68 | public Date getDataInicialEtapa() { |
||
| 69 | return dataInicialEtapa; |
||
| 70 | } |
||
| 71 | |||
| 72 | public void setDataInicialEtapa(Date dataInicialEtapa) { |
||
| 73 | this.dataInicialEtapa = dataInicialEtapa; |
||
| 74 | } |
||
| 75 | |||
| 76 | @Temporal(TemporalType.DATE) |
||
| 77 | @NotNull(message="Obrigatório informar a data final da etapa.", groups={Cadastrar.class, Alterar.class}) |
||
| 78 | @Column(name="dat_final_etapa", nullable=false) |
||
| 79 | public Date getDataFinalEtapa() { |
||
| 80 | return dataFinalEtapa; |
||
| 81 | } |
||
| 82 | |||
| 83 | public void setDataFinalEtapa(Date dataFinalEtapa) { |
||
| 84 | this.dataFinalEtapa = dataFinalEtapa; |
||
| 85 | } |
||
| 86 | |||
| 87 | @Override |
||
| 88 | @Transient |
||
| 89 | public Object getId() { |
||
| 90 | return cronogramaEtapaId; |
||
| 91 | } |
||
| 92 | |||
| 93 | @Override |
||
| 94 | public void setId(Object id) { |
||
| 95 | this.cronogramaEtapaId = (CronogramaEtapaId) id; |
||
| 96 | } |
||
| 97 | |||
| 98 | @Override |
||
| 99 | public int hashCode() { |
||
| 100 | final int prime = 31; |
||
| 101 | int result = 1; |
||
| 102 | result = prime * result |
||
| 103 | + ((cronogramaEtapaId == null) ? 0 : cronogramaEtapaId.hashCode()); |
||
| 104 | result = prime * result |
||
| 105 | + ((dataFinalEtapa == null) ? 0 : dataFinalEtapa.hashCode()); |
||
| 106 | result = prime * result |
||
| 107 | + ((dataInicialEtapa == null) ? 0 : dataInicialEtapa.hashCode()); |
||
| 108 | return result; |
||
| 109 | } |
||
| 110 | |||
| 111 | @Override |
||
| 112 | public boolean equals(Object obj) { |
||
| 113 | if (this == obj) |
||
| 114 | return true; |
||
| 115 | if (obj == null) |
||
| 116 | return false; |
||
| 117 | if (getClass() != obj.getClass()) |
||
| 118 | return false; |
||
| 119 | CronogramaEtapa other = (CronogramaEtapa) obj; |
||
| 120 | if (cronogramaEtapaId == null) { |
||
| 121 | if (other.cronogramaEtapaId != null) |
||
| 122 | return false; |
||
| 123 | } else if (!cronogramaEtapaId.equals(other.cronogramaEtapaId)) |
||
| 124 | return false; |
||
| 125 | if (dataFinalEtapa == null) { |
||
| 126 | if (other.dataFinalEtapa != null) |
||
| 127 | return false; |
||
| 128 | } else if (!dataFinalEtapa.equals(other.dataFinalEtapa)) |
||
| 129 | return false; |
||
| 130 | if (dataInicialEtapa == null) { |
||
| 131 | if (other.dataInicialEtapa != null) |
||
| 132 | return false; |
||
| 133 | } else if (!dataInicialEtapa.equals(other.dataInicialEtapa)) |
||
| 134 | return false; |
||
| 135 | return true; |
||
| 136 | } |
||
| 137 | |||
| 138 | @Override |
||
| 139 | public int compareTo(CronogramaEtapa cronogramaEtapa) { |
||
| 140 | return this.dataInicialEtapa.compareTo(cronogramaEtapa.getDataInicialEtapa()); |
||
| 141 | } |
||
| 142 | |||
| 143 | @Transient |
||
| 144 | private Date recuperarDataAtual() { |
||
| 145 | return DataUtils.converterStringParaData(DataUtils.converterDataParaString(new Date())); |
||
| 146 | } |
||
| 147 | |||
| 148 | @Transient |
||
| 149 | public Boolean isDataEtapaConcluida() { |
||
| 150 | return isDataEstaVigente().equals(Boolean.FALSE) && this.getDataFinalEtapa().before(recuperarDataAtual()); |
||
| 151 | } |
||
| 152 | |||
| 153 | @Transient |
||
| 154 | public Boolean isDataEtapaFutura() { |
||
| 155 | return isDataEstaVigente().equals(Boolean.FALSE) && this.getDataInicialEtapa().after(recuperarDataAtual()); |
||
| 156 | } |
||
| 157 | |||
| 158 | @Transient |
||
| 159 | public Boolean isDataEstaVigente() { |
||
| 160 | Date dataAtual = recuperarDataAtual(); |
||
| 161 | return (this.getDataInicialEtapa().before(dataAtual) || this.getDataInicialEtapa().equals(dataAtual)) && |
||
| 162 | (this.getDataFinalEtapa().after(dataAtual) || this.getDataFinalEtapa().equals(dataAtual)); |
||
| 163 | } |
||
| 164 | |||
| 165 | } |