Subversion Repositories Integrator Subversion

Rev

Blame | Last modification | View Log | Download | RSS feed

package br.gov.al.saude.srv.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import br.gov.al.saude.framework.core.generic.identidade.Identidade;
import br.gov.al.saude.framework.core.interfaces.Alterar;
import br.gov.al.saude.framework.core.interfaces.Cadastrar;
import br.gov.al.saude.framework.core.util.VerificadorUtil;
import br.gov.al.saude.scg.model.Sexo;
import br.gov.al.saude.srv.model.enums.TipoParentesco;

@Entity
@Table(name = "srv_servidor_dependente", schema = "sc_srv")
public class ServidorDependente implements Serializable, Identidade, Comparable<ServidorDependente> {
        private static final long serialVersionUID = 1L;

        private Long sequencial;
        private String numeroCpf;
        private String nome;
        private String tipoSexo;
        private Date dataNascimento;
        private String tipoParentesco;
        private Servidor servidor;
       
       
        @Id
        @Column(name="seq_servidor_dependente", nullable=false)
        @GeneratedValue(generator = "SERVIDOR_DEPENDENTE_GENERATOR", strategy = GenerationType.SEQUENCE)
        @SequenceGenerator(name = "SERVIDOR_DEPENDENTE_GENERATOR", sequenceName = "sc_srv.sq_servidepend", initialValue = 1, allocationSize = 1)
        public Long getSequencial() {
                return sequencial;
        }
        public void setSequencial(Long sequencial) {
                this.sequencial = sequencial;
        }

       
        @Column(name="num_cpf_depentende", length=11)
        public String getNumeroCpf() {
                return numeroCpf;
        }
        public void setNumeroCpf(String numeroCpf) {
                this.numeroCpf = numeroCpf;
        }

       
        @Column(name="nom_dependente", length=100, nullable=false)
        @NotNull(message ="Obrigatório informar o nome.", groups={Cadastrar.class, Alterar.class})
        public String getNome() {
                return nome;
        }
        public void setNome(String nome) {
                this.nome = nome;
        }

       
        @Column(name="tip_sexo", length=1, nullable=false)
        @NotNull(message ="Obrigatório informar o sexo.", groups={Cadastrar.class, Alterar.class})
        public String getTipoSexo() {
                return tipoSexo;
        }
        public void setTipoSexo(String tipoSexo) {
                this.tipoSexo = tipoSexo;
        }
        public void setTipoSexo(Sexo sexo) {
                this.tipoSexo = sexo.getValue();
        }
       
        @Transient
        public String getDescricaoTipoSexo() {
                return VerificadorUtil.estaNulo(this.getTipoSexo())?null:Sexo.parse(this.getTipoSexo()).getDescricao();
        }
       
       
        @Temporal(TemporalType.DATE)
        @Column(name="dat_nascimento", nullable=false)
        public Date getDataNascimento() {
                return dataNascimento;
        }
        public void setDataNascimento(Date dataNascimento) {
                this.dataNascimento = dataNascimento;
        }

       
        @Column(name="tip_parentesco", length=1, nullable=false)
        @NotNull(message ="Obrigatório informar o parentesco.", groups={Cadastrar.class, Alterar.class})
        public String getTipoParentesco() {
                return tipoParentesco;
        }
        public void setTipoParentesco(String tipoParentesco) {
                this.tipoParentesco = tipoParentesco;
        }      
        public void setTipoParentesco(TipoParentesco tipoParentesco) {
                this.tipoParentesco = tipoParentesco.getValue();
        }
       
        @Transient
        public String getDescricaoTipoParentesco() {
                return TipoParentesco.parse(getTipoParentesco()).getDescricao();
        }
       
       
        @ManyToOne
        @JoinColumn(name="seq_pessoa_servidor", referencedColumnName="seq_pessoa_servidor", nullable=false)
        public Servidor getServidor() {
                return servidor;
        }
        public void setServidor(Servidor servidor) {
                this.servidor = servidor;
        }

       
        @Transient
        @Override
        public Object getId() {
                return this.sequencial;
        }
        @Override
        public void setId(Object id) {
                this.sequencial = (Long) id;
        }

       
        @Override
        public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result
                                + ((dataNascimento == null) ? 0 : dataNascimento.hashCode());
                result = prime * result + ((nome == null) ? 0 : nome.hashCode());
                result = prime * result
                                + ((sequencial == null) ? 0 : sequencial.hashCode());
                result = prime * result
                                + ((tipoParentesco == null) ? 0 : tipoParentesco.hashCode());
                result = prime * result
                                + ((tipoSexo == null) ? 0 : tipoSexo.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;
                ServidorDependente other = (ServidorDependente) obj;
                if (dataNascimento == null) {
                        if (other.dataNascimento != null)
                                return false;
                } else if (!dataNascimento.equals(other.dataNascimento))
                        return false;
                if (nome == null) {
                        if (other.nome != null)
                                return false;
                } else if (!nome.equals(other.nome))
                        return false;
                if (sequencial == null) {
                        if (other.sequencial != null)
                                return false;
                } else if (!sequencial.equals(other.sequencial))
                        return false;
                if (tipoParentesco == null) {
                        if (other.tipoParentesco != null)
                                return false;
                } else if (!tipoParentesco.equals(other.tipoParentesco))
                        return false;
                if (tipoSexo == null) {
                        if (other.tipoSexo != null)
                                return false;
                } else if (!tipoSexo.equals(other.tipoSexo))
                        return false;
                return true;
        }
       
        @Override
        public int compareTo(ServidorDependente sd) {
                return getNome().compareTo(sd.getNome());
        }
}