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 static br.gov.al.saude.srv.ContantesSrv.Mensagens.OBRIGATORIO_INFORMAR_DESCRICAO; |
||
| 4 | import static br.gov.al.saude.srv.ContantesSrv.Mensagens.OBRIGATORIO_INFORMAR_ORGAO; |
||
| 5 | import static br.gov.al.saude.srv.ContantesSrv.Mensagens.OBRIGATORIO_INFORMAR_SIGLA; |
||
| 6 | |||
| 7 | import java.io.Serializable; |
||
| 8 | |||
| 9 | import javax.persistence.Column; |
||
| 10 | import javax.persistence.Entity; |
||
| 11 | import javax.persistence.GeneratedValue; |
||
| 12 | import javax.persistence.GenerationType; |
||
| 13 | import javax.persistence.Id; |
||
| 14 | import javax.persistence.JoinColumn; |
||
| 15 | import javax.persistence.ManyToOne; |
||
| 16 | import javax.persistence.SequenceGenerator; |
||
| 17 | import javax.persistence.Table; |
||
| 18 | import javax.persistence.Transient; |
||
| 19 | import javax.validation.constraints.NotNull; |
||
| 20 | |||
| 21 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 22 | |||
| 23 | import br.gov.al.saude.framework.core.generic.identidade.Identidade; |
||
| 24 | import br.gov.al.saude.framework.core.interfaces.Alterar; |
||
| 25 | import br.gov.al.saude.framework.core.interfaces.Cadastrar; |
||
| 26 | import br.gov.al.saude.framework.core.util.VerificadorUtil; |
||
| 27 | |||
| 28 | @Entity |
||
| 29 | @Table(name="srv_unidade", schema="sc_srv") |
||
| 30 | public class Unidade implements Serializable, Identidade { |
||
| 31 | |||
| 32 | private static final long serialVersionUID = 1L; |
||
| 33 | |||
| 34 | private Integer codigo; |
||
| 35 | private String descricao; |
||
| 36 | private String sigla; |
||
| 37 | private Boolean ativo; |
||
| 38 | private Orgao orgao; |
||
| 39 | |||
| 40 | @Id |
||
| 41 | @GeneratedValue(generator = "UNIDADE_GENERATOR", strategy = GenerationType.SEQUENCE) |
||
| 42 | @SequenceGenerator(name = "UNIDADE_GENERATOR", sequenceName = "sq_unidade", initialValue = 1, allocationSize = 1) |
||
| 43 | @Column(name="cod_unidade", length=4, nullable=false) |
||
| 44 | public Integer getCodigo() { |
||
| 45 | return codigo; |
||
| 46 | } |
||
| 47 | |||
| 48 | public void setCodigo(Integer codigo) { |
||
| 49 | this.codigo = codigo; |
||
| 50 | } |
||
| 51 | |||
| 52 | @NotEmpty(message=OBRIGATORIO_INFORMAR_DESCRICAO, groups={Cadastrar.class, Alterar.class}) |
||
| 53 | @NotNull(message=OBRIGATORIO_INFORMAR_DESCRICAO, groups={Cadastrar.class, Alterar.class}) |
||
| 54 | @Column(name="dsc_unidade", length=200, nullable=false) |
||
| 55 | public String getDescricao() { |
||
| 56 | return descricao; |
||
| 57 | } |
||
| 58 | |||
| 59 | public void setDescricao(String descricao) { |
||
| 60 | this.descricao = VerificadorUtil.naoEstaNulo(descricao) ? descricao.toUpperCase() : descricao; |
||
| 61 | } |
||
| 62 | |||
| 63 | @NotEmpty(message=OBRIGATORIO_INFORMAR_SIGLA, groups={Cadastrar.class, Alterar.class}) |
||
| 64 | @NotNull(message=OBRIGATORIO_INFORMAR_SIGLA, groups={Cadastrar.class, Alterar.class}) |
||
| 65 | @Column(name="dsc_sigla_unidade", length=20) |
||
| 66 | public String getSigla() { |
||
| 67 | return sigla; |
||
| 68 | } |
||
| 69 | |||
| 70 | public void setSigla(String sigla) { |
||
| 71 | this.sigla = VerificadorUtil.naoEstaNulo(sigla) ? sigla.toUpperCase() : sigla; |
||
| 72 | } |
||
| 73 | |||
| 74 | @Column(name="ind_ativo", insertable = false) |
||
| 75 | public Boolean getAtivo() { |
||
| 76 | return ativo; |
||
| 77 | } |
||
| 78 | |||
| 79 | public void setAtivo(Boolean ativo) { |
||
| 80 | this.ativo = ativo; |
||
| 81 | } |
||
| 82 | |||
| 83 | @ManyToOne |
||
| 84 | @JoinColumn(name="seq_orgao", referencedColumnName="seq_orgao") |
||
| 85 | @NotNull(message=OBRIGATORIO_INFORMAR_ORGAO, groups={Cadastrar.class, Alterar.class}) |
||
| 86 | public Orgao getOrgao() { |
||
| 87 | return orgao; |
||
| 88 | } |
||
| 89 | |||
| 90 | public void setOrgao(Orgao orgao) { |
||
| 91 | this.orgao = orgao; |
||
| 92 | } |
||
| 93 | |||
| 94 | @Transient |
||
| 95 | public String getDescricaoAtivo() { |
||
| 96 | return getAtivo() ? "SIM" : "NÃO"; |
||
| 97 | } |
||
| 98 | |||
| 99 | @Transient |
||
| 100 | public String getDescricaoOrgao() { |
||
| 101 | return VerificadorUtil.naoEstaNulo(getOrgao()) ? getOrgao().getDescricao(): ""; |
||
| 102 | } |
||
| 103 | |||
| 104 | @Transient |
||
| 105 | @Override |
||
| 106 | public Object getId() { |
||
| 107 | return getCodigo(); |
||
| 108 | } |
||
| 109 | |||
| 110 | @Override |
||
| 111 | public void setId(Object codigo) { |
||
| 112 | setCodigo((Integer) codigo); |
||
| 113 | } |
||
| 114 | |||
| 115 | @Override |
||
| 116 | public int hashCode() { |
||
| 117 | final int prime = 31; |
||
| 118 | int result = 1; |
||
| 119 | result = prime * result + ((codigo == null) ? 0 : codigo.hashCode()); |
||
| 120 | return result; |
||
| 121 | } |
||
| 122 | |||
| 123 | @Override |
||
| 124 | public boolean equals(Object obj) { |
||
| 125 | if (this == obj) |
||
| 126 | return true; |
||
| 127 | if (obj == null) |
||
| 128 | return false; |
||
| 129 | if (getClass() != obj.getClass()) |
||
| 130 | return false; |
||
| 131 | Unidade other = (Unidade) obj; |
||
| 132 | if (codigo == null) { |
||
| 133 | if (other.codigo != null) |
||
| 134 | return false; |
||
| 135 | } else if (!codigo.equals(other.codigo)) |
||
| 136 | return false; |
||
| 137 | return true; |
||
| 138 | } |
||
| 139 | } |