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.ArrayList; |
||
| 5 | import java.util.Collections; |
||
| 6 | import java.util.Comparator; |
||
| 7 | import java.util.Date; |
||
| 8 | import java.util.List; |
||
| 9 | |||
| 10 | import javax.persistence.CascadeType; |
||
| 11 | import javax.persistence.Column; |
||
| 12 | import javax.persistence.Entity; |
||
| 13 | import javax.persistence.GeneratedValue; |
||
| 14 | import javax.persistence.GenerationType; |
||
| 15 | import javax.persistence.Id; |
||
| 16 | import javax.persistence.JoinColumn; |
||
| 17 | import javax.persistence.ManyToOne; |
||
| 18 | import javax.persistence.OneToMany; |
||
| 19 | import javax.persistence.Table; |
||
| 20 | import javax.persistence.Transient; |
||
| 21 | import javax.validation.constraints.NotNull; |
||
| 22 | |||
| 23 | import org.hibernate.annotations.ForeignKey; |
||
| 24 | |||
| 25 | import br.com.ec.domain.dto.TransferenciaProdutoDTO; |
||
| 26 | import br.edu.cesmac.core.generic.identidade.Identidade; |
||
| 27 | import br.edu.cesmac.core.interfaces.Alterar; |
||
| 28 | import br.edu.cesmac.core.interfaces.Cadastrar; |
||
| 29 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 30 | |||
| 31 | @Entity |
||
| 32 | @Table(name="sec_transferencia", schema="sc_sec") |
||
| 33 | public class Transferencia implements Serializable, Identidade { |
||
| 34 | |||
| 35 | private static final long serialVersionUID = 1L; |
||
| 36 | |||
| 37 | private Long sequencial; |
||
| 38 | private Loja lojaSaida; |
||
| 39 | private Loja lojaEntrada; |
||
| 40 | private Date dataSolicitacao; |
||
| 41 | private Boolean conferido; |
||
| 42 | private Date dataFinalizacao; |
||
| 43 | private NotaFiscal notaFiscalRemessa; |
||
| 44 | |||
| 45 | private List<TransferenciaProduto> listaProdutos; |
||
| 46 | |||
| 47 | private List<TransferenciaProdutoDTO> produtosDTO; |
||
| 48 | |||
| 49 | @Override |
||
| 50 | @Transient |
||
| 51 | public Object getId() { |
||
| 52 | return this.getSequencial(); |
||
| 53 | } |
||
| 54 | @Override |
||
| 55 | public void setId(Object id) { |
||
| 56 | this.sequencial = (Long) id; |
||
| 57 | } |
||
| 58 | |||
| 59 | @Id |
||
| 60 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 61 | @Column(name="seq_transferencia", nullable=false) |
||
| 62 | public Long getSequencial() { |
||
| 63 | return sequencial; |
||
| 64 | } |
||
| 65 | public void setSequencial(Long sequencial) { |
||
| 66 | this.sequencial = sequencial; |
||
| 67 | } |
||
| 68 | |||
| 69 | @ManyToOne |
||
| 70 | @ForeignKey(name="fk_transferencia_loja_saida") |
||
| 71 | @JoinColumn(name = "seq_loja_saida", nullable = false) |
||
| 72 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de saída", groups = {Cadastrar.class, Alterar.class}) |
||
| 73 | public Loja getLojaSaida() { |
||
| 74 | return lojaSaida; |
||
| 75 | } |
||
| 76 | public void setLojaSaida(Loja lojaSaida) { |
||
| 77 | this.lojaSaida = lojaSaida; |
||
| 78 | } |
||
| 79 | |||
| 80 | @ManyToOne |
||
| 81 | @ForeignKey(name="fk_transferencia_loja_entrada") |
||
| 82 | @JoinColumn(name = "seq_loja_entrada", nullable = false) |
||
| 83 | @NotNull(message = "Parâmetro obrigatório não preenchido: Loja de destino", groups = {Cadastrar.class, Alterar.class}) |
||
| 84 | public Loja getLojaEntrada() { |
||
| 85 | return lojaEntrada; |
||
| 86 | } |
||
| 87 | public void setLojaEntrada(Loja lojaEntrada) { |
||
| 88 | this.lojaEntrada = lojaEntrada; |
||
| 89 | } |
||
| 90 | |||
| 91 | @NotNull(message = "Parâmetro obrigatório não preenchido: Data da Solicitação", groups = {Cadastrar.class, Alterar.class}) |
||
| 92 | @Column(name="dat_solicitacao") |
||
| 93 | public Date getDataSolicitacao() { |
||
| 94 | return dataSolicitacao; |
||
| 95 | } |
||
| 96 | public void setDataSolicitacao(Date dataSolicitacao) { |
||
| 97 | this.dataSolicitacao = dataSolicitacao; |
||
| 98 | } |
||
| 99 | |||
| 100 | @NotNull(message = "Parâmetro obrigatório não preenchido: Transferência conferida", groups = {Cadastrar.class, Alterar.class}) |
||
| 101 | @Column(name="ind_conferido") |
||
| 102 | public Boolean getConferido() { |
||
| 103 | return conferido; |
||
| 104 | } |
||
| 105 | public void setConferido(Boolean conferido) { |
||
| 106 | this.conferido = conferido; |
||
| 107 | } |
||
| 108 | |||
| 109 | @Column(name="dat_finalizacao") |
||
| 110 | public Date getDataFinalizacao() { |
||
| 111 | return dataFinalizacao; |
||
| 112 | } |
||
| 113 | public void setDataFinalizacao(Date dataFinalizacao) { |
||
| 114 | this.dataFinalizacao = dataFinalizacao; |
||
| 115 | } |
||
| 116 | |||
| 117 | @ManyToOne |
||
| 118 | @ForeignKey(name="fk_transferencia_notafiscalremessa") |
||
| 119 | @JoinColumn(name = "seq_nota_fiscal") |
||
| 120 | public NotaFiscal getNotaFiscalRemessa() { |
||
| 121 | return notaFiscalRemessa; |
||
| 122 | } |
||
| 123 | public void setNotaFiscalRemessa(NotaFiscal notaFiscalRemessa) { |
||
| 124 | this.notaFiscalRemessa = notaFiscalRemessa; |
||
| 125 | } |
||
| 126 | |||
| 127 | @OneToMany(mappedBy="transferencia", cascade=CascadeType.ALL, orphanRemoval=true) |
||
| 128 | public List<TransferenciaProduto> getListaProdutos() { |
||
| 129 | return listaProdutos; |
||
| 130 | } |
||
| 131 | public void setListaProdutos(List<TransferenciaProduto> listaProdutos) { |
||
| 132 | this.listaProdutos = listaProdutos; |
||
| 133 | } |
||
| 134 | |||
| 135 | @Transient |
||
| 136 | public List<TransferenciaProdutoDTO> getProdutosDTO() { |
||
| 137 | return produtosDTO; |
||
| 138 | } |
||
| 139 | public void setProdutosDTO(List<TransferenciaProdutoDTO> produtosDTO) { |
||
| 140 | this.produtosDTO = produtosDTO; |
||
| 141 | } |
||
| 142 | |||
| 143 | @Override |
||
| 144 | public int hashCode() { |
||
| 145 | final int prime = 31; |
||
| 146 | int result = 1; |
||
| 147 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 148 | return result; |
||
| 149 | } |
||
| 150 | @Override |
||
| 151 | public boolean equals(Object obj) { |
||
| 152 | if (this == obj) |
||
| 153 | return true; |
||
| 154 | if (obj == null) |
||
| 155 | return false; |
||
| 156 | if (getClass() != obj.getClass()) |
||
| 157 | return false; |
||
| 158 | Transferencia other = (Transferencia) obj; |
||
| 159 | if (sequencial == null) { |
||
| 160 | if (other.sequencial != null) |
||
| 161 | return false; |
||
| 162 | } else if (!sequencial.equals(other.sequencial)) |
||
| 163 | return false; |
||
| 164 | return true; |
||
| 165 | } |
||
| 166 | |||
| 167 | @Transient |
||
| 168 | public Object getSequencialDaLojaEntrada() { |
||
| 169 | return VerificadorUtil.naoEstaNulo(getLojaEntrada())? getLojaEntrada().getSequencial() : null; |
||
| 170 | } |
||
| 171 | |||
| 172 | @Transient |
||
| 173 | public Object getSequencialDaLojaSaida() { |
||
| 174 | return VerificadorUtil.naoEstaNulo(getLojaSaida())? getLojaSaida().getSequencial() : null; |
||
| 175 | } |
||
| 176 | |||
| 177 | @Transient |
||
| 178 | public List<TransferenciaProduto> getProdutosOrdenados() { |
||
| 179 | List<TransferenciaProduto> produtosOrdenados = null; |
||
| 180 | if (VerificadorUtil.naoEstaNulo(getListaProdutos())) { |
||
| 181 | produtosOrdenados = new ArrayList<TransferenciaProduto>(getListaProdutos()); |
||
| 182 | Collections.sort(produtosOrdenados, new Comparator<TransferenciaProduto>() { |
||
| 183 | public int compare(TransferenciaProduto p1, TransferenciaProduto p2) { |
||
| 184 | return p1.getProduto().getDescricaoDoModelo().compareTo(p2.getProduto().getDescricaoDoModelo()); |
||
| 185 | }; |
||
| 186 | }); |
||
| 187 | } |
||
| 188 | return produtosOrdenados; |
||
| 189 | } |
||
| 190 | |||
| 191 | public void adicionarProduto(TransferenciaProduto produto) { |
||
| 192 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 193 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 194 | } |
||
| 195 | getListaProdutos().add(produto); |
||
| 196 | } |
||
| 197 | |||
| 198 | public void removerProduto(TransferenciaProduto transferenciaProduto) { |
||
| 199 | if (!VerificadorUtil.isListaNulaOuVazia(getListaProdutos())) { |
||
| 200 | getListaProdutos().remove(transferenciaProduto); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | public void removerProduto(TransferenciaProdutoDTO transferenciaProdutoDTO) { |
||
| 205 | if (!VerificadorUtil.isListaNulaOuVazia(getProdutosDTO())) { |
||
| 206 | getProdutosDTO().remove(transferenciaProdutoDTO); |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | public boolean verificarSeProdutoJaConstaNaLista(TransferenciaProduto transferenciaProduto) { |
||
| 211 | if (VerificadorUtil.estaNulo(getListaProdutos())) { |
||
| 212 | setListaProdutos(new ArrayList<TransferenciaProduto>()); |
||
| 213 | } |
||
| 214 | for (TransferenciaProduto item : getListaProdutos()) { |
||
| 215 | if (item.equals(transferenciaProduto)) { |
||
| 216 | return true; |
||
| 217 | } |
||
| 218 | } |
||
| 219 | return false; |
||
| 220 | } |
||
| 221 | |||
| 222 | public boolean verificarSeProdutoJaConstaNaLista(Long sequencialProduto) { |
||
| 223 | if (VerificadorUtil.estaNulo(getProdutosDTO())) { |
||
| 224 | setProdutosDTO(new ArrayList<TransferenciaProdutoDTO>()); |
||
| 225 | } |
||
| 226 | for (TransferenciaProdutoDTO item : getProdutosDTO()) { |
||
| 227 | if (item.getSequencialProduto().equals(sequencialProduto)) { |
||
| 228 | return true; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | return false; |
||
| 232 | } |
||
| 233 | |||
| 234 | } |