Rev 695 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 695 | blopes | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.File; |
||
| 4 | import java.io.Serializable; |
||
| 5 | import java.util.Date; |
||
| 6 | |||
| 7 | import javax.faces.context.FacesContext; |
||
| 8 | import javax.persistence.Column; |
||
| 9 | import javax.persistence.Entity; |
||
| 10 | import javax.persistence.GeneratedValue; |
||
| 11 | import javax.persistence.GenerationType; |
||
| 12 | import javax.persistence.Id; |
||
| 13 | import javax.persistence.SequenceGenerator; |
||
| 14 | import javax.persistence.Table; |
||
| 15 | import javax.persistence.Transient; |
||
| 16 | import javax.servlet.ServletContext; |
||
| 17 | import javax.validation.constraints.NotNull; |
||
| 18 | import javax.validation.constraints.Size; |
||
| 19 | |||
| 20 | import org.hibernate.validator.constraints.NotEmpty; |
||
| 21 | |||
| 22 | import br.com.ec.core.interfaces.Alterar; |
||
| 23 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 24 | import br.com.ec.core.util.StringUtil; |
||
| 25 | import br.com.ec.domain.model.tipos.TipoSituacoesVigencia; |
||
| 26 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 27 | |||
| 28 | @Entity |
||
| 749 | blopes | 29 | @Table(name="sec_vigencia", schema="sc_lse") |
| 695 | blopes | 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 | // SITUAÇÕES: PENDENTE, EM ANDAMENTO, FINALIZADA |
||
| 40 | private String tipoSituacaoFolha; //tip_situacao_folha |
||
| 41 | |||
| 42 | /* |
||
| 43 | private String tipoSituacaoValeTransporte; //tip_situacao_valetransporte |
||
| 44 | private String tipoSituacaoConciliacaoBancaria; //tip_situacao_conciliacaobancaria |
||
| 45 | private String tipoSituacaoEscala; //tip_situacao_escala |
||
| 46 | private String tipoSituacaoMetas; //tip_situacao_metas |
||
| 47 | private String tipoSituacaoAvaliacoes; //tip_situacao_avaliacoes |
||
| 48 | private String tipoSituacaoProvisaoFerias; //tip_situacao_provisaoferias |
||
| 49 | private String tipoSituacaoNotasFiscais; //tip_situacao_notasfiscais |
||
| 50 | |||
| 51 | private String tipoSituacaoConsolidacao; //tip_situacao_consolidacao |
||
| 52 | */ |
||
| 53 | |||
| 54 | public Vigencia() {} |
||
| 55 | |||
| 56 | public Vigencia(Long sequencial) { |
||
| 57 | this.sequencial = sequencial; |
||
| 58 | } |
||
| 59 | |||
| 60 | public Vigencia(Long sequencial, String descricao) { |
||
| 61 | this.sequencial = sequencial; |
||
| 62 | this.descricao = descricao; |
||
| 63 | } |
||
| 64 | |||
| 65 | @Id |
||
| 66 | @SequenceGenerator(name = "sq_vigencia") |
||
| 67 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 68 | @Column(name="seq_vigencia", nullable=false) |
||
| 69 | public Long getSequencial() { |
||
| 70 | return sequencial; |
||
| 71 | } |
||
| 72 | public void setSequencial(Long sequencial) { |
||
| 73 | this.sequencial = sequencial; |
||
| 74 | } |
||
| 75 | |||
| 76 | @Column(name="dsc_vigencia") |
||
| 77 | @Size(max = 10, message = "Limite de caracteres ultrapassado: Vigência") |
||
| 78 | @NotNull(message="Obrigatório informar a descrição", groups={Cadastrar.class, Alterar.class}) |
||
| 79 | @NotEmpty(message="Obrigatório informar a descrição", groups={Cadastrar.class, Alterar.class}) |
||
| 80 | public String getDescricao() { |
||
| 81 | return descricao; |
||
| 82 | } |
||
| 83 | public void setDescricao(String descricao) { |
||
| 84 | this.descricao = StringUtil.setarUpperCaseComTrim(descricao); |
||
| 85 | } |
||
| 86 | |||
| 87 | @Column(name="dth_inicio") |
||
| 88 | @NotNull(message="Obrigatório informar a data de início", groups={Cadastrar.class, Alterar.class}) |
||
| 89 | public Date getDataInicio() { |
||
| 90 | return dataInicio; |
||
| 91 | } |
||
| 92 | public void setDataInicio(Date dataInicio) { |
||
| 93 | this.dataInicio = dataInicio; |
||
| 94 | } |
||
| 95 | |||
| 96 | @Column(name="dth_fim") |
||
| 97 | @NotNull(message="Obrigatório informar a data de fim", groups={Cadastrar.class, Alterar.class}) |
||
| 98 | public Date getDataFim() { |
||
| 99 | return dataFim; |
||
| 100 | } |
||
| 101 | public void setDataFim(Date dataFim) { |
||
| 102 | this.dataFim = dataFim; |
||
| 103 | } |
||
| 104 | |||
| 105 | @Column(name="tip_situacao_folha") |
||
| 106 | @NotNull(message="Obrigatório informar a situação da folha de pagamento", groups={Cadastrar.class, Alterar.class}) |
||
| 107 | public String getTipoSituacaoFolha() { |
||
| 108 | return tipoSituacaoFolha; |
||
| 109 | } |
||
| 110 | public void setTipoSituacaoFolha(String tipoSituacaoFolha) { |
||
| 111 | this.tipoSituacaoFolha = tipoSituacaoFolha; |
||
| 112 | } |
||
| 113 | |||
| 114 | @Transient |
||
| 115 | public String descricaoSituacaoFolha() { |
||
| 116 | return TipoSituacoesVigencia.parse(getTipoSituacaoFolha()).getDescricao(); |
||
| 117 | } |
||
| 118 | |||
| 119 | @Transient |
||
| 120 | public String corSituacaoFolha() { |
||
| 121 | return TipoSituacoesVigencia.parse(getTipoSituacaoFolha()).getCor(); |
||
| 122 | } |
||
| 123 | |||
| 124 | @Override |
||
| 125 | public int hashCode() { |
||
| 126 | final int prime = 31; |
||
| 127 | int result = 1; |
||
| 128 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 129 | return result; |
||
| 130 | } |
||
| 131 | |||
| 132 | @Override |
||
| 133 | public boolean equals(Object obj) { |
||
| 134 | if (this == obj) |
||
| 135 | return true; |
||
| 136 | if (obj == null) |
||
| 137 | return false; |
||
| 138 | if (getClass() != obj.getClass()) |
||
| 139 | return false; |
||
| 140 | Vigencia other = (Vigencia) obj; |
||
| 141 | if (sequencial == null) { |
||
| 142 | if (other.sequencial != null) |
||
| 143 | return false; |
||
| 144 | } else if (!sequencial.equals(other.sequencial)) |
||
| 145 | return false; |
||
| 146 | return true; |
||
| 147 | } |
||
| 148 | |||
| 149 | /********************************************/ |
||
| 150 | |||
| 151 | @Transient |
||
| 152 | public String caminhoPadraoImagens() { |
||
| 153 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? ConstantesSEC.Imagem.CAMINHO_PADRAO_LOCAL : ConstantesSEC.Imagem.CAMINHO_PADRAO_SERVIDOR; |
||
| 154 | } |
||
| 155 | |||
| 156 | @Transient |
||
| 157 | public String caminhoPastaImagens() { |
||
| 158 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
||
| 159 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? |
||
| 160 | servletContext.getRealPath("") + File.separator + ConstantesSEC.Imagem.NOME_PASTA_PADRAO + File.separator : |
||
| 161 | servletContext.getRealPath("") + File.separator + ".." + File.separator + ConstantesSEC.Imagem.NOME_PASTA_PADRAO + File.separator; |
||
| 162 | } |
||
| 163 | |||
| 164 | @Transient |
||
| 165 | public String imagemPromocoes() { |
||
| 166 | return retornarImagemPngOuJpg("promocoes_"); |
||
| 167 | } |
||
| 168 | |||
| 169 | @Transient |
||
| 170 | public String imagemEscala() { |
||
| 171 | return retornarImagemPngOuJpg("escala_"); |
||
| 172 | } |
||
| 173 | |||
| 174 | @Transient |
||
| 175 | public String imagemDestaques() { |
||
| 176 | return retornarImagemPngOuJpg("destaques_"); |
||
| 177 | } |
||
| 178 | |||
| 179 | private String retornarImagemPngOuJpg(String pasta) { |
||
| 180 | File foto = new File(caminhoPastaImagens() + pasta + getSequencial() + ".jpg"); |
||
| 181 | if (foto.exists()) { |
||
| 182 | return caminhoPadraoImagens() + pasta + getSequencial() + ".jpg"; |
||
| 183 | } |
||
| 184 | foto = new File(caminhoPastaImagens() + pasta + getSequencial() + ".jpeg"); |
||
| 185 | if (foto.exists()) { |
||
| 186 | return caminhoPadraoImagens() + pasta + getSequencial() + ".jpeg"; |
||
| 187 | } |
||
| 188 | if (!foto.exists()) { |
||
| 189 | foto = new File(caminhoPastaImagens() + pasta + getSequencial() + ".png"); |
||
| 190 | } |
||
| 191 | return foto.exists()? caminhoPadraoImagens() + pasta + getSequencial() + ".png" : caminhoPadraoImagens() + "SEM_IMAGEM.png"; |
||
| 192 | } |
||
| 193 | |||
| 194 | } |