Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.srv.model; |
| 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.ManyToOne; |
||
| 14 | import javax.persistence.OneToMany; |
||
| 15 | import javax.persistence.OneToOne; |
||
| 16 | import javax.persistence.Table; |
||
| 17 | import javax.persistence.Temporal; |
||
| 18 | import javax.persistence.TemporalType; |
||
| 19 | import javax.persistence.Transient; |
||
| 20 | import javax.validation.Valid; |
||
| 21 | import javax.validation.constraints.NotNull; |
||
| 22 | |||
| 23 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 24 | |||
| 25 | import br.gov.al.saude.framework.core.generic.identidade.Identidade; |
||
| 26 | import br.gov.al.saude.framework.core.interfaces.Alterar; |
||
| 27 | import br.gov.al.saude.framework.core.interfaces.Cadastrar; |
||
| 28 | import br.gov.al.saude.framework.core.util.DocumentoUtils; |
||
| 29 | import br.gov.al.saude.framework.core.util.VerificadorUtil; |
||
| 30 | import br.gov.al.saude.framework.model.PessoaDocumentoView; |
||
| 31 | import br.gov.al.saude.framework.model.PessoaFisicaView; |
||
| 32 | import br.gov.al.saude.framework.model.UsuarioView; |
||
| 33 | import br.gov.al.saude.srv.model.enums.TipoSituacaoCadastral; |
||
| 34 | |||
| 35 | @Entity |
||
| 36 | @Table(name = "srv_servidor", schema = "sc_srv") |
||
| 37 | public class Servidor implements Serializable, Identidade { |
||
| 38 | |||
| 39 | private static final long serialVersionUID = 1L; |
||
| 40 | private PessoaFisicaView pessoa = new PessoaFisicaView(); |
||
| 41 | private String observacao; |
||
| 42 | private String tipoSituacaoCadastral; |
||
| 43 | private GrauInstrucao grauInstrucao; |
||
| 44 | private Deficiencia deficiencia; |
||
| 45 | private UsuarioView usuario = new UsuarioView(); |
||
| 46 | private UsuarioView usuarioAlteraSituacaoCadastral; |
||
| 47 | private Nacionalidade nacionalidade; |
||
| 48 | private Date dataHoraCadastro; |
||
| 49 | private Date dataHoraAlteracao; |
||
| 50 | private byte[] foto; |
||
| 51 | private ServidorLocalizacaoArquivo servidorLocalizacaoArquivo; |
||
| 52 | |||
| 53 | private Set<ServidorDadoFuncional> listaServidorDadoFuncional; |
||
| 54 | private Set<ServidorQualificacao> listaServidorQualificacao; |
||
| 55 | private Set<ServidorDependente> listaServidorDependente; |
||
| 56 | private Set<ServidorContaBancaria> listaServidorContaBancaria; |
||
| 57 | |||
| 58 | public Servidor(){ |
||
| 59 | tipoSituacaoCadastral = TipoSituacaoCadastral.PENDENTE.getValue(); |
||
| 60 | listaServidorDadoFuncional = new HashSet<ServidorDadoFuncional>(); |
||
| 61 | listaServidorQualificacao = new HashSet<ServidorQualificacao>(); |
||
| 62 | listaServidorDependente = new HashSet<ServidorDependente>(); |
||
| 63 | listaServidorContaBancaria = new HashSet<ServidorContaBancaria>(); |
||
| 64 | } |
||
| 65 | |||
| 66 | @Id |
||
| 67 | @OneToOne |
||
| 68 | @JoinColumn(name="seq_pessoa_servidor", referencedColumnName="seq_pessoa") |
||
| 69 | public PessoaFisicaView getPessoa() { |
||
| 70 | return pessoa; |
||
| 71 | } |
||
| 72 | public void setPessoa(PessoaFisicaView pessoa) { |
||
| 73 | this.pessoa = pessoa; |
||
| 74 | } |
||
| 75 | |||
| 76 | |||
| 77 | @Column(name="dsc_observacao") |
||
| 78 | public String getObservacao() { |
||
| 79 | return observacao; |
||
| 80 | } |
||
| 81 | public void setObservacao(String observacao) { |
||
| 82 | this.observacao = observacao; |
||
| 83 | } |
||
| 84 | |||
| 85 | @Column(name="tip_situacao_cadastral", length=1, nullable=false) |
||
| 86 | public String getTipoSituacaoCadastral() { |
||
| 87 | return tipoSituacaoCadastral; |
||
| 88 | } |
||
| 89 | public void setTipoSituacaoCadastral(String tipoSituacaoCadastral) { |
||
| 90 | this.tipoSituacaoCadastral = tipoSituacaoCadastral; |
||
| 91 | } |
||
| 92 | public void setTipoSituacaoCadastral(TipoSituacaoCadastral tipoSituacaoCadastral) { |
||
| 93 | this.tipoSituacaoCadastral = tipoSituacaoCadastral.getValue(); |
||
| 94 | } |
||
| 95 | @Transient |
||
| 96 | public TipoSituacaoCadastral getSituacaoCadastral() { |
||
| 97 | if(VerificadorUtil.naoEstaNulo(tipoSituacaoCadastral)) { |
||
| 98 | return TipoSituacaoCadastral.parse(tipoSituacaoCadastral); |
||
| 99 | } |
||
| 100 | return null; |
||
| 101 | } |
||
| 102 | |||
| 103 | @Transient |
||
| 104 | public String getDescricaoTipoSituacaoCadastral() { |
||
| 105 | return VerificadorUtil.estaNulo(this.getTipoSituacaoCadastral())?null:TipoSituacaoCadastral.parse(this.getTipoSituacaoCadastral()).getDescricao(); |
||
| 106 | } |
||
| 107 | |||
| 108 | @ManyToOne |
||
| 109 | @JoinColumn(name="cod_grau_instrucao", referencedColumnName="cod_grau_instrucao") |
||
| 110 | @NotNull(message="Obrigatório informar o grau de instrução.", groups={Cadastrar.class, Alterar.class}) |
||
| 111 | public GrauInstrucao getGrauInstrucao() { |
||
| 112 | return grauInstrucao; |
||
| 113 | } |
||
| 114 | public void setGrauInstrucao(GrauInstrucao grauInstrucao) { |
||
| 115 | this.grauInstrucao = grauInstrucao; |
||
| 116 | } |
||
| 117 | |||
| 118 | @ManyToOne |
||
| 119 | @JoinColumn(name="cod_deficiencia", referencedColumnName="cod_deficiencia") |
||
| 120 | public Deficiencia getDeficiencia() { |
||
| 121 | return deficiencia; |
||
| 122 | } |
||
| 123 | public void setDeficiencia(Deficiencia deficiencia) { |
||
| 124 | this.deficiencia = deficiencia; |
||
| 125 | } |
||
| 126 | |||
| 127 | @ManyToOne |
||
| 128 | @JoinColumn(name="seq_pessoa_usuario", referencedColumnName="seq_pessoa") |
||
| 129 | public UsuarioView getUsuario() { |
||
| 130 | return usuario; |
||
| 131 | } |
||
| 132 | public void setUsuario(UsuarioView usuario) { |
||
| 133 | this.usuario = usuario; |
||
| 134 | } |
||
| 135 | |||
| 136 | @ManyToOne |
||
| 137 | @JoinColumn(name="seq_pessoa_alterasitocadast", referencedColumnName="seq_pessoa") |
||
| 138 | public UsuarioView getUsuarioAlteracaoSituacaoCadastral() { |
||
| 139 | return usuarioAlteraSituacaoCadastral; |
||
| 140 | } |
||
| 141 | public void setUsuarioAlteracaoSituacaoCadastral(UsuarioView usuarioAlteraSituacaoCadastral) { |
||
| 142 | this.usuarioAlteraSituacaoCadastral = usuarioAlteraSituacaoCadastral; |
||
| 143 | } |
||
| 144 | |||
| 145 | @ManyToOne |
||
| 146 | @JoinColumn(name="cod_nacionalidade", referencedColumnName="cod_nacionalidade") |
||
| 147 | @NotNull(message="Obrigatório informar a nacionalidade.", groups={Cadastrar.class, Alterar.class}) |
||
| 148 | public Nacionalidade getNacionalidade() { |
||
| 149 | return nacionalidade; |
||
| 150 | } |
||
| 151 | public void setNacionalidade(Nacionalidade nacionalidade) { |
||
| 152 | this.nacionalidade = nacionalidade; |
||
| 153 | } |
||
| 154 | |||
| 155 | @Temporal(TemporalType.TIMESTAMP) |
||
| 156 | @Column(name="dth_cadastro") |
||
| 157 | public Date getDataHoraCadastro() { |
||
| 158 | return dataHoraCadastro; |
||
| 159 | } |
||
| 160 | public void setDataHoraCadastro(Date dataHoraCadastro) { |
||
| 161 | this.dataHoraCadastro = dataHoraCadastro; |
||
| 162 | } |
||
| 163 | |||
| 164 | @Temporal(TemporalType.TIMESTAMP) |
||
| 165 | @Column(name="dth_alteracao") |
||
| 166 | public Date getDataHoraAlteracao() { |
||
| 167 | return dataHoraAlteracao; |
||
| 168 | } |
||
| 169 | public void setDataHoraAlteracao(Date dataHoraAlteracao) { |
||
| 170 | this.dataHoraAlteracao = dataHoraAlteracao; |
||
| 171 | } |
||
| 172 | |||
| 173 | @Column(name="obj_foto") |
||
| 174 | public byte[] getFoto() { |
||
| 175 | return foto; |
||
| 176 | } |
||
| 177 | |||
| 178 | public void setFoto(byte[] foto) { |
||
| 179 | this.foto = foto; |
||
| 180 | } |
||
| 181 | |||
| 182 | @OneToOne(mappedBy="servidor", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 183 | public ServidorLocalizacaoArquivo getServidorLocalizacaoArquivo() { |
||
| 184 | return servidorLocalizacaoArquivo; |
||
| 185 | } |
||
| 186 | public void setServidorLocalizacaoArquivo(ServidorLocalizacaoArquivo servidorLocalizacaoArquivo) { |
||
| 187 | this.servidorLocalizacaoArquivo = servidorLocalizacaoArquivo; |
||
| 188 | } |
||
| 189 | |||
| 190 | @Valid |
||
| 191 | @NotEmpty(message="Obrigatório informar dado funcional.", groups={Cadastrar.class, Alterar.class}) |
||
| 192 | @OneToMany(mappedBy="servidor", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 193 | public Set<ServidorDadoFuncional> getListaServidorDadoFuncional() { |
||
| 194 | return listaServidorDadoFuncional; |
||
| 195 | } |
||
| 196 | public void setListaServidorDadoFuncional(Set<ServidorDadoFuncional> listaServidorDadoFuncional) { |
||
| 197 | this.listaServidorDadoFuncional = listaServidorDadoFuncional; |
||
| 198 | } |
||
| 199 | |||
| 200 | @Valid |
||
| 201 | @OneToMany(mappedBy="servidor", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 202 | public Set<ServidorQualificacao> getListaServidorQualificacao() { |
||
| 203 | return listaServidorQualificacao; |
||
| 204 | } |
||
| 205 | public void setListaServidorQualificacao(Set<ServidorQualificacao> listaServidorQualificacao) { |
||
| 206 | this.listaServidorQualificacao = listaServidorQualificacao; |
||
| 207 | } |
||
| 208 | |||
| 209 | @Valid |
||
| 210 | @OneToMany(mappedBy="servidor", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 211 | public Set<ServidorDependente> getListaServidorDependente() { |
||
| 212 | return listaServidorDependente; |
||
| 213 | } |
||
| 214 | public void setListaServidorDependente(Set<ServidorDependente> listaServidorDependente) { |
||
| 215 | this.listaServidorDependente = listaServidorDependente; |
||
| 216 | } |
||
| 217 | |||
| 218 | @Valid |
||
| 219 | @OneToMany(mappedBy="servidor", cascade=CascadeType.ALL, orphanRemoval = true) |
||
| 220 | public Set<ServidorContaBancaria> getListaServidorContaBancaria() { |
||
| 221 | return listaServidorContaBancaria; |
||
| 222 | } |
||
| 223 | public void setListaServidorContaBancaria(Set<ServidorContaBancaria> listaServidorContaBancaria) { |
||
| 224 | this.listaServidorContaBancaria = listaServidorContaBancaria; |
||
| 225 | } |
||
| 226 | |||
| 227 | @Transient |
||
| 228 | public boolean isSituacaoCadastralHomologado(){ |
||
| 229 | return getTipoSituacaoCadastral().equals(TipoSituacaoCadastral.HOMOLOGADO.getValue()); |
||
| 230 | } |
||
| 231 | |||
| 232 | @Transient |
||
| 233 | public boolean isSituacaoCadastralPendente(){ |
||
| 234 | return getTipoSituacaoCadastral().equals(TipoSituacaoCadastral.PENDENTE.getValue()); |
||
| 235 | } |
||
| 236 | |||
| 237 | @Transient |
||
| 238 | public boolean isSituacaoCadastralValidado(){ |
||
| 239 | return getTipoSituacaoCadastral().equals(TipoSituacaoCadastral.VALIDADO.getValue()); |
||
| 240 | } |
||
| 241 | |||
| 242 | @Transient |
||
| 243 | @Override |
||
| 244 | public Object getId() { |
||
| 245 | return this.pessoa.getSequencialPessoa(); |
||
| 246 | } |
||
| 247 | @Override |
||
| 248 | public void setId(Object id) { |
||
| 249 | this.pessoa.setSequencialPessoa((Long) id); |
||
| 250 | } |
||
| 251 | |||
| 252 | @Transient |
||
| 253 | public Set<PessoaDocumentoView> getListaDocumentosDePessoa() { |
||
| 254 | return (VerificadorUtil.naoEstaNulo(getPessoa())? getPessoa().getDocumentos(): null); |
||
| 255 | } |
||
| 256 | |||
| 257 | @Transient |
||
| 258 | public Long getSequencialDaPessoa() { |
||
| 259 | return (VerificadorUtil.naoEstaNulo(getPessoa())? getPessoa().getSequencialPessoa() : null); |
||
| 260 | } |
||
| 261 | |||
| 262 | @Transient |
||
| 263 | public String getNomeDaPessoa() { |
||
| 264 | return (VerificadorUtil.naoEstaNulo(getPessoa())? getPessoa().getNomePessoa(): null); |
||
| 265 | } |
||
| 266 | |||
| 267 | @Transient |
||
| 268 | public String getNumeroCpfFormatado(){ |
||
| 269 | try { |
||
| 270 | return DocumentoUtils.adicionarMascaraCpf(getPessoa().getNumeroDocumento()); |
||
| 271 | } catch (Exception e) { |
||
| 272 | return null; |
||
| 273 | } |
||
| 274 | } |
||
| 275 | |||
| 276 | @Override |
||
| 277 | public int hashCode() { |
||
| 278 | final int prime = 31; |
||
| 279 | int result = 1; |
||
| 280 | result = prime * result + ((pessoa == null) ? 0 : pessoa.hashCode()); |
||
| 281 | return result; |
||
| 282 | } |
||
| 283 | |||
| 284 | @Override |
||
| 285 | public boolean equals(Object obj) { |
||
| 286 | if (this == obj) |
||
| 287 | return true; |
||
| 288 | if (obj == null) |
||
| 289 | return false; |
||
| 290 | if (!(obj instanceof Servidor)) |
||
| 291 | return false; |
||
| 292 | Servidor other = (Servidor) obj; |
||
| 293 | if (pessoa == null) { |
||
| 294 | if (other.pessoa != null) |
||
| 295 | return false; |
||
| 296 | } else if (!pessoa.equals(other.pessoa)) |
||
| 297 | return false; |
||
| 298 | return true; |
||
| 299 | } |
||
| 300 | } |