Corregido error al validar NIFs duplicados.
Formateo del NIF introducido.
This commit is contained in:
@@ -66,7 +66,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ui-g-4 ui-md-4">
|
<div class="ui-g-4 ui-md-4">
|
||||||
<div class="ui-inputgroup">
|
<div class="ui-inputgroup">
|
||||||
<p:inputText id="nif" value="#{RegisterUser.nif}" validator="nifValidator" maxlength="20" required="true" requiredMessage="Por favor, indque su NIF">
|
<p:inputText id="nif" widgetVar="nif" value="#{RegisterUser.nif}" validator="nifValidator" maxlength="20" required="true" requiredMessage="Por favor, indque su NIF">
|
||||||
<p:ajax event="blur" update="nifmsg" listener="#{RegisterUser.handleNIFValueChange}" oncomplete="handleNIFResponse(xhr, status, args)" />
|
<p:ajax event="blur" update="nifmsg" listener="#{RegisterUser.handleNIFValueChange}" oncomplete="handleNIFResponse(xhr, status, args)" />
|
||||||
</p:inputText>
|
</p:inputText>
|
||||||
<p:commandButton widgetVar="nifButton" icon="pi pi-times" styleClass="red-button" />
|
<p:commandButton widgetVar="nifButton" icon="pi pi-times" styleClass="red-button" />
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ui-g-4 ui-md-4">
|
<div class="ui-g-4 ui-md-4">
|
||||||
<div class="ui-inputgroup">
|
<div class="ui-inputgroup">
|
||||||
<p:inputText id="nif" value="#{UpdateProfile.nif}" validator="nifValidator" maxlength="20" required="true" requiredMessage="Por favor, indque su NIF">
|
<p:inputText id="nif" widgetVar="nif" value="#{UpdateProfile.nif}" validator="nifValidator" maxlength="20" required="true" requiredMessage="Por favor, indque su NIF">
|
||||||
<p:ajax event="blur" update="nifmsg" listener="#{UpdateProfile.handleNIFValueChange}" oncomplete="handleNIFResponse(xhr, status, args)" />
|
<p:ajax event="blur" update="nifmsg" listener="#{UpdateProfile.handleNIFValueChange}" oncomplete="handleNIFResponse(xhr, status, args)" />
|
||||||
</p:inputText>
|
</p:inputText>
|
||||||
<p:commandButton widgetVar="nifButton" icon="pi pi-check" styleClass="green-button" />
|
<p:commandButton widgetVar="nifButton" icon="pi pi-check" styleClass="green-button" />
|
||||||
|
|||||||
@@ -22,20 +22,25 @@ function startLogin() {
|
|||||||
PF('btnLogin').disable();
|
PF('btnLogin').disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valida si un NIF está duplicado.
|
// Actualiza la interfaz tras validar si un nif está duplicado.
|
||||||
function handleNIFResponse(xhr, status, args) {
|
function handleNIFResponse(xhr, status, args) {
|
||||||
var nif = PF('nifButton');
|
if (args.formattedNIF) {
|
||||||
|
var nif = PF('nif');
|
||||||
|
nif.jq.val(args.formattedNIF);
|
||||||
|
}
|
||||||
|
|
||||||
|
var nifButton = PF('nifButton');
|
||||||
if (args.NIFisDupe == false) {
|
if (args.NIFisDupe == false) {
|
||||||
nif.jq.children(".ui-icon").removeClass("pi pi-times");
|
nifButton.jq.children(".ui-icon").removeClass("pi pi-times");
|
||||||
nif.jq.removeClass('red-button');
|
nifButton.jq.removeClass('red-button');
|
||||||
|
|
||||||
nif.jq.children(".ui-icon").addClass("pi pi-check");
|
nifButton.jq.children(".ui-icon").addClass("pi pi-check");
|
||||||
nif.jq.addClass('green-button');
|
nifButton.jq.addClass('green-button');
|
||||||
} else if (nif.jq.hasClass('red-button') == false) {
|
} else if (nifButton.jq.hasClass('red-button') == false) {
|
||||||
nif.jq.children(".ui-icon").removeClass("pi pi-check");
|
nifButton.jq.children(".ui-icon").removeClass("pi pi-check");
|
||||||
nif.jq.removeClass('green-button');
|
nifButton.jq.removeClass('green-button');
|
||||||
|
|
||||||
nif.jq.children(".ui-icon").addClass("pi pi-times");
|
nifButton.jq.children(".ui-icon").addClass("pi pi-times");
|
||||||
nif.jq.addClass('red-button');
|
nifButton.jq.addClass('red-button');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,9 @@ public class ValidationUtils {
|
|||||||
static final String NIF_LETTERS = "TRWAGMYFPDXBNJZSQVHLCKE";
|
static final String NIF_LETTERS = "TRWAGMYFPDXBNJZSQVHLCKE";
|
||||||
static final String NIE_LETTERS = "XYZ";
|
static final String NIE_LETTERS = "XYZ";
|
||||||
|
|
||||||
|
public static String normalizeNIF(String nif) {
|
||||||
|
return nif.toUpperCase().replace("-", "").replace(".", "");
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param nif NIF a validar
|
* @param nif NIF a validar
|
||||||
@@ -24,7 +27,7 @@ public class ValidationUtils {
|
|||||||
if (nif == null)
|
if (nif == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
nif = nif.toUpperCase().replace("-", "").replace(".", "");
|
nif = normalizeNIF(nif);
|
||||||
|
|
||||||
if (nif.length() < 2 || nif.length() > 9)
|
if (nif.length() < 2 || nif.length() > 9)
|
||||||
return false;
|
return false;
|
||||||
@@ -85,9 +88,9 @@ public class ValidationUtils {
|
|||||||
// para los especialistas
|
// para los especialistas
|
||||||
SpecialistDoctorTO sd = remoteSvc.findSpecialistDoctorByNif(nif);
|
SpecialistDoctorTO sd = remoteSvc.findSpecialistDoctorByNif(nif);
|
||||||
|
|
||||||
if (sd != null && (id == null || sd.getId() != id))
|
if (sd != null && (id == null || sd.getId().equals(id) == false))
|
||||||
nifExists = true;
|
nifExists = true;
|
||||||
} else if (id == null || fd.getId() != id)
|
} else if (id == null || fd.getId().equals(id) == false )
|
||||||
// Si se trata de un usuario diferente, entonces está repetido
|
// Si se trata de un usuario diferente, entonces está repetido
|
||||||
nifExists = true;
|
nifExists = true;
|
||||||
|
|
||||||
@@ -96,7 +99,7 @@ public class ValidationUtils {
|
|||||||
PatientTO pat = remoteSvc.findPatientByNif(nif);
|
PatientTO pat = remoteSvc.findPatientByNif(nif);
|
||||||
|
|
||||||
// Si se trata de un usuario diferente, entonces está repetido
|
// Si se trata de un usuario diferente, entonces está repetido
|
||||||
if (pat != null && (id == null || pat.getId() != id))
|
if (pat != null && (id == null || pat.getId().equals(id) == false))
|
||||||
nifExists = true;
|
nifExists = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,12 +163,15 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public void handleNIFValueChange() {
|
public void handleNIFValueChange() {
|
||||||
boolean isDupe = false;
|
boolean isDupe = false;
|
||||||
|
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||||
|
|
||||||
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, null) == true) {
|
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, null) == true) {
|
||||||
isDupe = true;
|
isDupe = true;
|
||||||
this.addFacesMessage("frmRegisterUser:nif", FacesMessage.SEVERITY_WARN, "NIF duplicado", "El nif indicado pertenece a otro usuario previamente registrado");
|
this.addFacesMessage("frmRegisterUser:nif", FacesMessage.SEVERITY_WARN, "NIF duplicado", "El nif indicado pertenece a otro usuario previamente registrado");
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimeFaces.current().ajax().addCallbackParam("NIFisDupe", isDupe);
|
PrimeFaces.current().ajax().addCallbackParam("NIFisDupe", isDupe);
|
||||||
|
PrimeFaces.current().ajax().addCallbackParam("formattedNIF", this.nif);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPatient() {
|
public boolean isPatient() {
|
||||||
@@ -244,6 +247,8 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public void addNewUser() {
|
public void addNewUser() {
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
|
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||||
|
|
||||||
if (this.isFamilyDoctor() && this.primaryHealthCareCenter == null) {
|
if (this.isFamilyDoctor() && this.primaryHealthCareCenter == null) {
|
||||||
this.addFacesMessage("frmRegisterUser:selPHC", FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado",
|
this.addFacesMessage("frmRegisterUser:selPHC", FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado",
|
||||||
|
|||||||
@@ -213,12 +213,15 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
|||||||
*/
|
*/
|
||||||
public void handleNIFValueChange() {
|
public void handleNIFValueChange() {
|
||||||
boolean isDupe = false;
|
boolean isDupe = false;
|
||||||
|
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||||
|
|
||||||
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, this.id) == true) {
|
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, this.id) == true) {
|
||||||
isDupe = true;
|
isDupe = true;
|
||||||
this.addFacesMessage("frmUpdateProfile:nif", FacesMessage.SEVERITY_WARN, "NIF duplicado", "El nif indicado pertenece a otro usuario previamente registrado");
|
this.addFacesMessage("frmUpdateProfile:nif", FacesMessage.SEVERITY_WARN, "NIF duplicado", "El nif indicado pertenece a otro usuario previamente registrado");
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimeFaces.current().ajax().addCallbackParam("NIFisDupe", isDupe);
|
PrimeFaces.current().ajax().addCallbackParam("NIFisDupe", isDupe);
|
||||||
|
PrimeFaces.current().ajax().addCallbackParam("formattedNIF", this.nif);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FamilyDoctorTO> getFamilyDoctorList() {
|
public List<FamilyDoctorTO> getFamilyDoctorList() {
|
||||||
@@ -318,6 +321,8 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
|||||||
// Si no hay tipo de usuario, es que algo raro ha pasado (sesión caducada?). salimos.
|
// Si no hay tipo de usuario, es que algo raro ha pasado (sesión caducada?). salimos.
|
||||||
if (this.userType == null)
|
if (this.userType == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||||
|
|
||||||
boolean changePassword = (this.oldPassword != null && this.oldPassword.equals("") == false) || (this.password != null && this.password.equals("") == false);
|
boolean changePassword = (this.oldPassword != null && this.oldPassword.equals("") == false) || (this.password != null && this.password.equals("") == false);
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ public class NifValidator implements Validator<String>, ClientValidator {
|
|||||||
strValue = String.valueOf(value);
|
strValue = String.valueOf(value);
|
||||||
|
|
||||||
if (strValue.equals(""))
|
if (strValue.equals(""))
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "El NIF no es válido", "El NIF " + value + " no es válido"));
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "El NIF no es válido", "El NIF " + strValue + " no es válido"));
|
||||||
|
|
||||||
|
strValue = ValidationUtils.normalizeNIF(strValue);
|
||||||
if (ValidationUtils.isValid(strValue) == false)
|
if (ValidationUtils.isValid(strValue) == false)
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "El NIF no es válido", "El NIF " + value + " no es válido"));
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "El NIF no es válido", "El NIF " + strValue + " no es válido"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getMetadata() {
|
public Map<String, Object> getMetadata() {
|
||||||
|
|||||||
Reference in New Issue
Block a user