Añadir usuario admin

This commit is contained in:
dalvarezgon
2020-01-01 12:02:37 +01:00
parent 4d6aedd863
commit 91faac6b63
10 changed files with 212 additions and 7 deletions

View File

@@ -19,11 +19,33 @@ import javax.xml.bind.annotation.XmlRootElement;
public class SystemAdminTO implements Serializable {
private static final long serialVersionUID = 1L;
private String email;
private String password;
public SystemAdminTO() {
super();
}
public SystemAdminTO(String email, String password) {
this.email = email;
this.setPassword(password);
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@@ -15,6 +15,7 @@ import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.QuestionTO;
import TO.SpecialistDoctorTO;
import TO.SystemAdminTO;
import TO.VisitTO;
import common.Utils;
import jpa.FamilyDoctorJPA;
@@ -24,6 +25,7 @@ import jpa.PatientJPA;
import jpa.PrimaryHealthCareCenterJPA;
import jpa.QuestionJPA;
import jpa.SpecialistDoctorJPA;
import jpa.SystemAdminJPA;
import jpa.VisitJPA;
/***
@@ -637,4 +639,15 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
return qsTO;
}
@Override
public SystemAdminTO getPOJOforSystemAdminJPA(SystemAdminJPA admin) {
SystemAdminTO adminTO = null;
if (admin != null) {
adminTO = new SystemAdminTO(admin.getEmail(), admin.getPassword());
}
return adminTO;
}
}

View File

@@ -11,7 +11,9 @@ import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.QuestionTO;
import TO.SpecialistDoctorTO;
import TO.SystemAdminTO;
import TO.VisitTO;
import jpa.SystemAdminJPA;
import jpa.FamilyDoctorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.MedicalTestJPA;
@@ -84,4 +86,6 @@ public interface CommonFacadeLocal {
public MedicalTestTO getPOJOforMedicalTestJPA(MedicalTestJPA mt, int nestedProps);
public VisitTO getPOJOforVisitJPA(VisitJPA qs, int nestedProps);
public SystemAdminTO getPOJOforSystemAdminJPA(SystemAdminJPA admin);
}

View File

@@ -15,11 +15,12 @@ import TO.MedicalSpecialtyTO;
import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.SpecialistDoctorTO;
import TO.SystemAdminTO;
import common.Constants;
import common.HashUtils;
import common.UserType;
import ejb.common.CommonFacadeLocal;
import jpa.AdministratorJPA;
import jpa.SystemAdminJPA;
import jpa.FamilyDoctorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.PrimaryHealthCareCenterJPA;
@@ -91,7 +92,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
// cual intentamos login contra la tabla de administradores
if (usr == null) {
// Intentamos recuperar un registro de administrador
AdministratorJPA adm = entman.find(AdministratorJPA.class, userCode);
SystemAdminJPA adm = entman.find(SystemAdminJPA.class, userCode);
if (adm != null) {
usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRATOR, adm.getEmail());
@@ -174,6 +175,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(ms);
}
@Override
public PrimaryHealthCareCenterTO findHealthCareCenterByName(String searchedName) {
TypedQuery<PrimaryHealthCareCenterJPA> query = entman.createQuery("from PrimaryHealthCareCenterJPA cap where cap.name=:name", PrimaryHealthCareCenterJPA.class);
query.setMaxResults(1);
@@ -205,12 +207,14 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(cap);
}
@Override
public Long getCAPCount() {
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from PrimaryHealthCareCenterJPA", Long.class);
return query.getSingleResult();
}
@Override
public List<PrimaryHealthCareCenterTO> listCAPsPaged(int pageNumber, int pageSize) {
TypedQuery<PrimaryHealthCareCenterJPA> query = entman.createQuery("SELECT c from PrimaryHealthCareCenterJPA c order by c.name", PrimaryHealthCareCenterJPA.class);
@@ -229,6 +233,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
return caps;
}
@Override
public List<FamilyDoctorTO> listAllFamilyDoctorsByCAPPaged(int primaryHealthCareCenterId, int pageNumber, int pageSize) {
List<FamilyDoctorTO> familyDoctorsByCAP = new ArrayList<FamilyDoctorTO>();
@@ -250,10 +255,32 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
return familyDoctorsByCAP;
}
@Override
public Long getPatientCount(int familyDoctorId) {
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from PatientJPA p where p.familyDoctor.id=:familyDoctorId", Long.class);
query.setParameter("familyDoctorId", familyDoctorId);
return query.getSingleResult();
}
@Override
public SystemAdminTO findAdminByEmail(String email) {
TypedQuery<SystemAdminJPA> query = entman.createQuery("from SystemAdminJPA a where a.email=:email", SystemAdminJPA.class);
query.setMaxResults(1);
query.setParameter("email", email);
List<SystemAdminJPA> results = query.getResultList();
if (results.size() > 0)
return this.commonServices.getPOJOforSystemAdminJPA(results.get(0));
else
return null;
}
@Override
public SystemAdminTO insertAdmin(String email, String password) throws Exception {
SystemAdminJPA admin = new SystemAdminJPA(email, password);
entman.persist(admin);
return this.commonServices.getPOJOforSystemAdminJPA(admin);
}
}

View File

@@ -8,6 +8,7 @@ import TO.FamilyDoctorTO;
import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import TO.PrimaryHealthCareCenterTO;
import TO.SystemAdminTO;
/**
*
@@ -45,4 +46,8 @@ public interface SystemAdminFacadeRemote {
public List<FamilyDoctorTO> listAllFamilyDoctorsByCAPPaged(int primaryHealthCareCenterId, int pageNumber, int pageSize);
public Long getPatientCount(int familyDoctorId);
public SystemAdminTO findAdminByEmail(String email);
public SystemAdminTO insertAdmin(String email, String password) throws Exception;
}

View File

@@ -13,7 +13,7 @@ import javax.persistence.Table;
*/
@Entity
@Table(name = "MyHealth.Administrator")
public class AdministratorJPA implements Serializable {
public class SystemAdminJPA implements Serializable {
private static final long serialVersionUID = 1L;
@@ -24,11 +24,11 @@ public class AdministratorJPA implements Serializable {
/**
* Class constructor methods
*/
public AdministratorJPA() {
public SystemAdminJPA() {
super();
}
public AdministratorJPA(String email, String password) {
public SystemAdminJPA(String email, String password) {
this.email = email;
this.password = password;
}

View File

@@ -109,6 +109,8 @@ public class AuthorizationFilter implements Filter {
authorized = true;
if (reqURI.indexOf("/systemAdmin/ListDoctorsByCenter") > 0)
authorized = true;
if (reqURI.indexOf("/systemAdmin/AddAdmin") > 0)
authorized = true;
if (reqURI.indexOf("/visit/PatientVisitList") > 0)
authorized = true;
if (reqURI.indexOf("/visit/UpdateVisit") > 0)

View File

@@ -46,7 +46,7 @@ public class MenuMBean implements Serializable {
subMenu.addElement(new DefaultSeparator());
subMenu.addElement(createMenuItem("Ver médicos de un CAP", "fa fa-medkit", "/systemAdmin/ListDoctorsByCenter", null));
subMenu.addElement(new DefaultSeparator());
subMenu.addElement(createMenuItem("Añadir usuario Admin", "fa fa-user-secret", "/systemAdmin/ManageSpecialties", null));
subMenu.addElement(createMenuItem("Añadir usuario Admin", "fa fa-user-secret", "/systemAdmin/AddAdmin", null));
model.addElement(subMenu);
}

View File

@@ -0,0 +1,79 @@
package managedbean.systemAdmin;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.inject.Named;
import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import common.HashUtils;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@Named("AddAdmin")
@RequestScoped
public class AddAdminMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private String email;
private String password;
public AddAdminMBean() {
}
@PostConstruct
public void init() {
// Recuperamos el usuario logeado actual
LoggedUserTO usr = null;
try {
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.");
}
} catch (Exception e) {
this.manageException(e);
}
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void insertData() {
int error = 0;
if (this.getRemoteManagerSystemAdmin().findAdminByEmail(email) != null) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Administrador ya existente", "El administrador ya se encuentra dado de alta");
error++;
}
if (error == 0) {
try {
this.getRemoteManagerSystemAdmin().insertAdmin(email, HashUtils.hashMD5(password));
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "El administrador se ha dado de alta", "Los datos del administrador se han guardado correctamente.");
} catch (Exception e) {
this.manageException(e);
}
}
}
}