From 04f66c8cb0ab8edfe8b7f9a0a1e769cf24cbd326 Mon Sep 17 00:00:00 2001 From: valdir Date: Tue, 13 Nov 2018 18:50:21 +0000 Subject: [PATCH] =?UTF-8?q?0012411:=20[BPe]=20-=20[PP0037EC]=20-=20Exigir?= =?UTF-8?q?=20CPF=20com=20valida=C3=A7=C3=A3o=20no=20Call=20Center=20fixes?= =?UTF-8?q?=20bug#12411=20dev:valdevir=20qua:Wallysson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validando o CPF na ADM git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@87024 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../sendaAmigo/EditarClienteController.java | 77 +++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/sendaAmigo/EditarClienteController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/sendaAmigo/EditarClienteController.java index dbee980a4..2c9552341 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/sendaAmigo/EditarClienteController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/sendaAmigo/EditarClienteController.java @@ -9,6 +9,8 @@ import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.brazilutils.br.cpfcnpj.Cpf; +import org.brazilutils.validation.ValidationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -75,6 +77,7 @@ import com.rjconsultores.ventaboletos.web.utilerias.render.RenderCurso; @Scope("prototype") public class EditarClienteController extends MyGenericForwardComposer { + private static final String CPF = "CPF"; private static final long serialVersionUID = 1L; private static Logger log = Logger.getLogger(EditarClienteController.class); @@ -321,7 +324,7 @@ public class EditarClienteController extends MyGenericForwardComposer { cliente = clienteService.obtenerID(cliente.getClienteId()); lsClienteFidelidad = cliente.getListClienteFidelidadActivos(); - if (cliente.getTipoIdentificacionUno() != null && cliente.getTipoIdentificacionUno().getDesctipo().equals("CPF")) { + if (cliente.getTipoIdentificacionUno() != null && cliente.getTipoIdentificacionUno().getDesctipo().equals(CPF)) { txtNumFidelidade.setText(cliente.getNumIdentificaUno().toString()); setValidadoresCPF(); } @@ -489,10 +492,15 @@ public class EditarClienteController extends MyGenericForwardComposer { txtNumRfc.setMaxlength(11); txtNumRfc.setConstraint("/[0-9]{11}/ : " + Labels.getLabel("editarClienteController.MSG.validacaoCPF")); } + + private void setValidadoresCPF2() { + txtNumRfc2.setMaxlength(11); + txtNumRfc2.setConstraint("/[0-9]{11}/ : " + Labels.getLabel("editarClienteController.MSG.validacaoCPF")); + } private TipoIdentificacion getTipoIdentificacionCPF(List tipos) { for (TipoIdentificacion t : tipos) { - if (t.getDesctipo().equals("CPF")) { + if (t.getDesctipo().equals(CPF)) { return t; } } @@ -517,7 +525,7 @@ public class EditarClienteController extends MyGenericForwardComposer { public void onSelect$cmbTipoIdentificacion(Event ev) throws InterruptedException { txtNumRfc.setConstraint(""); txtNumRfc.setValue(""); - if (cmbTipoIdentificacion.getSelectedItem().getValue().toString().equals("CPF")) { + if (cmbTipoIdentificacion.getSelectedItem().getValue().toString().equals(CPF)) { setValidadoresCPF(); } else { txtNumRfc.setMaxlength(20); @@ -526,11 +534,21 @@ public class EditarClienteController extends MyGenericForwardComposer { txtNumFidelidade.setText(""); } } - + + public void onSelect$cmbTipoIdentificacion2(Event ev) throws InterruptedException { + txtNumRfc2.setConstraint(""); + txtNumRfc2.setValue(""); + if (cmbTipoIdentificacion2.getSelectedItem().getValue().toString().equals(CPF)) { + setValidadoresCPF2(); + } else { + txtNumRfc2.setMaxlength(20); + } + } + public void onChange$txtNumRfc(Event ev) throws InterruptedException { if (usaCPFComoFidelidade && cmbTipoIdentificacion.getSelectedItem() != null - && cmbTipoIdentificacion.getSelectedItem().getValue().toString().equals("CPF")) { + && cmbTipoIdentificacion.getSelectedItem().getValue().toString().equals(CPF)) { txtNumFidelidade.setText(txtNumRfc.getText()); } else { txtNumFidelidade.setText(""); @@ -807,6 +825,37 @@ public class EditarClienteController extends MyGenericForwardComposer { cmbMotivacionViaje.getValue(); cmbOcupacion.getValue(); + if (txtNumRfc.getText() != null && !txtNumRfc.getText().isEmpty()) { + if ( cmbTipoIdentificacion != null + && cmbTipoIdentificacion.getSelectedItem() != null + && cmbTipoIdentificacion.getSelectedItem().getValue() != null + && CPF.equals(cmbTipoIdentificacion.getSelectedItem().getValue().toString())) { + String numDoc = txtNumRfc.getText(); + if(!validarCPF(numDoc)) { + Messagebox.show(Labels.getLabel("editarClienteController.MSG.validacaoCPFInvalido"), + Labels.getLabel("editarClienteController.window.title"), Messagebox.OK, + Messagebox.EXCLAMATION); + txtNumRfc.focus(); + return; + } + } + } + + if (txtNumRfc2.getText() != null && !txtNumRfc2.getText().isEmpty()) { + if ( cmbTipoIdentificacion2 != null + && cmbTipoIdentificacion2.getSelectedItem() != null + && cmbTipoIdentificacion2.getSelectedItem().getValue() != null + && CPF.equals(cmbTipoIdentificacion2.getSelectedItem().getValue().toString())) { + String numDoc = txtNumRfc2.getText(); + if(!validarCPF(numDoc)) { + Messagebox.show(Labels.getLabel("editarClienteController.MSG.validacaoCPFInvalido"), + Labels.getLabel("editarClienteController.window.title"), Messagebox.OK, + Messagebox.EXCLAMATION); + txtNumRfc2.focus(); + return; + } + } + } List lsCliente = clienteService.buscarPorDocumento(txtNumRfc.getValue()); if (lsCliente.size() > 1 @@ -904,6 +953,24 @@ public class EditarClienteController extends MyGenericForwardComposer { } } + + /** + * @param numDoc + * @throws InterruptedException + */ + private Boolean validarCPF(String numDoc) { + try { + Cpf cpf = new Cpf(numDoc); + if(!cpf.isValid()) { + return false; + } + } catch (ValidationException e) { + return false; + } + + return true; + } + private List criarFidelidadesTodasEmpresas(List fidelidades, List empresas) { List result = new ArrayList();