Rev 530 | Rev 533 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 530 | Rev 531 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | package br.com.ec.domain.model; |
1 | package br.com.ec.domain.model; |
| 2 | 2 | ||
| - | 3 | import java.beans.Transient; |
|
| - | 4 | import java.io.File; |
|
| 3 | import java.io.Serializable; |
5 | import java.io.Serializable; |
| 4 | 6 | ||
| - | 7 | import javax.faces.context.FacesContext; |
|
| 5 | import javax.persistence.Column; |
8 | import javax.persistence.Column; |
| 6 | import javax.persistence.Entity; |
9 | import javax.persistence.Entity; |
| 7 | import javax.persistence.GeneratedValue; |
10 | import javax.persistence.GeneratedValue; |
| 8 | import javax.persistence.GenerationType; |
11 | import javax.persistence.GenerationType; |
| 9 | import javax.persistence.Id; |
12 | import javax.persistence.Id; |
| 10 | import javax.persistence.JoinColumn; |
13 | import javax.persistence.JoinColumn; |
| 11 | import javax.persistence.ManyToOne; |
14 | import javax.persistence.ManyToOne; |
| 12 | import javax.persistence.Table; |
15 | import javax.persistence.Table; |
| - | 16 | import javax.servlet.ServletContext; |
|
| 13 | import javax.validation.constraints.NotNull; |
17 | import javax.validation.constraints.NotNull; |
| 14 | import javax.validation.constraints.Size; |
18 | import javax.validation.constraints.Size; |
| 15 | 19 | ||
| 16 | import org.hibernate.annotations.ForeignKey; |
20 | import org.hibernate.annotations.ForeignKey; |
| 17 | import org.hibernate.validator.constraints.NotEmpty; |
21 | import org.hibernate.validator.constraints.NotEmpty; |
| 18 | 22 | ||
| 19 | import br.com.ec.core.interfaces.Alterar; |
23 | import br.com.ec.core.interfaces.Alterar; |
| 20 | import br.com.ec.core.interfaces.Cadastrar; |
24 | import br.com.ec.core.interfaces.Cadastrar; |
| 21 | import br.com.ec.core.util.StringUtil; |
25 | import br.com.ec.core.util.StringUtil; |
| - | 26 | import br.com.ec.domain.shared.ConstantesSEC; |
|
| 22 | 27 | ||
| 23 | @Entity |
28 | @Entity |
| 24 | @Table(name="sec_estampa", schema="sc_sec") |
29 | @Table(name="sec_estampa", schema="sc_sec") |
| 25 | public class Estampa implements Serializable { |
30 | public class Estampa implements Serializable { |
| 26 | 31 | ||
| Line 128... | Line 133... | ||
| 128 | 133 | ||
| 129 | /*******************************************/
|
134 | /*******************************************/
|
| 130 | 135 | ||
| 131 | public String identificadorEstampa() { |
136 | public String identificadorEstampa() { |
| 132 | return "#" + getTemaEstampa().getCodigo() + getCodigo(); |
137 | return "#" + getTemaEstampa().getCodigo() + getCodigo(); |
| - | 138 | }
|
|
| - | 139 | ||
| - | 140 | public String identificadorImagemEstampa() { |
|
| - | 141 | return getTemaEstampa().getCodigo() + getCodigo(); |
|
| - | 142 | }
|
|
| - | 143 | ||
| - | 144 | /******************/
|
|
| - | 145 | ||
| - | 146 | @Transient |
|
| - | 147 | public String caminhoPastaImagens() { |
|
| - | 148 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
|
| - | 149 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? |
|
| - | 150 | servletContext.getRealPath("") + File.separator + ConstantesSEC.Estampa.NOME_PASTA_PADRAO + File.separator : |
|
| - | 151 | servletContext.getRealPath("") + File.separator + ".." + File.separator + ConstantesSEC.Estampa.NOME_PASTA_PADRAO + File.separator; |
|
| - | 152 | }
|
|
| - | 153 | ||
| - | 154 | @Transient |
|
| - | 155 | public String imagemEstampa() { |
|
| - | 156 | return retornarImagemPngOuJpg(); |
|
| - | 157 | }
|
|
| - | 158 | ||
| - | 159 | private String retornarImagemPngOuJpg() { |
|
| - | 160 | File foto = new File(caminhoPastaImagens() + StringUtil.setarLowerCase(identificadorImagemEstampa()) + ".jpg"); |
|
| - | 161 | if (foto.exists()) { |
|
| - | 162 | return caminhoPastaImagens() + StringUtil.setarLowerCase(identificadorImagemEstampa()) + ".jpg"; |
|
| - | 163 | }
|
|
| - | 164 | foto = new File(caminhoPastaImagens() + StringUtil.setarLowerCase(identificadorImagemEstampa()) + ".jpeg"); |
|
| - | 165 | if (foto.exists()) { |
|
| - | 166 | return caminhoPastaImagens() + StringUtil.setarLowerCase(identificadorImagemEstampa()) + ".jpeg"; |
|
| - | 167 | }
|
|
| - | 168 | if (!foto.exists()) { |
|
| - | 169 | foto = new File(caminhoPastaImagens() + StringUtil.setarLowerCase(identificadorImagemEstampa()) + ".png"); |
|
| - | 170 | }
|
|
| - | 171 | return foto.exists()? caminhoPastaImagens() + StringUtil.setarLowerCase(identificadorImagemEstampa()) + ".png" : |
|
| - | 172 | caminhoPastaImagens() + "SEM_IMAGEM.png"; |
|
| 133 | }
|
173 | }
|
| 134 | 174 | ||
| 135 | }
|
175 | }
|