Corregido error al validar NIFs duplicados.
Formateo del NIF introducido.
This commit is contained in:
@@ -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() {
|
||||
@@ -244,6 +247,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",
|
||||
|
||||
@@ -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() {
|
||||
@@ -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.
|
||||
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);
|
||||
|
||||
|
||||
@@ -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