Corregido error al validar NIFs duplicados.
Formateo del NIF introducido.
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
</div>
|
||||
<div class="ui-g-4 ui-md-4">
|
||||
<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:inputText>
|
||||
<p:commandButton widgetVar="nifButton" icon="pi pi-times" styleClass="red-button" />
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
</div>
|
||||
<div class="ui-g-4 ui-md-4">
|
||||
<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:inputText>
|
||||
<p:commandButton widgetVar="nifButton" icon="pi pi-check" styleClass="green-button" />
|
||||
|
||||
@@ -22,20 +22,25 @@ function startLogin() {
|
||||
PF('btnLogin').disable();
|
||||
}
|
||||
|
||||
// Valida si un NIF está duplicado.
|
||||
// Actualiza la interfaz tras validar si un nif está duplicado.
|
||||
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) {
|
||||
nif.jq.children(".ui-icon").removeClass("pi pi-times");
|
||||
nif.jq.removeClass('red-button');
|
||||
nifButton.jq.children(".ui-icon").removeClass("pi pi-times");
|
||||
nifButton.jq.removeClass('red-button');
|
||||
|
||||
nif.jq.children(".ui-icon").addClass("pi pi-check");
|
||||
nif.jq.addClass('green-button');
|
||||
} else if (nif.jq.hasClass('red-button') == false) {
|
||||
nif.jq.children(".ui-icon").removeClass("pi pi-check");
|
||||
nif.jq.removeClass('green-button');
|
||||
nifButton.jq.children(".ui-icon").addClass("pi pi-check");
|
||||
nifButton.jq.addClass('green-button');
|
||||
} else if (nifButton.jq.hasClass('red-button') == false) {
|
||||
nifButton.jq.children(".ui-icon").removeClass("pi pi-check");
|
||||
nifButton.jq.removeClass('green-button');
|
||||
|
||||
nif.jq.children(".ui-icon").addClass("pi pi-times");
|
||||
nif.jq.addClass('red-button');
|
||||
nifButton.jq.children(".ui-icon").addClass("pi pi-times");
|
||||
nifButton.jq.addClass('red-button');
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@ public class ValidationUtils {
|
||||
static final String NIF_LETTERS = "TRWAGMYFPDXBNJZSQVHLCKE";
|
||||
static final String NIE_LETTERS = "XYZ";
|
||||
|
||||
public static String normalizeNIF(String nif) {
|
||||
return nif.toUpperCase().replace("-", "").replace(".", "");
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param nif NIF a validar
|
||||
@@ -24,7 +27,7 @@ public class ValidationUtils {
|
||||
if (nif == null)
|
||||
return false;
|
||||
|
||||
nif = nif.toUpperCase().replace("-", "").replace(".", "");
|
||||
nif = normalizeNIF(nif);
|
||||
|
||||
if (nif.length() < 2 || nif.length() > 9)
|
||||
return false;
|
||||
@@ -85,9 +88,9 @@ public class ValidationUtils {
|
||||
// para los especialistas
|
||||
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;
|
||||
} 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
|
||||
nifExists = true;
|
||||
|
||||
@@ -96,7 +99,7 @@ public class ValidationUtils {
|
||||
PatientTO pat = remoteSvc.findPatientByNif(nif);
|
||||
|
||||
// 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;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -163,12 +163,15 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
|
||||
*/
|
||||
public void handleNIFValueChange() {
|
||||
boolean isDupe = false;
|
||||
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||
|
||||
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, null) == true) {
|
||||
isDupe = true;
|
||||
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("formattedNIF", this.nif);
|
||||
}
|
||||
|
||||
public boolean isPatient() {
|
||||
@@ -245,6 +248,8 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
|
||||
public void addNewUser() {
|
||||
int error = 0;
|
||||
|
||||
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||
|
||||
if (this.isFamilyDoctor() && this.primaryHealthCareCenter == null) {
|
||||
this.addFacesMessage("frmRegisterUser:selPHC", FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado",
|
||||
"Por favor, especifique un centro de atención primaria.");
|
||||
|
||||
@@ -213,12 +213,15 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
||||
*/
|
||||
public void handleNIFValueChange() {
|
||||
boolean isDupe = false;
|
||||
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||
|
||||
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, this.id) == true) {
|
||||
isDupe = true;
|
||||
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("formattedNIF", this.nif);
|
||||
}
|
||||
|
||||
public List<FamilyDoctorTO> getFamilyDoctorList() {
|
||||
@@ -319,6 +322,8 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
||||
if (this.userType == null)
|
||||
return;
|
||||
|
||||
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||
|
||||
boolean changePassword = (this.oldPassword != null && this.oldPassword.equals("") == false) || (this.password != null && this.password.equals("") == false);
|
||||
|
||||
if (this.isUserTypeFamilyDoctor() && this.primaryHealthCareCenter == null) {
|
||||
|
||||
@@ -23,10 +23,11 @@ public class NifValidator implements Validator<String>, ClientValidator {
|
||||
strValue = String.valueOf(value);
|
||||
|
||||
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)
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user