Cambios varios para login de usuario

* Login de diferentes usuarios completado.
* Cambiado esquema de BBDD, campos texto a character varying.
* Cambiada relación entre paciente y medico de cabecera.
* Movida clase UserType a paquete common ya que se utiliza en el EJB.
* Datos de prueba para realizar logins, el password es admin para todos
(hashMD5).
This commit is contained in:
Marcos Garcia Nuñez
2019-12-06 02:17:07 +01:00
parent 32ce0a7eb6
commit 547af98a78
12 changed files with 192 additions and 159 deletions

View File

@@ -12,20 +12,17 @@ import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import TO.PrimaryHealthCareCenterTO;
import common.HashUtils;
import common.UserType;
import jpa.AdministratorJPA;
import jpa.FamilyDoctorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.PatientJPA;
import jpa.PrimaryHealthCareCenterJPA;
import jpa.SpecialistDoctorJPA;
import managedbean.common.UserType;
/**
* EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los
* métodos de la capa de negocio que implementan la logica de negocio y la
* interacción con la capa de persistencia.
*
* @author mark
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Stateless
@@ -97,27 +94,37 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
// First try to login as Admin
AdministratorJPA adm = entman.find(AdministratorJPA.class, id);
if (adm != null) {
usr = new LoggedUserTO(adm.getEmail(), "", adm.getPassword(), UserType.ADMINISTRADOR);
usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRADOR);
} else {
Integer iId = Integer.valueOf(id);
// Try to login Patient
PatientJPA pat = entman.find(PatientJPA.class, iId);
try {
int iId = Integer.parseInt(id);
if (pat != null) {
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), UserType.PATIENT);
} else {
FamilyDoctorJPA fdoc = entman.find(FamilyDoctorJPA.class, iId);
// Try to login Patient, FamilyDoctor or SpecialistDoctor
// TODO: Si Patient, FamilyDoctor o Specialist Doctor tienen el mismo id, solo
// el paciente se puede logear. ¿Deberíamos cambiar esto permitiendo seleccionar
// el perfil a logearse?
PatientJPA pat = entman.find(PatientJPA.class, iId);
if (fdoc != null) {
usr = new LoggedUserTO(fdoc.getId().toString(), fdoc.getName(), fdoc.getPassword(), UserType.FAMILY_DOCTOR);
if (pat != null) {
usr = new LoggedUserTO(String.valueOf(pat.getId()), pat.getName(), pat.getPassword(), UserType.PATIENT);
} else {
SpecialistDoctorJPA sdoc = entman.find(SpecialistDoctorJPA.class, iId);
FamilyDoctorJPA fdoc = entman.find(FamilyDoctorJPA.class, iId);
if (sdoc != null) {
usr = new LoggedUserTO(sdoc.getId().toString(), sdoc.getName(), sdoc.getPassword(), UserType.SPECIALIST_DOCTOR);
if (fdoc != null) {
usr = new LoggedUserTO(String.valueOf(fdoc.getId()), fdoc.getName(), fdoc.getPassword(), UserType.FAMILY_DOCTOR);
} else {
SpecialistDoctorJPA sdoc = entman.find(SpecialistDoctorJPA.class, iId);
if (sdoc != null) {
usr = new LoggedUserTO(String.valueOf(sdoc.getId()), sdoc.getName(), sdoc.getPassword(), UserType.SPECIALIST_DOCTOR);
}
}
}
} catch (NumberFormatException nf) {
// id is not an intenger, so, login fails
usr = null;
}
}
if (usr != null) {

View File

@@ -9,10 +9,8 @@ import TO.PrimaryHealthCareCenterTO;
import TO.LoggedUserTO;
/**
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para
* los clientes del EJB
*
* @author mark
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Remote
@@ -21,6 +19,8 @@ public interface SystemAdminFacadeRemote {
* Definimos la interfaz remota
*/
public Collection<MedicalSpecialtyTO> listAllMedicalSpecialities();
public Collection<PrimaryHealthCareCenterTO> listAllCAPs();
public LoggedUserTO login(String id, String pwd);
}