Rev 472 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 472 | Rev 485 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | 2 | ||
| 3 | import java.io.File; |
3 | import java.io.File; |
| 4 | import java.io.FileOutputStream; |
- | |
| 5 | import java.util.ArrayList; |
- | |
| 6 | import java.util.List; |
- | |
| 7 | 4 | ||
| 8 | import javax.faces.context.FacesContext; |
5 | import javax.faces.context.FacesContext; |
| 9 | import javax.inject.Named; |
6 | import javax.inject.Named; |
| 10 | import javax.persistence.Transient; |
- | |
| 11 | import javax.servlet.ServletContext; |
7 | import javax.servlet.ServletContext; |
| 12 | 8 | ||
| 13 | import org.primefaces.event.FileUploadEvent; |
- | |
| 14 | import org.primefaces.model.file.UploadedFile; |
9 | import org.primefaces.model.file.UploadedFile; |
| 15 | import org.springframework.context.annotation.Scope; |
10 | import org.springframework.context.annotation.Scope; |
| 16 | 11 | ||
| 17 | import br.com.ec.core.exception.NegocioException; |
- | |
| 18 | import br.com.ec.core.util.ArquivoUtil; |
- | |
| 19 | import br.com.ec.core.util.VerificadorUtil; |
12 | import br.com.ec.core.util.VerificadorUtil; |
| 20 | import br.com.ec.domain.dto.FotoDTO; |
13 | import br.com.ec.domain.dto.FotoDTO; |
| 21 | import br.com.ec.domain.dto.ProdutoDTO; |
14 | import br.com.ec.domain.dto.ProdutoDTO; |
| 22 | import br.com.ec.domain.model.Produto; |
15 | import br.com.ec.domain.model.Produto; |
| 23 | import br.com.ec.domain.shared.ConstantesSEC; |
16 | import br.com.ec.domain.shared.ConstantesSEC; |
| 24 | import br.com.ec.web.exception.VerificadorLancamentoException; |
- | |
| 25 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
- | |
| 26 | import br.com.ec.web.message.LancadorMensagem; |
- | |
| 27 | 17 | ||
| 28 | @Named |
18 | @Named |
| 29 | @Scope("view") |
19 | @Scope("view") |
| 30 | public class FotoBean { |
20 | public class FotoBean { |
| 31 | 21 | ||
| Line 47... | Line 37... | ||
| 47 | }
|
37 | }
|
| 48 | 38 | ||
| 49 | /**********************************************/
|
39 | /**********************************************/
|
| 50 | 40 | ||
| 51 | public String getCaminhoPadraoFotos() { |
41 | public String getCaminhoPadraoFotos() { |
| 52 | return ConstantesSEC.TESTE_LOCAL? ConstantesSEC.Foto.CAMINHO_PADRAO_LOCAL : ConstantesSEC.Foto.CAMINHO_PADRAO_SERVIDOR; |
- | |
| - | 42 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? ConstantesSEC.Foto.CAMINHO_PADRAO_LOCAL : ConstantesSEC.Foto.CAMINHO_PADRAO_SERVIDOR; |
|
| 53 | }
|
43 | }
|
| 54 | 44 | ||
| 55 | public String getCaminhoPastaFotos() { |
45 | public String getCaminhoPastaFotos() { |
| 56 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
46 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
| 57 | return ConstantesSEC.TESTE_LOCAL? |
- | |
| - | 47 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? |
|
| 58 | servletContext.getRealPath("") + File.separator + "fotos" + File.separator : |
48 | servletContext.getRealPath("") + File.separator + "fotos" + File.separator : |
| 59 | servletContext.getRealPath("") + File.separator + ".." + File.separator + "fotos" + File.separator; |
49 | servletContext.getRealPath("") + File.separator + ".." + File.separator + "fotos" + File.separator; |
| 60 | }
|
50 | }
|
| 61 | 51 | ||
| 62 | public String fotoPadraoProduto(ProdutoDTO produtoDTO) { |
- | |
| - | 52 | public String fotoPadraoProdutoDTO(ProdutoDTO produtoDTO) { |
|
| 63 | try { |
53 | try { |
| 64 | if (VerificadorUtil.naoEstaNulo(produtoDTO)) { |
54 | if (VerificadorUtil.naoEstaNulo(produtoDTO)) { |
| 65 | if (VerificadorUtil.naoEstaNuloOuVazio(produtoDTO.getCodigo())) { |
55 | if (VerificadorUtil.naoEstaNuloOuVazio(produtoDTO.getCodigo())) { |
| 66 | File foto = new File(getCaminhoPastaFotos() + produtoDTO.getCodigoProdutoPadrao() + ".jpg"); |
56 | File foto = new File(getCaminhoPastaFotos() + produtoDTO.getCodigoProdutoPadrao() + ".jpg"); |
| 67 | return foto.exists()? getCaminhoPadraoFotos() + produtoDTO.getCodigoProdutoPadrao() + ".jpg" : getCaminhoPadraoFotos() + "SEM_FOTO.jpg"; |
57 | return foto.exists()? getCaminhoPadraoFotos() + produtoDTO.getCodigoProdutoPadrao() + ".jpg" : getCaminhoPadraoFotos() + "SEM_FOTO.jpg"; |
| Line 74... | Line 64... | ||
| 74 | }
|
64 | }
|
| 75 | 65 | ||
| 76 | public String fotoPadraoProdutoComCodigo(String codigo) { |
66 | public String fotoPadraoProdutoComCodigo(String codigo) { |
| 77 | ProdutoDTO produtoDTO = new ProdutoDTO(); |
67 | ProdutoDTO produtoDTO = new ProdutoDTO(); |
| 78 | produtoDTO.setCodigo(codigo); |
68 | produtoDTO.setCodigo(codigo); |
| 79 | return fotoPadraoProduto(produtoDTO); |
- | |
| - | 69 | return fotoPadraoProdutoDTO(produtoDTO); |
|
| 80 | }
|
70 | }
|
| 81 | 71 | ||
| 82 | public String fotoPadraoProduto(Produto produto) { |
72 | public String fotoPadraoProduto(Produto produto) { |
| 83 | try { |
73 | try { |
| 84 | if (VerificadorUtil.naoEstaNulo(produto)) { |
74 | if (VerificadorUtil.naoEstaNulo(produto)) { |