Mejoras en la gestión de excepciones.
This commit is contained in:
@@ -78,38 +78,31 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
||||
|
||||
// Recuperamos el usuario logeado actual
|
||||
LoggedUserTO usr = null;
|
||||
try {
|
||||
usr = SessionUtils.getloggedOnUser();
|
||||
usr = SessionUtils.getloggedOnUser();
|
||||
|
||||
if (usr == null)
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida",
|
||||
"Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
|
||||
else {
|
||||
this.userType = usr.getUserType();
|
||||
this.id = Integer.valueOf(usr.getId());
|
||||
if (usr == null)
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida", "Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
|
||||
else {
|
||||
this.userType = usr.getUserType();
|
||||
this.id = Integer.valueOf(usr.getId());
|
||||
|
||||
switch (usr.getUserType()) {
|
||||
case PATIENT:
|
||||
this.familyDoctorList = this.getRemoteManagerCommon().listFamilyDoctorsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
this.setPatientData(this.getRemoteManagerCommon().findPatientById(this.id));
|
||||
break;
|
||||
case SPECIALIST_DOCTOR:
|
||||
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
this.setSpecialistDoctorData(this.getRemoteManagerCommon().findSpecialistDoctorById(this.id));
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listCAPsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
this.setFamilyDoctorData(this.getRemoteManagerCommon().findFamilyDoctorById(this.id));
|
||||
break;
|
||||
case ADMINISTRATOR:
|
||||
// TODO: Recuperar usuario administrador para editar su perfil ¿?
|
||||
// this.getRemoteManagerProfile().retrievePatient(usr.getId());
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Usuario sin perfil", "Usted es un usuario de tipo administrador y no puede editar su perfil de usuario.");
|
||||
break;
|
||||
}
|
||||
switch (usr.getUserType()) {
|
||||
case PATIENT:
|
||||
this.familyDoctorList = this.getRemoteManagerCommon().listFamilyDoctorsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
this.setPatientData(this.getRemoteManagerCommon().findPatientById(this.id));
|
||||
break;
|
||||
case SPECIALIST_DOCTOR:
|
||||
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
this.setSpecialistDoctorData(this.getRemoteManagerCommon().findSpecialistDoctorById(this.id));
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listCAPsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
this.setFamilyDoctorData(this.getRemoteManagerCommon().findFamilyDoctorById(this.id));
|
||||
break;
|
||||
case ADMINISTRATOR:
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Usuario sin perfil", "Usted es un usuario de tipo administrador y no puede editar su perfil de usuario.");
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,43 +302,47 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
||||
if (this.userType == null)
|
||||
return;
|
||||
|
||||
this.nif = ValidationUtils.normalizeNIF(this.nif);
|
||||
try {
|
||||
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);
|
||||
|
||||
if (this.isUserTypeFamilyDoctor() && this.primaryHealthCareCenter == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado", "Por favor, especifique un centro de atención primaria.");
|
||||
error++;
|
||||
}
|
||||
if (this.isUserTypeSpecialistDoctor() && this.medicalSpecialty == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Especialidad médica no seleccionada", "Por favor, especifique una especialidad médica.");
|
||||
error++;
|
||||
}
|
||||
if (ValidationUtils.isValid(nif) == false) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "El NIF indicado no es válido", "Por favor, especifique un NIF válido.");
|
||||
error++;
|
||||
}
|
||||
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, this.id) == true) {
|
||||
this.addFacesMessage("frmUpdateProfile:nif", FacesMessage.SEVERITY_WARN, "NIF duplicado", "El nif indicado pertenece a otro usuario previamente registrado");
|
||||
error++;
|
||||
}
|
||||
if (changePassword == true) {
|
||||
// el usuario queire cambiar el password Comprobamos que el password
|
||||
// especificado coincide con el guardado
|
||||
if (this.password == null || this.password.length() < 4) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Nueva contraseña incorrectra", "Su nueva contraseña debe tener al menos 4 caracteres.");
|
||||
error++;
|
||||
} else if (HashUtils.hashMD5(this.oldPassword).equals(this.currentPassword) == false) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Contraseña actual incorrecta",
|
||||
"Su actual contraseña es incorrecta. Por favor, especifique su contraseña actual.");
|
||||
if (this.userType == UserType.ADMINISTRATOR) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Perfil de usuario incorrecto", "Su perfil es de un usuario de tipo administrador y no puede editar su perfil.");
|
||||
error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
if (this.isUserTypeFamilyDoctor() && this.primaryHealthCareCenter == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado", "Por favor, especifique un centro de atención primaria.");
|
||||
error++;
|
||||
}
|
||||
if (this.isUserTypeSpecialistDoctor() && this.medicalSpecialty == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Especialidad médica no seleccionada", "Por favor, especifique una especialidad médica.");
|
||||
error++;
|
||||
}
|
||||
if (ValidationUtils.isValid(nif) == false) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "El NIF indicado no es válido", "Por favor, especifique un NIF válido.");
|
||||
error++;
|
||||
}
|
||||
if (ValidationUtils.checkIfNifAlreadyRegistered(this.getRemoteManagerCommon(), this.userType, this.nif, this.id) == true) {
|
||||
this.addFacesMessage("frmUpdateProfile:nif", FacesMessage.SEVERITY_WARN, "NIF duplicado", "El nif indicado pertenece a otro usuario previamente registrado");
|
||||
error++;
|
||||
}
|
||||
if (changePassword == true) {
|
||||
// el usuario queire cambiar el password Comprobamos que el password
|
||||
// especificado coincide con el guardado
|
||||
if (this.password == null || this.password.length() < 4) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Nueva contraseña incorrectra", "Su nueva contraseña debe tener al menos 4 caracteres.");
|
||||
error++;
|
||||
} else if (HashUtils.hashMD5(this.oldPassword).equals(this.currentPassword) == false) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Contraseña actual incorrecta",
|
||||
"Su actual contraseña es incorrecta. Por favor, especifique su contraseña actual.");
|
||||
error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
LoggedUserTO usr = null;
|
||||
|
||||
switch (this.userType) {
|
||||
case PATIENT:
|
||||
PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email);
|
||||
@@ -366,7 +363,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
||||
|
||||
break;
|
||||
case ADMINISTRATOR:
|
||||
throw new NotSupportedException("No se soporta la edición de perfiles de tipo administrador.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (changePassword == true) {
|
||||
@@ -379,9 +376,9 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
|
||||
SessionUtils.createOrUpdateSession(usr);
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de su perfil se han guardado correctamente.");
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
this.manageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user