fixes bug#21545

qua:
dev:Valdir

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@105385 d1611594-4594-4d17-8e1d-87c2c4800839
master
valdevir 2021-02-18 13:09:16 +00:00
parent 47fedc3e24
commit a80f241be4
4 changed files with 25 additions and 13 deletions

View File

@ -69,7 +69,7 @@ public class ContingenciaClienteRest {
} catch (JSONException e) {
log.error(e);
} catch (IllegalStateException e) {
log.error(e);
log.error("Erro no envio/retorno da requisicao para BPERS", e);
}
return null;
}
@ -89,7 +89,7 @@ public class ContingenciaClienteRest {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK
&& response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
throw new IllegalStateException("Ocorreu um erro na requisição.");
throw new IllegalStateException("Ocorreu um erro na requisição." + response.getStatusLine() !=null ? response.getStatusLine().getReasonPhrase() : "");
}
return getRetornoJSON(response);

View File

@ -2,6 +2,7 @@ package com.rjconsultores.ventaboletos.service;
import java.util.List;
import javax.mail.AuthenticationFailedException;
import javax.mail.SendFailedException;
import com.rjconsultores.ventaboletos.entidad.LogHistoricoContingencia;
@ -11,5 +12,5 @@ public interface ContingenciaService {
public List<LogHistoricoContingencia> buscarHistorico(Integer empresaID, Integer estadoID);
public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException, SendFailedException;
public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException, SendFailedException, AuthenticationFailedException;
}

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import javax.mail.AuthenticationFailedException;
import javax.mail.SendFailedException;
import org.apache.commons.collections.CollectionUtils;
@ -23,7 +24,6 @@ import com.rjconsultores.ventaboletos.enums.EAmbienteContingencia;
import com.rjconsultores.ventaboletos.enums.EStatusContingencia;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.rest.ContingenciaClienteRest;
import com.rjconsultores.ventaboletos.rest.ContingenciaClienteRest.ETipoEnvio;
import com.rjconsultores.ventaboletos.service.ConstanteService;
import com.rjconsultores.ventaboletos.service.ContingenciaService;
import com.rjconsultores.ventaboletos.service.EmpresaEmailConfigService;
@ -60,7 +60,7 @@ public class ContingenciaServiceImpl implements ContingenciaService {
}
@Transactional
public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException{
public LogHistoricoContingencia salvarHistoricoContingencia(LogHistoricoContingencia historicoCont) throws BusinessException, SendFailedException, AuthenticationFailedException{
historicoCont.setUsuario(UsuarioLogado.getUsuarioLogado());
historicoCont.setDataHora(Calendar.getInstance().getTime());
@ -86,18 +86,26 @@ public class ContingenciaServiceImpl implements ContingenciaService {
if (EStatusContingencia.CONTINGENCIA.equals(getStatusContingencia(historicoCont))) {
enviaEmail(historicoCont);
}
} catch (SendFailedException e) {
log.error(String.format("Erro no envio de e-mail de contingência da empresa %s para o estado %s.", historicoCont.getEmpresa().getEmpresaId(),historicoCont.getEstado()),e);
String motivo = historicoCont.getMotivo();
motivo = motivo.concat("**Problema no envio de E-mail de notificação. Favor checar.");
historicoCont.setMotivo(motivo);
} catch (SendFailedException e2 ) {
setMotivoNaoTrocaStatus(historicoCont, e2);
throw e2;
}catch (AuthenticationFailedException e2) {
setMotivoNaoTrocaStatus(historicoCont, e2);
throw e2;
}
return histContingenciaDAO.suscribir(historicoCont);
}
private void setMotivoNaoTrocaStatus(LogHistoricoContingencia historicoCont, Exception e) {
log.error(String.format("Erro no envio de e-mail de contingência da empresa %s para o estado %s.", historicoCont.getEmpresa().getEmpresaId(),historicoCont.getEstado()), e);
String motivo = historicoCont.getMotivo();
motivo = motivo.concat("**Problema no envio de E-mail de notificação. Favor checar.");
historicoCont.setMotivo(motivo);
}
private Integer definirStatusContingencia(LogHistoricoContingencia historicoCont) {
Integer statusEnviado = Integer.valueOf(historicoCont.getStatus());
@ -152,7 +160,7 @@ public class ContingenciaServiceImpl implements ContingenciaService {
return EStatusContingencia.getStatusContingencia(Integer.valueOf(historicoCont.getStatus()));
}
private void enviaEmail(LogHistoricoContingencia historicoCont) throws SendFailedException {
private void enviaEmail(LogHistoricoContingencia historicoCont) throws SendFailedException, AuthenticationFailedException {
SendMail mail = new SendMail();
EmpresaEmail empresaEmail = empresaEmailService.buscarPorEmpresa(historicoCont.getEmpresa());
EmpresaEmailConfig empresaEmailConfig = empresaEmailConfigService.buscarPorEmpresa(historicoCont.getEmpresa());

View File

@ -97,6 +97,9 @@ public class SendMail implements java.io.Serializable {
public void send(TypeContentEmail type) throws SendFailedException {
try {
if(emailTo==null) {
throw new SendFailedException("Email de envio não foi corretamente configurado");
}
String[] to = removeNull(getArrayEnderecoEmail(emailTo));
String[] bcc = removeNull(getArrayEnderecoEmail(emailToCO));