Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.rhd.model.view; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.Date; |
||
| 5 | import java.util.HashSet; |
||
| 6 | import java.util.Set; |
||
| 7 | |||
| 8 | import javax.persistence.CascadeType; |
||
| 9 | import javax.persistence.Column; |
||
| 10 | import javax.persistence.Entity; |
||
| 11 | import javax.persistence.Id; |
||
| 12 | import javax.persistence.JoinColumn; |
||
| 13 | import javax.persistence.OneToMany; |
||
| 14 | import javax.persistence.OneToOne; |
||
| 15 | import javax.persistence.Table; |
||
| 16 | import javax.persistence.Temporal; |
||
| 17 | import javax.persistence.TemporalType; |
||
| 18 | import javax.persistence.Transient; |
||
| 19 | |||
| 20 | import org.hibernate.annotations.ForeignKey; |
||
| 21 | |||
| 22 | import br.gov.al.saude.framework.core.generic.identidade.Identidade; |
||
| 23 | import br.gov.al.saude.scg.model.view.PessoaFisicaView; |
||
| 24 | |||
| 25 | @Entity |
||
| 26 | @Table(name = "vw_servidor", schema = "sc_srv") |
||
| 27 | public class ServidorView implements Serializable, Identidade, Comparable<ServidorView> { |
||
| 28 | |||
| 29 | private static final long serialVersionUID = 1L; |
||
| 30 | |||
| 31 | private PessoaFisicaView pessoa; |
||
| 32 | |||
| 33 | private String nome; |
||
| 34 | private String cpf; |
||
| 35 | private String sexo; |
||
| 36 | private Date dataNascimento; |
||
| 37 | private String email; |
||
| 38 | private String nacionalidade; |
||
| 39 | private String tipoGrauInstrucao; |
||
| 40 | |||
| 41 | private Set<ServidorDadoFuncionalView> listaDadosFuncionaisView; |
||
| 42 | private Set<QualificacaoServidorView> listaQualificacoesView; |
||
| 43 | |||
| 44 | public ServidorView() { |
||
| 45 | listaDadosFuncionaisView = new HashSet<ServidorDadoFuncionalView>(); |
||
| 46 | listaQualificacoesView = new HashSet<QualificacaoServidorView>(); |
||
| 47 | } |
||
| 48 | |||
| 49 | public ServidorView(String nomeServidor, Long sequencialPessoa) { |
||
| 50 | this.nome = nomeServidor; |
||
| 51 | pessoa = new PessoaFisicaView(); |
||
| 52 | pessoa.setSequencialPessoa(sequencialPessoa); |
||
| 53 | pessoa.setNomePessoa(nomeServidor); |
||
| 54 | } |
||
| 55 | |||
| 56 | @Id |
||
| 57 | @OneToOne |
||
| 58 | @ForeignKey(name="fk_servidor_pessoa") |
||
| 59 | @JoinColumn(name="seq_pessoa_servidor", referencedColumnName="seq_pessoa") |
||
| 60 | public PessoaFisicaView getPessoa() { |
||
| 61 | return pessoa; |
||
| 62 | } |
||
| 63 | |||
| 64 | public void setPessoa(PessoaFisicaView pessoa) { |
||
| 65 | this.pessoa = pessoa; |
||
| 66 | } |
||
| 67 | |||
| 68 | @Column(name="nom_pessoa") |
||
| 69 | public String getNome() { |
||
| 70 | return nome; |
||
| 71 | } |
||
| 72 | |||
| 73 | public void setNome(String nome) { |
||
| 74 | this.nome = nome; |
||
| 75 | } |
||
| 76 | |||
| 77 | @Column(name="num_cpf") |
||
| 78 | public String getCpf() { |
||
| 79 | return cpf; |
||
| 80 | } |
||
| 81 | |||
| 82 | public void setCpf(String cpf) { |
||
| 83 | this.cpf = cpf; |
||
| 84 | } |
||
| 85 | |||
| 86 | @Column(name="tip_sexo") |
||
| 87 | public String getSexo() { |
||
| 88 | return sexo; |
||
| 89 | } |
||
| 90 | |||
| 91 | public void setSexo(String sexo) { |
||
| 92 | this.sexo = sexo; |
||
| 93 | } |
||
| 94 | |||
| 95 | @Temporal(TemporalType.DATE) |
||
| 96 | @Column(name="dat_nascimento") |
||
| 97 | public Date getDataNascimento() { |
||
| 98 | return dataNascimento; |
||
| 99 | } |
||
| 100 | |||
| 101 | public void setDataNascimento(Date dataNascimento) { |
||
| 102 | this.dataNascimento = dataNascimento; |
||
| 103 | } |
||
| 104 | |||
| 105 | @Column(name="dsc_email") |
||
| 106 | public String getEmail() { |
||
| 107 | return email; |
||
| 108 | } |
||
| 109 | |||
| 110 | public void setEmail(String email) { |
||
| 111 | this.email = email; |
||
| 112 | } |
||
| 113 | |||
| 114 | @Column(name="dsc_nacionalidade") |
||
| 115 | public String getNacionalidade() { |
||
| 116 | return nacionalidade; |
||
| 117 | } |
||
| 118 | |||
| 119 | public void setNacionalidade(String nacionalidade) { |
||
| 120 | this.nacionalidade = nacionalidade; |
||
| 121 | } |
||
| 122 | |||
| 123 | @Column(name="tip_grau_instrucao") |
||
| 124 | public String getTipoGrauInstrucao() { |
||
| 125 | return tipoGrauInstrucao; |
||
| 126 | } |
||
| 127 | |||
| 128 | public void setTipoGrauInstrucao(String tipoGrauInstrucao) { |
||
| 129 | this.tipoGrauInstrucao = tipoGrauInstrucao; |
||
| 130 | } |
||
| 131 | |||
| 132 | @OneToMany(mappedBy="servidorView", cascade=CascadeType.ALL) |
||
| 133 | public Set<ServidorDadoFuncionalView> getListaDadosFuncionaisView() { |
||
| 134 | return listaDadosFuncionaisView; |
||
| 135 | } |
||
| 136 | |||
| 137 | public void setListaDadosFuncionaisView(Set<ServidorDadoFuncionalView> listaDadosFuncionaisView) { |
||
| 138 | this.listaDadosFuncionaisView = listaDadosFuncionaisView; |
||
| 139 | } |
||
| 140 | |||
| 141 | @OneToMany(mappedBy="servidorView", cascade=CascadeType.ALL) |
||
| 142 | public Set<QualificacaoServidorView> getListaQualificacoesView() { |
||
| 143 | return listaQualificacoesView; |
||
| 144 | } |
||
| 145 | |||
| 146 | public void setListaQualificacoesView(Set<QualificacaoServidorView> listaQualificacoesView) { |
||
| 147 | this.listaQualificacoesView = listaQualificacoesView; |
||
| 148 | } |
||
| 149 | |||
| 150 | @Override |
||
| 151 | @Transient |
||
| 152 | public Object getId() { |
||
| 153 | return pessoa.getId(); |
||
| 154 | } |
||
| 155 | |||
| 156 | @Override |
||
| 157 | public void setId(Object id) { |
||
| 158 | this.pessoa.setId((Long) id); |
||
| 159 | } |
||
| 160 | |||
| 161 | @Transient |
||
| 162 | public String getSexoPorExtenso() { |
||
| 163 | if("M".equals(sexo)) |
||
| 164 | return "Masculino"; |
||
| 165 | if("F".equals(sexo)) |
||
| 166 | return "Feminino"; |
||
| 167 | return null; |
||
| 168 | } |
||
| 169 | |||
| 170 | @Transient |
||
| 171 | public Long getSequencialDaPessoa() { |
||
| 172 | return pessoa != null ? pessoa.getSequencialPessoa() : null; |
||
| 173 | } |
||
| 174 | |||
| 175 | @Transient |
||
| 176 | public String getMatriculas() { |
||
| 177 | StringBuilder matriculas = new StringBuilder(""); |
||
| 178 | for (ServidorDadoFuncionalView dadoFuncional : listaDadosFuncionaisView) { |
||
| 179 | matriculas.append(dadoFuncional.getNumeroMatricula()); |
||
| 180 | matriculas.append(", "); |
||
| 181 | } |
||
| 182 | matriculas.append("."); |
||
| 183 | return matriculas.toString().replace(", .", ""); |
||
| 184 | } |
||
| 185 | |||
| 186 | @Transient |
||
| 187 | public ServidorDadoFuncionalView getPrimeiroDadoFuncional() { |
||
| 188 | for (ServidorDadoFuncionalView dadoFuncional : listaDadosFuncionaisView) { |
||
| 189 | return dadoFuncional; |
||
| 190 | } |
||
| 191 | return null; |
||
| 192 | } |
||
| 193 | |||
| 194 | @Transient |
||
| 195 | public UnidadeView getUnidadeDoPrimeiroDadoFuncional() { |
||
| 196 | return getPrimeiroDadoFuncional() != null ? getPrimeiroDadoFuncional().getUnidadeExercicio() : null; |
||
| 197 | } |
||
| 198 | |||
| 199 | @Transient |
||
| 200 | public Long getSequencialDaUnidadeDoPrimeiroDadoFuncional() { |
||
| 201 | return getUnidadeDoPrimeiroDadoFuncional() != null ? getUnidadeDoPrimeiroDadoFuncional().getSequencial() : null; |
||
| 202 | } |
||
| 203 | |||
| 204 | @Override |
||
| 205 | public int hashCode() { |
||
| 206 | final int prime = 31; |
||
| 207 | int result = 1; |
||
| 208 | result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); |
||
| 209 | return result; |
||
| 210 | } |
||
| 211 | |||
| 212 | @Override |
||
| 213 | public boolean equals(Object obj) { |
||
| 214 | if (this == obj) |
||
| 215 | return true; |
||
| 216 | if (obj == null) |
||
| 217 | return false; |
||
| 218 | if (getClass() != obj.getClass()) |
||
| 219 | return false; |
||
| 220 | ServidorView other = (ServidorView) obj; |
||
| 221 | if (getId() == null) { |
||
| 222 | if (other.getId() != null) |
||
| 223 | return false; |
||
| 224 | } else if (!getId().equals(other.getId())) |
||
| 225 | return false; |
||
| 226 | return true; |
||
| 227 | } |
||
| 228 | |||
| 229 | @Override |
||
| 230 | public int compareTo(ServidorView o) { |
||
| 231 | return getNome().compareToIgnoreCase(o.getNome()); |
||
| 232 | } |
||
| 233 | |||
| 234 | } |