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