Rev 530 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 528 | blopes | 1 | package br.com.ec.domain.service.impl; |
| 2 | |||
| 3 | import java.io.File; |
||
| 4 | |||
| 5 | import javax.faces.context.FacesContext; |
||
| 6 | import javax.servlet.ServletContext; |
||
| 7 | |||
| 8 | import org.primefaces.event.FileUploadEvent; |
||
| 9 | import org.primefaces.model.file.UploadedFile; |
||
| 10 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 11 | import org.springframework.stereotype.Service; |
||
| 12 | |||
| 13 | import br.com.ec.core.generic.AbstractService; |
||
| 14 | import br.com.ec.core.generic.GenericRepository; |
||
| 15 | import br.com.ec.core.util.ArquivoUtil; |
||
| 16 | import br.com.ec.core.validador.Validador; |
||
| 17 | import br.com.ec.domain.dto.ImagemDTO; |
||
| 18 | import br.com.ec.domain.service.ImagemService; |
||
| 19 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 20 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 21 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 22 | import br.com.ec.web.message.LancadorMensagem; |
||
| 23 | |||
| 24 | @Service |
||
| 25 | public class ImagemServiceImpl extends AbstractService<ImagemDTO> implements ImagemService { |
||
| 26 | |||
| 27 | @Autowired |
||
| 28 | public ImagemServiceImpl(Validador validador) { |
||
| 29 | super(validador); |
||
| 30 | } |
||
| 31 | |||
| 32 | @Override |
||
| 33 | protected GenericRepository<ImagemDTO> getRepository() { |
||
| 34 | return null; |
||
| 35 | } |
||
| 36 | |||
| 37 | @Override |
||
| 38 | public String caminhoPadraoFotos() { |
||
| 39 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? ConstantesSEC.Foto.CAMINHO_PADRAO_LOCAL : ConstantesSEC.Foto.CAMINHO_PADRAO_SERVIDOR; |
||
| 40 | } |
||
| 41 | |||
| 42 | @Override |
||
| 43 | public String caminhoPastaFotos() { |
||
| 44 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
||
| 45 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? |
||
| 46 | servletContext.getRealPath("") + File.separator + ConstantesSEC.Foto.NOME_PASTA_PADRAO + File.separator : |
||
| 47 | servletContext.getRealPath("") + File.separator + ".." + File.separator + ConstantesSEC.Foto.NOME_PASTA_PADRAO + File.separator; |
||
| 48 | } |
||
| 49 | |||
| 50 | @Override |
||
| 51 | public String caminhoPadraoImagens() { |
||
| 52 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? ConstantesSEC.Imagem.CAMINHO_PADRAO_LOCAL : ConstantesSEC.Imagem.CAMINHO_PADRAO_SERVIDOR; |
||
| 53 | } |
||
| 54 | |||
| 55 | @Override |
||
| 56 | public String caminhoPastaImagens() { |
||
| 57 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
||
| 58 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? |
||
| 59 | servletContext.getRealPath("") + File.separator + ConstantesSEC.Imagem.NOME_PASTA_PADRAO + File.separator : |
||
| 60 | servletContext.getRealPath("") + File.separator + ".." + File.separator + ConstantesSEC.Imagem.NOME_PASTA_PADRAO + File.separator; |
||
| 61 | } |
||
| 62 | |||
| 63 | @Override |
||
| 64 | public String caminhoPadraoEstampas() { |
||
| 65 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? ConstantesSEC.Estampa.CAMINHO_PADRAO_LOCAL : ConstantesSEC.Estampa.CAMINHO_PADRAO_SERVIDOR; |
||
| 66 | } |
||
| 67 | |||
| 68 | @Override |
||
| 69 | public String caminhoPastaEstampas() { |
||
| 70 | ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); |
||
| 71 | return ConstantesSEC.TESTE_EMISSAO_LOCAL? |
||
| 72 | servletContext.getRealPath("") + File.separator + ConstantesSEC.Estampa.NOME_PASTA_PADRAO + File.separator : |
||
| 73 | servletContext.getRealPath("") + File.separator + ".." + File.separator + ConstantesSEC.Estampa.NOME_PASTA_PADRAO + File.separator; |
||
| 74 | } |
||
| 75 | |||
| 76 | /*****************************************/ |
||
| 77 | |||
| 78 | @Override |
||
| 79 | public ImagemDTO uploadImagem(FileUploadEvent e) { |
||
| 80 | // ImagemDTO imagemAdicionada = gerarArquivo(e.getFile()); |
||
| 81 | // imagemAdicionada.setDescricao("promocoes_" + getEntidade().getVigencia().getSequencial()); |
||
| 82 | // lancarExcecaoCasoArquivoExcedeuLimite(imagemAdicionada); |
||
| 83 | // imagemAdicionada.compactarImagem(); |
||
| 84 | // imagemAdicionada.converterPngParaJpg(); |
||
| 85 | // setImagemParaUpload(e.getFile()); |
||
| 86 | // uploadFisico(imagemAdicionada); |
||
| 87 | return null; |
||
| 88 | } |
||
| 89 | |||
| 90 | public ImagemDTO gerarArquivo(UploadedFile file) { |
||
| 91 | ImagemDTO arquivo = new ImagemDTO(); |
||
| 92 | arquivo.setArquivo(file.getContent()); |
||
| 93 | arquivo.setDescricao(file.getFileName()); |
||
| 94 | arquivo.setExtensao(ArquivoUtil.retornarExtensaoDoArquivo(file.getFileName())); |
||
| 95 | return arquivo; |
||
| 96 | } |
||
| 97 | |||
| 98 | } |