Rev 527 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 527 | blopes | 3 | import java.beans.Transient; |
| 4 | import java.io.File; |
||
| 106 | espaco | 5 | import java.io.Serializable; |
| 6 | import java.util.Date; |
||
| 7 | |||
| 527 | blopes | 8 | import javax.faces.context.FacesContext; |
| 106 | espaco | 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.SequenceGenerator; |
||
| 15 | import javax.persistence.Table; |
||
| 527 | blopes | 16 | import javax.servlet.ServletContext; |
| 106 | espaco | 17 | import javax.validation.constraints.NotNull; |
| 18 | import javax.validation.constraints.Size; |
||
| 19 | |||
| 250 | espaco | 20 | import org.hibernate.annotations.Index; |
| 106 | espaco | 21 | import org.hibernate.validator.constraints.NotEmpty; |
| 22 | |||
| 195 | espaco | 23 | import br.com.ec.core.interfaces.Alterar; |
| 24 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 25 | import br.com.ec.core.util.StringUtil; |
||
| 527 | blopes | 26 | import br.com.ec.domain.shared.ConstantesSEC; |
| 106 | espaco | 27 | |
| 28 | @Entity |
||
| 29 | @Table(name="sec_vigencia", schema="sc_sec") |
||
| 30 | public class Vigencia implements Serializable { |
||
| 31 | |||
| 32 | private static final long serialVersionUID = 1L; |
||
| 33 | |||
| 34 | private Long sequencial; |
||
| 35 | private String descricao; |
||
| 36 | private Date dataInicio; |
||
| 37 | private Date dataFim; |
||
| 38 | |||
| 39 | public Vigencia() {} |
||
| 40 | |||
| 41 | public Vigencia(Long sequencial, String descricao) { |
||
| 42 | this.sequencial = sequencial; |
||
| 43 | this.descricao = descricao; |
||
| 44 | } |
||
| 45 | |||
| 46 | @Id |
||
| 250 | espaco | 47 | @Index(name = "ix_vigencia", columnNames = "seq_vigencia") |
| 106 | espaco | 48 | @SequenceGenerator(name = "sq_vigencia") |
| 49 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 50 | @Column(name="seq_vigencia", nullable=false) |
||
| 51 | public Long getSequencial() { |
||
| 52 | return sequencial; |
||
| 53 | } |
||
| 54 | public void setSequencial(Long sequencial) { |
||
| 55 | this.sequencial = sequencial; |
||
| 56 | } |
||
| 57 | |||
| 58 | @Column(name="dsc_vigencia") |
||
| 59 | @Size(max = 10, message = "Limite de caracteres ultrapassado: Vigência") |
||
| 60 | @NotNull(message="Obrigatório informar a descrição", groups={Cadastrar.class, Alterar.class}) |
||
| 61 | @NotEmpty(message="Obrigatório informar a descrição", groups={Cadastrar.class, Alterar.class}) |
||
| 62 | public String getDescricao() { |
||
| 63 | return descricao; |
||
| 64 | } |
||
| 65 | public void setDescricao(String descricao) { |
||
| 66 | this.descricao = StringUtil.setarUpperCaseComTrim(descricao); |
||
| 67 | } |
||
| 68 | |||
| 69 | @Column(name="dth_inicio") |
||
| 70 | @NotNull(message="Obrigatório informar a data de início", groups={Cadastrar.class, Alterar.class}) |
||
| 71 | public Date getDataInicio() { |
||
| 72 | return dataInicio; |
||
| 73 | } |
||
| 74 | public void setDataInicio(Date dataInicio) { |
||
| 75 | this.dataInicio = dataInicio; |
||
| 76 | } |
||
| 77 | |||
| 78 | @Column(name="dth_fim") |
||
| 79 | @NotNull(message="Obrigatório informar a data de fim", groups={Cadastrar.class, Alterar.class}) |
||
| 80 | public Date getDataFim() { |
||
| 81 | return dataFim; |
||
| 82 | } |
||
| 83 | public void setDataFim(Date dataFim) { |
||
| 84 | this.dataFim = dataFim; |
||
| 85 | } |
||
| 86 | |||
| 87 | @Override |
||
| 88 | public int hashCode() { |
||
| 89 | final int prime = 31; |
||
| 90 | int result = 1; |
||
| 91 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 92 | return result; |
||
| 93 | } |
||
| 94 | |||
| 95 | @Override |
||
| 96 | public boolean equals(Object obj) { |
||
| 97 | if (this == obj) |
||
| 98 | return true; |
||
| 99 | if (obj == null) |
||
| 100 | return false; |
||
| 101 | if (getClass() != obj.getClass()) |
||
| 102 | return false; |
||
| 103 | Vigencia other = (Vigencia) obj; |
||
| 104 | if (sequencial == null) { |
||
| 105 | if (other.sequencial != null) |
||
| 106 | return false; |
||
| 107 | } else if (!sequencial.equals(other.sequencial)) |
||
| 108 | return false; |
||
| 109 | return true; |
||
| 110 | } |
||
| 111 | |||
| 527 | blopes | 112 | /********************************************/ |
| 113 | |||
| 114 | @Transient |
||
| 115 | public String caminhoPadraoImagens() { |
||
| 116 | return ConstantesSEC.TESTE_LOCAL? ConstantesSEC.Imagem.CAMINHO_PADRAO_IMAGEM_LOCAL : ConstantesSEC.Imagem.CAMINHO_PADRAO_IMAGEM_SERVIDOR; |
||
| 117 | } |
||
| 118 | |||
| 119 | @Transient |
||
| 120 | public String caminhoPastaImagens() { |
||
| 121 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
||
| 122 | return ConstantesSEC.TESTE_LOCAL? |
||
| 123 | servletContext.getRealPath("") + File.separator + ConstantesSEC.Imagem.NOME_PASTA_PADRAO + File.separator : |
||
| 124 | servletContext.getRealPath("") + File.separator + ".." + File.separator + ConstantesSEC.Imagem.NOME_PASTA_PADRAO + File.separator; |
||
| 125 | } |
||
| 126 | |||
| 127 | @Transient |
||
| 529 | blopes | 128 | public String imagemPromocoes() { |
| 527 | blopes | 129 | return retornarImagemPngOuJpg("promocoes_"); |
| 130 | } |
||
| 131 | |||
| 132 | @Transient |
||
| 133 | public String imagemEscala() { |
||
| 134 | return retornarImagemPngOuJpg("escala_"); |
||
| 135 | } |
||
| 136 | |||
| 137 | private String retornarImagemPngOuJpg(String pasta) { |
||
| 138 | File foto = new File(caminhoPastaImagens() + pasta + getSequencial() + ".jpg"); |
||
| 139 | if (foto.exists()) { |
||
| 140 | return caminhoPadraoImagens() + pasta + getSequencial() + ".jpg"; |
||
| 141 | } |
||
| 529 | blopes | 142 | foto = new File(caminhoPastaImagens() + pasta + getSequencial() + ".jpeg"); |
| 143 | if (foto.exists()) { |
||
| 144 | return caminhoPadraoImagens() + pasta + getSequencial() + ".jpeg"; |
||
| 145 | } |
||
| 527 | blopes | 146 | if (!foto.exists()) { |
| 147 | foto = new File(caminhoPastaImagens() + pasta + getSequencial() + ".png"); |
||
| 148 | } |
||
| 149 | return foto.exists()? caminhoPadraoImagens() + pasta + getSequencial() + ".png" : caminhoPadraoImagens() + "SEM_IMAGEM.png"; |
||
| 150 | } |
||
| 151 | |||
| 106 | espaco | 152 | } |