Clase base para todos los managedBeans con soporte para mensajes JSF,

conexión a los FacadeRemote de los EJB.
Mejoras en el login de usuario.
Corregido problema en registro de usuario.
This commit is contained in:
Marcos Garcia Nuñez
2019-12-08 16:56:06 +01:00
parent 1dff77f32a
commit 54cc9da998
19 changed files with 264 additions and 146 deletions

View File

@@ -8,6 +8,8 @@ import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.naming.Context;
@@ -24,6 +26,7 @@ import TO.PrimaryHealthCareCenterTO;
import TO.SpecialistDoctorTO;
import common.UserType;
import ejb.systemAdmin.SystemAdminFacadeRemote;
import managedbean.common.ManagedBeanBase;
import managedbean.common.ValidationUtils;
/**
@@ -35,17 +38,19 @@ import managedbean.common.ValidationUtils;
*/
@Named("registerUser")
@ViewScoped
public class RegisterUserMBean extends ProfileMBeanBase implements Serializable {
public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private int id;
private String nif;
private String name;
private String surname;
private String password;
private String passwordRepeat;
private String email;
private boolean registered;
// private HashMap<String, String> userTypes;
private List<UserType> userTypes;
private String userType;
@@ -59,8 +64,8 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
*
* @throws Exception
*/
public RegisterUserMBean() throws Exception {
super.initializeProfileFacadeRemote();
public RegisterUserMBean() {
}
@PostConstruct
@@ -69,20 +74,12 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
this.userTypes.add(UserType.PATIENT);
this.userTypes.add(UserType.FAMILY_DOCTOR);
this.userTypes.add(UserType.SPECIALIST_DOCTOR);
this.registered = false;
this.userType = UserType.PATIENT.name();
Properties props = System.getProperties();
Context ctx;
try {
ctx = new InitialContext(props);
SystemAdminFacadeRemote rman = (SystemAdminFacadeRemote) ctx.lookup("java:app/MyHealth.jar/SystemAdminFacadeBean!ejb.systemAdmin.SystemAdminFacadeRemote");
this.medicalSpecialitiesList = rman.listAllMedicalSpecialities();
this.primaryHealthCareCentersList = rman.listAllCAPs();
} catch (NamingException e) {
this.manageException(e);
}
this.medicalSpecialitiesList = this.getRemoteManagerSystemAdmin().listAllMedicalSpecialities();
this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs();
}
public List<UserType> getUserTypes() {
@@ -115,19 +112,10 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
public Collection<MedicalSpecialtyTO> getMedicalSpecialtiesList() {
return medicalSpecialitiesList;
}
// public void setMedicalSpecialtiesList(Collection<MedicalSpecialtyTO> list) {
// medicalSpecialitiesList = list;
// }
public Collection<PrimaryHealthCareCenterTO> getPhcList() {
return primaryHealthCareCentersList;
}
// public void setPhcList(Collection<PrimaryHealthCareCenterTO> list) {
// primaryHealthCareCentersList = list;
// }
public boolean isPatient() {
return (UserType.valueOf(this.userType) == UserType.PATIENT);
}
@@ -143,7 +131,7 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
public boolean isDoctor() {
return (isFamilyDoctor() || isSpecialistDoctor());
}
public String getEmail() {
return email;
}
@@ -191,8 +179,8 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
public void setId(int id) {
this.id = id;
}
public String addNewUser() {
public void addNewUser() {
int error = 0;
if (this.isFamilyDoctor() && this.primaryHealthCareCenter == null) {
@@ -212,34 +200,31 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
try {
switch (UserType.valueOf(this.userType)) {
case PATIENT:
PatientTO pat = this.remoteManager.registerPatient(id, nif, name, surname, password, email);
PatientTO pat = this.getRemoteManagerProfile().registerPatient(id, nif, name, surname, password, email);
this.id = pat.getId();
break;
case FAMILY_DOCTOR:
FamilyDoctorTO fd = this.remoteManager.registerFamilyDoctor1(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
FamilyDoctorTO fd = this.getRemoteManagerProfile().registerFamilyDoctor1(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
this.id = fd.getId();
break;
case SPECIALIST_DOCTOR:
SpecialistDoctorTO sd = this.remoteManager.registerSpecialistDoctor(id, nif, name, surname, password, email, this.medicalSpecialty);
SpecialistDoctorTO sd = this.getRemoteManagerProfile().registerSpecialistDoctor(id, nif, name, surname, password, email, this.medicalSpecialty);
this.id = sd.getId();
break;
case ADMINISTRADOR:
throw new NotSupportedException("No se soporta el registro directo de administradores.");
}
this.registered = true;
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Registro realizado", "El usuario " + name + " " + surname + " se ha registrado correctamente.");
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Registro realizado",
"El usuario " + name + " " + surname + " se ha registrado correctamente. Por favor, comprueba su correo electrónico para verificar su cuenta.");
return "RegisterUserResult";
} catch (Exception e) {
this.manageException(e);
}
}
return "";
}
public String getPasswordRepeat() {
@@ -274,4 +259,8 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
this.primaryHealthCareCenter = primaryHealthCareCenter;
}
public boolean isRegistered() {
return registered;
}
}