valdevir 2016-09-29 19:49:31 +00:00
parent 5a42085280
commit 60c232f973
1 changed files with 56 additions and 54 deletions

View File

@ -86,24 +86,24 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
if (entidad.getIndIntegracion() == null || (entidad.getIndIntegracion().equals(TipoRetorno.PENDENTE.getValor())
|| entidad.getIndIntegracion().equals(TipoRetorno.ERRO.getValor()))) {
String resp = integracionTotvs(entidad);
TipoRetorno retornoTotvs = RetornoTotvs.validaRetornoTotvs(resp);
switch (retornoTotvs) {
case CONCLUIDA:
entidad.setIndIntegracion(TipoRetorno.CONCLUIDA.getValor());
break;
case JA_CADASTRADA:
entidad.setIndIntegracion(TipoRetorno.JA_CADASTRADA.getValor());
respEx = new IntegracionException(Atributos.MSG_ERRO_JA_CADASTRADO);
break;
case ERRO:
entidad.setIndIntegracion(TipoRetorno.ERRO.getValor());
respEx = new IntegracionException(Atributos.MSG_ERRO_GENERICA + resp);
break;
default:
break;
}
@ -113,22 +113,22 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
} catch (ValidacionCampoException ev) {
entidad.setIndIntegracion(TipoRetorno.ERRO.getValor());
respEx = ev;
} catch (Exception e) {
entidad.setIndIntegracion(TipoRetorno.ERRO.getValor());
log.error(Atributos.MSG_ERRO_GENERICA, e);
respEx = new IntegracionException(Atributos.MSG_ERRO_GENERICA + e.getMessage());
}
}
entidad = puntoVentaDAO.suscribir(entidad);
if (respEx != null) {
if (respEx instanceof IntegracionException) {
throw (IntegracionException) respEx;
} else if (respEx instanceof ValidacionCampoException) {
if (respEx instanceof ValidacionCampoException) {
throw (ValidacionCampoException) respEx;
} else if (respEx instanceof IntegracionException) {
entidad = puntoVentaDAO.suscribir(entidad);
throw (IntegracionException) respEx;
}
}
entidad = puntoVentaDAO.suscribir(entidad);
return entidad;
}
@ -138,33 +138,33 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.TRUE);
Exception respEx = null;
if (ApplicationProperties.getInstance().integracionTotvs()) {
try {
if (entidad.getIndIntegracion() == null || (entidad.getIndIntegracion().equals(TipoRetorno.PENDENTE.getValor())
|| entidad.getIndIntegracion().equals(TipoRetorno.ERRO.getValor()))) {
String resp = integracionTotvs(entidad);
TipoRetorno retornoTotvs = RetornoTotvs.validaRetornoTotvs(resp);
switch (retornoTotvs) {
case CONCLUIDA:
entidad.setIndIntegracion(TipoRetorno.CONCLUIDA.getValor());
break;
case JA_CADASTRADA:
entidad.setIndIntegracion(TipoRetorno.JA_CADASTRADA.getValor());
respEx = new IntegracionException(Atributos.MSG_ERRO_JA_CADASTRADO);
break;
case ERRO:
entidad.setIndIntegracion(TipoRetorno.ERRO.getValor());
respEx = new IntegracionException(Atributos.MSG_ERRO_GENERICA + resp);
break;
default:
break;
}
@ -174,7 +174,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
} catch (ValidacionCampoException e) {
entidad.setIndIntegracion(TipoRetorno.ERRO.getValor());
respEx = e;
} catch (Exception e) {
entidad.setIndIntegracion(TipoRetorno.ERRO.getValor());
log.error(Atributos.MSG_ERRO_GENERICA, e);
@ -194,22 +194,22 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
return entidad;
}
private boolean tienesEstacionEnPuntoVta(PuntoVenta entidad) {
List<Estacion> lsEstaciones = estacionService.buscarEstaciones(entidad);
if(lsEstaciones != null && lsEstaciones.size() > 0 ){
if (lsEstaciones != null && lsEstaciones.size() > 0) {
return true;
}
return false;
}
@Transactional
public void borrar(PuntoVenta entidad) throws BusinessException{
public void borrar(PuntoVenta entidad) throws BusinessException {
if(tienesEstacionEnPuntoVta(entidad)){
if (tienesEstacionEnPuntoVta(entidad)) {
throw new BusinessException("editarPuntoVentaController.MSG.estacionVinculadaAgenciaOnDelete");
}
for (FormaPagoDet forma : entidad.getLsFormaPagoDet()) {
forma.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
forma.setFecmodif(Calendar.getInstance().getTime());
@ -286,25 +286,25 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
if (puntoVenta.getNumDoCPuntoVenta() == null) {
throw new ValidacionCampoException("editarPuntoVentaController.erro.numDoCPuntoVenta");
}
String cpfOrCnpj = puntoVenta.getNumDoCPuntoVenta().replaceAll("[^0-9.]", "");
if (!CpfCnpj.isValid(cpfOrCnpj)){
if (!CpfCnpj.isValid(cpfOrCnpj)) {
throw new ValidacionCampoException("editarPuntoVentaController.erro.cpfCnpj");
}
if (puntoVenta.getNumIEPuntoVenta() == null) {
throw new ValidacionCampoException("editarPuntoVentaController.erro.numIEPuntoVenta");
}
if (puntoVenta.getColonia() == null) {
throw new ValidacionCampoException("editarPuntoVentaController.erro.colonia");
}
if (puntoVenta.getCodpostal() == null) {
throw new ValidacionCampoException("editarPuntoVentaController.erro.cep");
}
if (puntoVenta.getDireccioncalle() == null) {
throw new ValidacionCampoException("editarPuntoVentaController.erro.calle");
}
@ -347,15 +347,15 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
String nome = puntoVenta.getNombpuntoventa();
nome = removerAcentosCaracteresEspeciaisTotvs(nome);
String cgc = puntoVenta.getNumDoCPuntoVenta();
String endereco = puntoVenta.getDireccioncalle() + "," + ((puntoVenta.getDireccionnumero() == null) ? "" : puntoVenta.getDireccionnumero());
endereco = removerAcentosCaracteresEspeciaisTotvs(endereco);
String complemen = puntoVenta.getCompl() == null ? "" : puntoVenta.getCompl();
complemen = removerAcentosCaracteresEspeciaisTotvs(complemen);
String bairro = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getDesccolonia();
bairro = removerAcentosCaracteresEspeciaisTotvs(bairro);
@ -365,7 +365,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
String est = puntoVenta.getColonia() == null ? null : puntoVenta.getColonia().getCiudad().getEstado().getCveestado();
String codpais = CodPaisBanco.BRASIL.getValor();
String cep = puntoVenta.getCodpostal() != null?puntoVenta.getCodpostal().toString():null;
String cep = puntoVenta.getCodpostal() != null ? puntoVenta.getCodpostal().toString() : null;
String tel = puntoVenta.getNumtelefonouno();
String ddd = null;
@ -379,7 +379,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
String email = puntoVenta.getDescCorreo() == null ? "" : puntoVenta.getDescCorreo();
email = removerCaracteresInvalidosXml(email);
String fax = puntoVenta.getNumfax() == null ? "" : puntoVenta.getNumfax();
String inscr = puntoVenta.getNumIEPuntoVenta();
String inscrm = InscricaoMunicipal.ISENTO.name();
@ -484,29 +484,31 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
vlr = somenteNumeros(vlr);
return vlr.length() > 11;
}
/**
* From xml spec valid chars:<br>
* #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]<br>
* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.<br>
*
* link artigo:http://stackoverflow.com/questions/9710185/how-to-deal-with-invalid-characters-in-a-ws-output-when-using-cxf
*
* @param text The String to clean
* @param replacement The string to be substituted for each match
* @return The resulting String
*/
private String removerCaracteresInvalidosXml(String s){
if (s == null){
* From xml spec valid chars:<br>
* #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]<br>
* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.<br>
*
* link artigo:http://stackoverflow.com/questions/9710185/how-to-deal-with-invalid-characters-in-a-ws-output-when-using-cxf
*
* @param text
* The String to clean
* @param replacement
* The string to be substituted for each match
* @return The resulting String
*/
private String removerCaracteresInvalidosXml(String s) {
if (s == null) {
return s;
}
String re = "[^\\x09\\x0A\\x0D\\x20-\\xD7FF\\xE000-\\xFFFD\\x10000-x10FFFF]";
return s.replaceAll(re, "");
return s.replaceAll(re, "");
}
private String removerAcentosCaracteresEspeciaisTotvs(String s){
if (StringUtils.isBlank(s)){
private String removerAcentosCaracteresEspeciaisTotvs(String s) {
if (StringUtils.isBlank(s)) {
return s;
}
s = StringUtils.trim(s);