Ejemplo de paginación (Listado de preguntas pendientes) con primefaces

utilizando LazyDataModel, con recarga automática de la página
solicitada.
This commit is contained in:
Marcos Garcia Nuñez
2019-12-16 22:02:27 +01:00
parent dcbebe5253
commit 9bfdebbea4
12 changed files with 250 additions and 54 deletions

View File

@@ -6,21 +6,20 @@ import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.jboss.security.auth.spi.Users.User;
import TO.FamilyDoctorTO;
import TO.MedicalSpecialtyTO;
import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.QuestionTO;
import TO.SpecialistDoctorTO;
import common.Utils;
import jpa.FamilyDoctorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.PatientJPA;
import jpa.PrimaryHealthCareCenterJPA;
import jpa.QuestionJPA;
import jpa.SpecialistDoctorJPA;
@Stateless
@@ -311,4 +310,24 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
else
return null;
}
public QuestionTO getPOJOforQuestionJPA(QuestionJPA qs, int nestedProps) {
QuestionTO qsTO = null;
if (qs != null) {
FamilyDoctorJPA fd = null;
PatientJPA pat = null;
if (nestedProps > 0) {
fd = qs.getFamilyDoctor();
pat = qs.getPatient();
}
nestedProps--;
qsTO = new QuestionTO(qs.getId(), qs.getTitle(), qs.getMessage(), qs.getStatus(), this.getPOJOforPatientJPA(pat, nestedProps),
this.getPOJOforFamilyDoctorJPA(fd, nestedProps), qs.getResponse());
}
return qsTO;
}
}

View File

@@ -1,6 +1,5 @@
package ejb.common;
import java.util.Collection;
import java.util.List;
import javax.ejb.Local;
@@ -9,11 +8,13 @@ import TO.FamilyDoctorTO;
import TO.MedicalSpecialtyTO;
import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.QuestionTO;
import TO.SpecialistDoctorTO;
import jpa.FamilyDoctorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.PatientJPA;
import jpa.PrimaryHealthCareCenterJPA;
import jpa.QuestionJPA;
import jpa.SpecialistDoctorJPA;
/**
@@ -70,4 +71,5 @@ public interface CommonFacadeLocal {
public PatientTO getPOJOforPatientJPA(PatientJPA pat, int nestedProps);
public QuestionTO getPOJOforQuestionJPA(QuestionJPA qs, int nestedProps);
}

View File

@@ -1,20 +1,21 @@
package ejb.medicalTest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import TO.FamilyDoctorTO;
import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import TO.MedicalTestTO.MedicalTestType;
import TO.PatientTO;
import TO.QuestionTO;
import common.QuestionStatus;
import common.UserType;
import TO.QuestionTO;
import ejb.common.CommonFacadeLocal;
import jpa.FamilyDoctorJPA;
import jpa.PatientJPA;
@@ -34,10 +35,9 @@ import managedbean.common.SessionUtils;
*/
@Stateless
public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
// Persistence Unit Context
@PersistenceContext(unitName = "MyHealth")
private EntityManager entman;
EntityManager entman;
@EJB
CommonFacadeLocal commonServices;
@@ -77,13 +77,36 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
public void answerQuestion(String question, String response) {
}
/**
* Recuperar las preguntas sin respuesta para un médico
*
* @param professionalNumber
*/
@Override
public void listAllPendingQuestions(int professionalNumber) {
public List<QuestionTO> listAllPendingQuestions(int familyDoctorId) {
return null;
}
public Long getPendingQuestionsCount(int familyDoctorId) {
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId", Long.class);
query.setParameter("status", QuestionStatus.PENDING);
query.setParameter("docId", familyDoctorId);
return query.getSingleResult();
}
public List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize) {
TypedQuery<QuestionJPA> query = entman.createQuery("SELECT q from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId order by q.title", QuestionJPA.class);
query.setParameter("status", QuestionStatus.PENDING);
query.setParameter("docId", familyDoctorId);
if (pageSize > 0) {
query.setFirstResult(pageNumber * pageSize);
query.setMaxResults(pageSize);
}
List<QuestionJPA> allJPA = query.getResultList();
List<QuestionTO> pendingQuestions = new ArrayList<QuestionTO>();
for (QuestionJPA item : allJPA) {
pendingQuestions.add(commonServices.getPOJOforQuestionJPA(item, 1));
}
return pendingQuestions;
}
/**

View File

@@ -1,11 +1,13 @@
package ejb.medicalTest;
import java.util.Date;
import java.util.List;
import javax.ejb.Remote;
import TO.MedicalSpecialtyTO;
import TO.MedicalTestTO.MedicalTestType;
import TO.QuestionTO;
/**
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para
@@ -42,10 +44,14 @@ public interface MedicalTestFacadeRemote {
*
* De utilidad para paciente y médico de familia. No para médico especialista.
*
* @param professionalNumber
* @param familydoctorid
*/
public void listAllPendingQuestions(int professionalNumber);
public List<QuestionTO> listAllPendingQuestions(int familyDoctorId);
public Long getPendingQuestionsCount(int familyDoctorId);
public List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize);
/**
* Recuperar una pregunta por su String
*