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

@@ -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;
}