From b0f5c69a47e0daf36b938700d3b03518ad2f5fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garcia=20Nu=C3=B1ez?= Date: Mon, 23 Dec 2019 16:23:51 +0100 Subject: [PATCH] Nueva propiedad para guardar el displayName del usuario logeado. --- 1.sources/MyHealth/src/TO/LoggedUserTO.java | 17 ++++++++--- .../systemAdmin/SystemAdminFacadeBean.java | 30 ++++++++----------- .../src/managedbean/common/SessionUtils.java | 12 +++++++- .../profile/UpdateProfileMBean.java | 6 ++-- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/1.sources/MyHealth/src/TO/LoggedUserTO.java b/1.sources/MyHealth/src/TO/LoggedUserTO.java index 0ea7a58..9c80e4c 100644 --- a/1.sources/MyHealth/src/TO/LoggedUserTO.java +++ b/1.sources/MyHealth/src/TO/LoggedUserTO.java @@ -18,20 +18,21 @@ public class LoggedUserTO implements Serializable { private String id; private String password; private String name; + private String displayName; private UserType userType; public LoggedUserTO() { super(); } - - public LoggedUserTO(String usrId, String usrName, String usrPwd, UserType usrType) { + + public LoggedUserTO(String usrId, String usrName, String usrPwd, UserType usrType, String dispName) { id = usrId; name = usrName; password = usrPwd; userType = usrType; - + displayName = dispName; } - + public String getId() { return id; } @@ -64,4 +65,12 @@ public class LoggedUserTO implements Serializable { this.userType = value; } + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + } diff --git a/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java b/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java index 787169a..9112b28 100644 --- a/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java +++ b/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java @@ -33,29 +33,23 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote { CommonFacadeLocal commonServices; /** - * Si la autenticación no es correcgta devuelve null, sino devuelve un POJO con - * datos del usuario logeado. + * Si la autenticación no es correcgta devuelve null, sino devuelve un POJO con datos del usuario logeado. * * La autenticación se realiza en 2 pasos: * * Paso 1. Se intenta localizar un registro de usuario, por orden: * - * a. Primero Paciente, si el identificador comienza por los caracteres - * correctos. + * a. Primero Paciente, si el identificador comienza por los caracteres correctos. * * b.Después médico de familia, si el identificador es de profesional * - * c. Si no lo localizamos buscamos el identificador en la tabla de médicos - * especialistas (el identificador es de profesional) + * c. Si no lo localizamos buscamos el identificador en la tabla de médicos especialistas (el identificador es de profesional) * - * d. Si no hemos localizado aún al usuario, lo buscamos en la tabla de - * administradores, aún cuando el identificador comience por cualquier carácter - * (podría ser una dirección de email que comienza por caracteres del - * identificaodr de paciente o profesional) + * d. Si no hemos localizado aún al usuario, lo buscamos en la tabla de administradores, aún cuando el identificador comience por cualquier carácter (podría ser una dirección + * de email que comienza por caracteres del identificaodr de paciente o profesional) * - * Paso 2. Si hemos localizado un registro de usuario, verificamos si el - * password recibido coincide con el de la base de datos, en tal caso la - * autenticación se compelta y es correcta. + * Paso 2. Si hemos localizado un registro de usuario, verificamos si el password recibido coincide con el de la base de datos, en tal caso la autenticación se compelta y es + * correcta. */ public LoggedUserTO login(String userCode, String pwd) { LoggedUserTO usr = null; @@ -65,7 +59,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote { // login. PatientTO pat = this.commonServices.findPatientByCode(userCode); if (pat != null) { - usr = new LoggedUserTO(String.valueOf(pat.getId()), pat.getName(), pat.getPassword(), UserType.PATIENT); + usr = new LoggedUserTO(String.valueOf(pat.getId()), pat.getName(), pat.getPassword(), UserType.PATIENT, pat.getDisplayName()); } } else if (userCode.startsWith(Constants.PROFESSIONAL_NUMBER_PREFIX)) { // Si el identificador de usuario es de tipo profesional, intentamos realizar el @@ -73,13 +67,13 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote { FamilyDoctorTO fd = this.commonServices.findFamilyDoctorByCode(userCode); if (fd != null) { - usr = new LoggedUserTO(String.valueOf(fd.getId()), fd.getName(), fd.getPassword(), UserType.FAMILY_DOCTOR); + usr = new LoggedUserTO(String.valueOf(fd.getId()), fd.getName(), fd.getPassword(), UserType.FAMILY_DOCTOR, fd.getDisplayName()); } else { // No era un código de médico de familia, intenamos logearlo como especialista SpecialistDoctorTO sd = this.commonServices.findSpecialistDoctorByCode(userCode); if (sd != null) { - usr = new LoggedUserTO(String.valueOf(sd.getId()), sd.getName(), sd.getPassword(), UserType.SPECIALIST_DOCTOR); + usr = new LoggedUserTO(String.valueOf(sd.getId()), sd.getName(), sd.getPassword(), UserType.SPECIALIST_DOCTOR, sd.getDisplayName()); } } } @@ -93,7 +87,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote { AdministratorJPA adm = entman.find(AdministratorJPA.class, userCode); if (adm != null) { - usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRATOR); + usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRATOR, adm.getEmail()); } } @@ -125,7 +119,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote { return this.commonServices.getPOJOforMedicalSpecialtyJPA(ms); } - + @Override public void deleteSpecialtyData(int id, String name, String description) throws Exception { MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, id); diff --git a/1.sources/MyHealth/src/managedbean/common/SessionUtils.java b/1.sources/MyHealth/src/managedbean/common/SessionUtils.java index 3fb14dc..9c3a4c1 100644 --- a/1.sources/MyHealth/src/managedbean/common/SessionUtils.java +++ b/1.sources/MyHealth/src/managedbean/common/SessionUtils.java @@ -24,7 +24,7 @@ public class SessionUtils { else return null; } - + public static HttpSession getSession() { return getSession(false); } @@ -77,6 +77,16 @@ public class SessionUtils { return ""; } + public static String getUserDisplayName() { + HttpSession session = getSession(); + if (session != null && session.getAttribute(SessionUtils.SESSION_VAR_USER) != null) { + LoggedUserTO usr = LoggedUserTO.class.cast(session.getAttribute(SessionUtils.SESSION_VAR_USER)); + + return usr.getDisplayName(); + } else + return ""; + } + public static UserType getUserType() { return getUserType(getSession()); } diff --git a/1.sources/MyHealth/src/managedbean/profile/UpdateProfileMBean.java b/1.sources/MyHealth/src/managedbean/profile/UpdateProfileMBean.java index be48f9c..e0e9b7c 100644 --- a/1.sources/MyHealth/src/managedbean/profile/UpdateProfileMBean.java +++ b/1.sources/MyHealth/src/managedbean/profile/UpdateProfileMBean.java @@ -300,19 +300,19 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable case PATIENT: PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email); this.setPatientData(pat); - usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), this.userType); + usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), this.userType, pat.getDisplayName()); break; case FAMILY_DOCTOR: FamilyDoctorTO fd = this.getRemoteManagerProfile().updateFamilyDoctorData(id, nif, name, surname, password, email, this.primaryHealthCareCenter); this.setFamilyDoctorData(fd); - usr = new LoggedUserTO(fd.getId().toString(), fd.getName(), fd.getPassword(), this.userType); + usr = new LoggedUserTO(fd.getId().toString(), fd.getName(), fd.getPassword(), this.userType, fd.getDisplayName()); break; case SPECIALIST_DOCTOR: SpecialistDoctorTO sd = this.getRemoteManagerProfile().updateSpecialistDoctorData(id, nif, name, surname, password, email, this.medicalSpecialty); this.setSpecialistDoctorData(sd); - usr = new LoggedUserTO(sd.getId().toString(), sd.getName(), sd.getPassword(), this.userType); + usr = new LoggedUserTO(sd.getId().toString(), sd.getName(), sd.getPassword(), this.userType, sd.getDisplayName()); break; case ADMINISTRATOR: