Rev 528 | Rev 531 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 528 | Rev 530 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | 2 | ||
| 3 | import java.io.File; |
3 | import java.io.File; |
| - | 4 | import java.io.FileOutputStream; |
|
| 4 | 5 | ||
| 5 | import javax.faces.context.FacesContext; |
6 | import javax.faces.context.FacesContext; |
| 6 | import javax.servlet.ServletContext; |
7 | import javax.servlet.ServletContext; |
| 7 | 8 | ||
| 8 | import org.primefaces.event.FileUploadEvent; |
- | |
| 9 | import org.primefaces.model.file.UploadedFile; |
9 | import org.primefaces.model.file.UploadedFile; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; |
10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; |
11 | import org.springframework.stereotype.Service; |
| 12 | 12 | ||
| 13 | import br.com.ec.core.generic.AbstractService; |
13 | import br.com.ec.core.generic.AbstractService; |
| Line 15... | Line 15... | ||
| 15 | import br.com.ec.core.util.ArquivoUtil; |
15 | import br.com.ec.core.util.ArquivoUtil; |
| 16 | import br.com.ec.core.validador.Validador; |
16 | import br.com.ec.core.validador.Validador; |
| 17 | import br.com.ec.domain.dto.ImagemDTO; |
17 | import br.com.ec.domain.dto.ImagemDTO; |
| 18 | import br.com.ec.domain.service.ImagemService; |
18 | import br.com.ec.domain.service.ImagemService; |
| 19 | import br.com.ec.domain.shared.ConstantesSEC; |
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 | 20 | ||
| 24 | @Service |
21 | @Service |
| 25 | public class ImagemServiceImpl extends AbstractService<ImagemDTO> implements ImagemService { |
22 | public class ImagemServiceImpl extends AbstractService<ImagemDTO> implements ImagemService { |
| 26 | 23 | ||
| 27 | @Autowired |
24 | @Autowired |
| Line 74... | Line 71... | ||
| 74 | }
|
71 | }
|
| 75 | 72 | ||
| 76 | /*****************************************/
|
73 | /*****************************************/
|
| 77 | 74 | ||
| 78 | @Override |
75 | @Override |
| 79 | public ImagemDTO uploadImagem(FileUploadEvent e) { |
- | |
| 80 | // ImagemDTO imagemAdicionada = gerarArquivo(e.getFile());
|
- | |
| 81 | // imagemAdicionada.setDescricao("promocoes_" + getEntidade().getVigencia().getSequencial());
|
- | |
| - | 76 | public String retornarCaminhoImagem(String pasta, String nomeArquivo, String extensaoArquivo) { |
|
| - | 77 | File foto = new File(pasta + nomeArquivo + "." + extensaoArquivo); |
|
| - | 78 | return foto.exists()? pasta + nomeArquivo + "." + extensaoArquivo : pasta + "SEM_IMAGEM.png"; |
|
| - | 79 | }
|
|
| - | 80 | ||
| - | 81 | @Override |
|
| - | 82 | public ImagemDTO uploadImagem(UploadedFile e, String nomeArquivo, String caminhoPasta) { |
|
| - | 83 | ImagemDTO imagemAdicionada = gerarArquivo(e, nomeArquivo); |
|
| - | 84 | uploadFisico(imagemAdicionada, caminhoPasta); |
|
| 82 | // lancarExcecaoCasoArquivoExcedeuLimite(imagemAdicionada);
|
85 | // lancarExcecaoCasoArquivoExcedeuLimite(imagemAdicionada);
|
| 83 | // imagemAdicionada.compactarImagem();
|
- | |
| 84 | // imagemAdicionada.converterPngParaJpg();
|
- | |
| 85 | // setImagemParaUpload(e.getFile());
|
- | |
| 86 | // uploadFisico(imagemAdicionada);
|
- | |
| 87 | return null; |
- | |
| - | 86 | // imagemAdicionada.compactarImagem();
|
|
| - | 87 | // imagemAdicionada.converterPngParaJpg();
|
|
| - | 88 | return imagemAdicionada; |
|
| 88 | }
|
89 | }
|
| 89 | 90 | ||
| 90 | public ImagemDTO gerarArquivo(UploadedFile file) { |
- | |
| - | 91 | public ImagemDTO gerarArquivo(UploadedFile file, String nomeArquivo) { |
|
| 91 | ImagemDTO arquivo = new ImagemDTO(); |
92 | ImagemDTO arquivo = new ImagemDTO(); |
| 92 | arquivo.setArquivo(file.getContent()); |
93 | arquivo.setArquivo(file.getContent()); |
| 93 | arquivo.setDescricao(file.getFileName()); |
- | |
| - | 94 | arquivo.setDescricao(nomeArquivo); |
|
| 94 | arquivo.setExtensao(ArquivoUtil.retornarExtensaoDoArquivo(file.getFileName())); |
95 | arquivo.setExtensao(ArquivoUtil.retornarExtensaoDoArquivo(file.getFileName())); |
| 95 | return arquivo; |
96 | return arquivo; |
| - | 97 | }
|
|
| - | 98 | ||
| - | 99 | public void uploadFisico(ImagemDTO arquivoParaUpload, String caminhoPasta) { |
|
| - | 100 | String caminho = caminhoPasta + arquivoParaUpload.getDescricao() + "." + arquivoParaUpload.getExtensao(); |
|
| - | 101 | FileOutputStream fos; |
|
| - | 102 | try { |
|
| - | 103 | fos = new FileOutputStream(caminho); |
|
| - | 104 | fos.write(arquivoParaUpload.getArquivo()); |
|
| - | 105 | fos.close(); |
|
| - | 106 | } catch (Exception e1) { |
|
| - | 107 | e1.printStackTrace(); |
|
| - | 108 | }
|
|
| 96 | }
|
109 | }
|
| 97 | 110 | ||
| 98 | }
|
111 | }
|