Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.scs.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.HashSet; |
||
| 6 | import java.util.List; |
||
| 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.GeneratedValue; |
||
| 13 | import javax.persistence.GenerationType; |
||
| 14 | import javax.persistence.Id; |
||
| 15 | import javax.persistence.JoinColumn; |
||
| 16 | import javax.persistence.JoinTable; |
||
| 17 | import javax.persistence.ManyToMany; |
||
| 18 | import javax.persistence.ManyToOne; |
||
| 19 | import javax.persistence.OneToMany; |
||
| 20 | import javax.persistence.SequenceGenerator; |
||
| 21 | import javax.persistence.Table; |
||
| 22 | import javax.persistence.Transient; |
||
| 23 | import javax.validation.constraints.NotNull; |
||
| 24 | |||
| 25 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 26 | |||
| 27 | import br.gov.al.saude.framework.core.generic.identidade.Identidade; |
||
| 28 | import br.gov.al.saude.framework.core.interfaces.Alterar; |
||
| 29 | import br.gov.al.saude.framework.core.interfaces.Cadastrar; |
||
| 30 | import br.gov.al.saude.framework.core.util.DataUtils; |
||
| 31 | import br.gov.al.saude.framework.core.util.VerificadorUtil; |
||
| 32 | import br.gov.al.saude.scg.model.view.MunicipioView; |
||
| 33 | import br.gov.al.saude.scg.model.view.PessoaFisicaView; |
||
| 34 | import br.gov.al.saude.scg.model.view.UfView; |
||
| 35 | import br.gov.al.saude.scs.model.view.UnidadeView; |
||
| 36 | import br.gov.al.saude.scs.tipo.TipoSituacaoTurma; |
||
| 37 | |||
| 38 | @Entity |
||
| 39 | @Table(name = "scs_turma", schema = "sc_scs") |
||
| 40 | public class Turma implements Serializable, Identidade { |
||
| 41 | |||
| 42 | private static final long serialVersionUID = 1L; |
||
| 43 | |||
| 44 | private Long sequencial; |
||
| 45 | private Integer anoExercicio; |
||
| 46 | private Capacitacao capacitacao; |
||
| 47 | private UnidadeView unidadeSolicitante; |
||
| 48 | private Integer cargaHoraria; |
||
| 49 | private UfView uf; |
||
| 50 | private MunicipioView municipio; |
||
| 51 | private String observacao; |
||
| 52 | private String ementa; |
||
| 53 | private Boolean indicadorAtivo; |
||
| 54 | private Set<PessoaFisicaView> representantes = new HashSet<PessoaFisicaView>(); |
||
| 55 | private Set<TurmaParticipante> participantes = new HashSet<TurmaParticipante>(); |
||
| 56 | private Set<TurmaPeriodo> periodos = new HashSet<TurmaPeriodo>(); |
||
| 57 | private Set<TurmaProcesso> processos = new HashSet<TurmaProcesso>(); |
||
| 58 | private Set<Frequencia> frequencias = new HashSet<Frequencia>(); |
||
| 59 | |||
| 60 | @Id |
||
| 61 | @GeneratedValue(generator="turma_generator", strategy=GenerationType.SEQUENCE) |
||
| 62 | @SequenceGenerator(name="turma_generator", sequenceName="sq_turma", initialValue = 1, allocationSize = 1, schema="sc_scs") |
||
| 63 | @Column(name="seq_turma", nullable=false) |
||
| 64 | public Long getSequencial() { |
||
| 65 | return sequencial; |
||
| 66 | } |
||
| 67 | public void setSequencial(Long sequencial) { |
||
| 68 | this.sequencial = sequencial; |
||
| 69 | } |
||
| 70 | |||
| 71 | @Column(name="num_ano", nullable=false, length=4) |
||
| 72 | @NotNull(message= "Obrigatório informar o ano de exercício.", groups={Cadastrar.class, Alterar.class}) |
||
| 73 | public Integer getAnoExercicio() { |
||
| 74 | return anoExercicio; |
||
| 75 | } |
||
| 76 | public void setAnoExercicio(Integer anoExercicio) { |
||
| 77 | this.anoExercicio = anoExercicio; |
||
| 78 | } |
||
| 79 | |||
| 80 | @ManyToOne |
||
| 81 | @JoinColumn(name="seq_capacitacao", referencedColumnName="seq_capacitacao", nullable=false) |
||
| 82 | @NotNull(message="Obrigatório informar a capacitação.", groups={Cadastrar.class, Alterar.class}) |
||
| 83 | public Capacitacao getCapacitacao() { |
||
| 84 | return capacitacao; |
||
| 85 | } |
||
| 86 | public void setCapacitacao(Capacitacao capacitacao) { |
||
| 87 | this.capacitacao = capacitacao; |
||
| 88 | } |
||
| 89 | |||
| 90 | @ManyToOne |
||
| 91 | @JoinColumn(name="cod_unidade_solicitante", referencedColumnName="cod_unidade", nullable=false) |
||
| 92 | @NotNull(message="Obrigatório informar a unidade solicitante.", groups={Cadastrar.class, Alterar.class}) |
||
| 93 | public UnidadeView getUnidadeSolicitante() { |
||
| 94 | return unidadeSolicitante; |
||
| 95 | } |
||
| 96 | public void setUnidadeSolicitante(UnidadeView unidadeSolicitante) { |
||
| 97 | this.unidadeSolicitante = unidadeSolicitante; |
||
| 98 | } |
||
| 99 | |||
| 100 | @Column(name="num_carga_horaria") |
||
| 101 | public Integer getCargaHoraria() { |
||
| 102 | return cargaHoraria; |
||
| 103 | } |
||
| 104 | public void setCargaHoraria(Integer cargaHoraria) { |
||
| 105 | this.cargaHoraria = cargaHoraria; |
||
| 106 | } |
||
| 107 | |||
| 108 | @ManyToOne |
||
| 109 | @JoinColumn(name="cod_uf", referencedColumnName="cod_uf") |
||
| 110 | public UfView getUf() { |
||
| 111 | return uf; |
||
| 112 | } |
||
| 113 | public void setUf(UfView uf) { |
||
| 114 | this.uf = uf; |
||
| 115 | } |
||
| 116 | |||
| 117 | @ManyToOne |
||
| 118 | @JoinColumn(name="seq_municipio", referencedColumnName="seq_municipio") |
||
| 119 | public MunicipioView getMunicipio() { |
||
| 120 | return municipio; |
||
| 121 | } |
||
| 122 | public void setMunicipio(MunicipioView municipio) { |
||
| 123 | this.municipio = municipio; |
||
| 124 | } |
||
| 125 | |||
| 126 | @Column(name="dsc_observacao") |
||
| 127 | public String getObservacao() { |
||
| 128 | return observacao; |
||
| 129 | } |
||
| 130 | public void setObservacao(String observacao) { |
||
| 131 | this.observacao = observacao; |
||
| 132 | } |
||
| 133 | |||
| 134 | @Column(name="dsc_ementa") |
||
| 135 | public String getEmenta() { |
||
| 136 | return ementa; |
||
| 137 | } |
||
| 138 | public void setEmenta(String ementa) { |
||
| 139 | this.ementa = ementa; |
||
| 140 | } |
||
| 141 | |||
| 142 | @Column(name="ind_ativo", nullable=false) |
||
| 143 | public Boolean getIndicadorAtivo() { |
||
| 144 | return indicadorAtivo; |
||
| 145 | } |
||
| 146 | |||
| 147 | public void setIndicadorAtivo(Boolean indicadorAtivo) { |
||
| 148 | this.indicadorAtivo = indicadorAtivo; |
||
| 149 | } |
||
| 150 | |||
| 151 | // @Valid |
||
| 152 | @ManyToMany |
||
| 153 | @JoinTable(name="scs_turma_representante", |
||
| 154 | joinColumns=@JoinColumn(name="seq_turma", referencedColumnName="seq_turma"), |
||
| 155 | inverseJoinColumns=@JoinColumn(name="seq_pessoa", referencedColumnName="seq_pessoa") |
||
| 156 | ) |
||
| 157 | public Set<PessoaFisicaView> getRepresentantes() { |
||
| 158 | return representantes; |
||
| 159 | } |
||
| 160 | public void setRepresentantes(Set<PessoaFisicaView> representantes) { |
||
| 161 | this.representantes = representantes; |
||
| 162 | } |
||
| 163 | |||
| 164 | @Transient |
||
| 165 | public List<PessoaFisicaView> getRepresentantesAsList() { |
||
| 166 | if(VerificadorUtil.estaNulo(representantes)) { |
||
| 167 | return new ArrayList<PessoaFisicaView>(); |
||
| 168 | } |
||
| 169 | return new ArrayList<PessoaFisicaView>(representantes); |
||
| 170 | } |
||
| 171 | |||
| 172 | @OneToMany(mappedBy="turma", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 173 | public Set<TurmaParticipante> getParticipantes() { |
||
| 174 | return participantes; |
||
| 175 | } |
||
| 176 | public void setParticipantes(Set<TurmaParticipante> participantes) { |
||
| 177 | this.participantes = participantes; |
||
| 178 | } |
||
| 179 | |||
| 180 | @Transient |
||
| 181 | public List<TurmaParticipante> getParticipantesAsList() { |
||
| 182 | if(VerificadorUtil.estaNulo(participantes)) { |
||
| 183 | return new ArrayList<TurmaParticipante>(); |
||
| 184 | } |
||
| 185 | return new ArrayList<TurmaParticipante>(participantes); |
||
| 186 | } |
||
| 187 | |||
| 188 | @OneToMany(mappedBy="turma", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 189 | public Set<TurmaProcesso> getProcessos() { |
||
| 190 | return processos; |
||
| 191 | } |
||
| 192 | public void setProcessos(Set<TurmaProcesso> processos) { |
||
| 193 | this.processos = processos; |
||
| 194 | } |
||
| 195 | |||
| 196 | @Transient |
||
| 197 | public List<TurmaProcesso> getProcessosAsList() { |
||
| 198 | if(VerificadorUtil.estaNulo(processos)) { |
||
| 199 | return new ArrayList<TurmaProcesso>(); |
||
| 200 | } |
||
| 201 | return new ArrayList<TurmaProcesso>(processos); |
||
| 202 | } |
||
| 203 | |||
| 204 | @OneToMany(mappedBy="turma", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 205 | @NotEmpty(message="Obrigatório informar um período.", groups={Cadastrar.class, Alterar.class}) |
||
| 206 | public Set<TurmaPeriodo> getPeriodos() { |
||
| 207 | return periodos; |
||
| 208 | } |
||
| 209 | public void setPeriodos(Set<TurmaPeriodo> periodos) { |
||
| 210 | this.periodos = periodos; |
||
| 211 | } |
||
| 212 | |||
| 213 | @Transient |
||
| 214 | public List<TurmaPeriodo> getPeriodosAsList() { |
||
| 215 | if(periodos == null) { |
||
| 216 | return new ArrayList<TurmaPeriodo>(); |
||
| 217 | } |
||
| 218 | return new ArrayList<TurmaPeriodo>(periodos); |
||
| 219 | } |
||
| 220 | |||
| 221 | @OneToMany(mappedBy="turma") |
||
| 222 | public Set<Frequencia> getFrequencias() { |
||
| 223 | return frequencias; |
||
| 224 | } |
||
| 225 | public void setFrequencias(Set<Frequencia> frequencias) { |
||
| 226 | this.frequencias = frequencias; |
||
| 227 | } |
||
| 228 | |||
| 229 | @Transient |
||
| 230 | public String getSituacaoTurma(){ |
||
| 231 | return TipoSituacaoTurma.recuperarTipoSituacao(this, DataUtils.getDataAtual()); |
||
| 232 | } |
||
| 233 | |||
| 234 | public void adicionarRepresentante(PessoaFisicaView representante) { |
||
| 235 | if(representantes == null) { |
||
| 236 | representantes = new HashSet<PessoaFisicaView>(); |
||
| 237 | } |
||
| 238 | representantes.add(representante); |
||
| 239 | } |
||
| 240 | |||
| 241 | public void removerRepresentante(PessoaFisicaView representante) { |
||
| 242 | representantes.remove(representante); |
||
| 243 | } |
||
| 244 | |||
| 245 | public void adicionarProcesso(TurmaProcesso turmaProcesso) { |
||
| 246 | if(processos == null) { |
||
| 247 | processos = new HashSet<TurmaProcesso>(); |
||
| 248 | } |
||
| 249 | processos.add(turmaProcesso); |
||
| 250 | } |
||
| 251 | |||
| 252 | public void removerProcesso(TurmaProcesso turmaProcesso) { |
||
| 253 | processos.remove(turmaProcesso); |
||
| 254 | } |
||
| 255 | |||
| 256 | public void adicionarParticipante(TurmaParticipante turmaParticipante) { |
||
| 257 | if(participantes == null) { |
||
| 258 | participantes = new HashSet<TurmaParticipante>(); |
||
| 259 | } |
||
| 260 | participantes.add(turmaParticipante); |
||
| 261 | } |
||
| 262 | |||
| 263 | public void removerParticipante(TurmaParticipante turmaParticipante) { |
||
| 264 | participantes.remove(turmaParticipante); |
||
| 265 | } |
||
| 266 | |||
| 267 | public void adicionarTurmaPeriodo(TurmaPeriodo turmaPeriodo) { |
||
| 268 | if(periodos == null) { |
||
| 269 | periodos = new HashSet<TurmaPeriodo>(); |
||
| 270 | } |
||
| 271 | periodos.add(turmaPeriodo); |
||
| 272 | } |
||
| 273 | |||
| 274 | public void removerTurmaPeriodo(TurmaPeriodo turmaPeriodo) { |
||
| 275 | periodos.remove(turmaPeriodo); |
||
| 276 | } |
||
| 277 | |||
| 278 | @Override |
||
| 279 | @Transient |
||
| 280 | public Object getId() { |
||
| 281 | return sequencial; |
||
| 282 | } |
||
| 283 | |||
| 284 | @Override |
||
| 285 | public void setId(Object id) { |
||
| 286 | this.sequencial = (Long) id; |
||
| 287 | } |
||
| 288 | |||
| 289 | @Override |
||
| 290 | public int hashCode() { |
||
| 291 | final int prime = 31; |
||
| 292 | int result = 1; |
||
| 293 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 294 | return result; |
||
| 295 | } |
||
| 296 | |||
| 297 | @Override |
||
| 298 | public boolean equals(Object obj) { |
||
| 299 | if (this == obj) |
||
| 300 | return true; |
||
| 301 | if (obj == null) |
||
| 302 | return false; |
||
| 303 | if (getClass() != obj.getClass()) |
||
| 304 | return false; |
||
| 305 | Turma other = (Turma) obj; |
||
| 306 | if (sequencial == null) { |
||
| 307 | if (other.sequencial != null) |
||
| 308 | return false; |
||
| 309 | } else if (!sequencial.equals(other.sequencial)) |
||
| 310 | return false; |
||
| 311 | return true; |
||
| 312 | } |
||
| 313 | |||
| 314 | |||
| 315 | } |