Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.regex.Matcher; |
||
| 5 | import java.util.regex.Pattern; |
||
| 6 | |||
| 7 | import javax.persistence.Column; |
||
| 8 | import javax.persistence.Entity; |
||
| 9 | import javax.persistence.GeneratedValue; |
||
| 10 | import javax.persistence.GenerationType; |
||
| 11 | import javax.persistence.Id; |
||
| 12 | import javax.persistence.JoinColumn; |
||
| 13 | import javax.persistence.OneToOne; |
||
| 14 | import javax.persistence.Table; |
||
| 15 | import javax.persistence.Transient; |
||
| 16 | import javax.validation.constraints.NotNull; |
||
| 17 | |||
| 18 | import org.hibernate.annotations.ForeignKey; |
||
| 19 | |||
| 20 | import br.edu.cesmac.core.interfaces.Alterar; |
||
| 21 | import br.edu.cesmac.core.interfaces.Cadastrar; |
||
| 22 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 23 | |||
| 24 | @Entity |
||
| 25 | @Table(name="sec_fornecedor", schema="sc_sec") |
||
| 26 | public class Fornecedor implements Serializable { |
||
| 27 | |||
| 28 | private static final long serialVersionUID = 1L; |
||
| 29 | |||
| 30 | private Long sequencial; |
||
| 31 | private Pessoa pessoa; |
||
| 32 | private Boolean emiteNotaFiscal; |
||
| 33 | private Boolean ativo; |
||
| 34 | |||
| 35 | public Fornecedor() { |
||
| 36 | setEmiteNotaFiscal(false); |
||
| 37 | setAtivo(true); |
||
| 38 | } |
||
| 39 | |||
| 40 | @Id |
||
| 41 | @GeneratedValue(strategy=GenerationType.IDENTITY) |
||
| 42 | @Column(name="seq_fornecedor", nullable=false) |
||
| 43 | public Long getSequencial() { |
||
| 44 | return sequencial; |
||
| 45 | } |
||
| 46 | public void setSequencial(Long sequencial) { |
||
| 47 | this.sequencial = sequencial; |
||
| 48 | } |
||
| 49 | |||
| 50 | @OneToOne |
||
| 51 | @ForeignKey(name="fk_fornecedorproduto_pessoa") |
||
| 52 | @JoinColumn(name="seq_pessoa", referencedColumnName="seq_pessoa") |
||
| 53 | @NotNull(message="Obrigatório informar a pessoa", groups={Cadastrar.class, Alterar.class}) |
||
| 54 | public Pessoa getPessoa() { |
||
| 55 | return pessoa; |
||
| 56 | } |
||
| 57 | public void setPessoa(Pessoa pessoa) { |
||
| 58 | this.pessoa = pessoa; |
||
| 59 | } |
||
| 60 | |||
| 61 | @Column(name="ind_emite_notafiscal", nullable=false) |
||
| 62 | @NotNull(message="Obrigatório informar a indicação de emissão de nota fiscal", groups={Cadastrar.class, Alterar.class}) |
||
| 63 | public Boolean getEmiteNotaFiscal() { |
||
| 64 | return emiteNotaFiscal; |
||
| 65 | } |
||
| 66 | public void setEmiteNotaFiscal(Boolean emiteNotaFiscal) { |
||
| 67 | this.emiteNotaFiscal = emiteNotaFiscal; |
||
| 68 | } |
||
| 69 | |||
| 70 | @Column(name="ind_ativo", nullable=false) |
||
| 71 | @NotNull(message="Obrigatório informar a indicação de ativo", groups={Cadastrar.class, Alterar.class}) |
||
| 72 | public Boolean getAtivo() { |
||
| 73 | return ativo; |
||
| 74 | } |
||
| 75 | public void setAtivo(Boolean ativo) { |
||
| 76 | this.ativo = ativo; |
||
| 77 | } |
||
| 78 | |||
| 79 | @Transient |
||
| 80 | public Long getSequencialPessoa() { |
||
| 81 | return VerificadorUtil.naoEstaNulo(getPessoa())? getPessoa().getSequencial() : null; |
||
| 82 | } |
||
| 83 | |||
| 84 | @Transient |
||
| 85 | public String getNomeDaPessoa() { |
||
| 86 | return VerificadorUtil.naoEstaNulo(getPessoa())? getPessoa().getNome() : null; |
||
| 87 | } |
||
| 88 | @Transient |
||
| 89 | public String getNomeAbreviadoDaPessoa() { |
||
| 90 | if (VerificadorUtil.naoEstaNulo(getNomeDaPessoa())) { |
||
| 91 | String pattern = "\\S+"; |
||
| 92 | Pattern r = Pattern.compile(pattern); |
||
| 93 | Matcher m = r.matcher(getNomeDaPessoa()); |
||
| 94 | if (m.find( )) { |
||
| 95 | return m.group(0); |
||
| 96 | } |
||
| 97 | return getNomeDaPessoa(); |
||
| 98 | } |
||
| 99 | return ""; |
||
| 100 | } |
||
| 101 | |||
| 102 | @Override |
||
| 103 | public int hashCode() { |
||
| 104 | final int prime = 31; |
||
| 105 | int result = 1; |
||
| 106 | result = prime * result + ((pessoa == null) ? 0 : pessoa.hashCode()); |
||
| 107 | return result; |
||
| 108 | } |
||
| 109 | |||
| 110 | @Override |
||
| 111 | public boolean equals(Object obj) { |
||
| 112 | if (this == obj) |
||
| 113 | return true; |
||
| 114 | if (obj == null) |
||
| 115 | return false; |
||
| 116 | if (getClass() != obj.getClass()) |
||
| 117 | return false; |
||
| 118 | Fornecedor other = (Fornecedor) obj; |
||
| 119 | if (pessoa == null) { |
||
| 120 | if (other.pessoa != null) |
||
| 121 | return false; |
||
| 122 | } else if (!pessoa.equals(other.pessoa)) |
||
| 123 | return false; |
||
| 124 | return true; |
||
| 125 | } |
||
| 126 | |||
| 127 | } |