-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPORT-906: Add pagination support to ReportRequest read methods #249
Changes from 1 commit
aca2b85
533d2b5
28d54b4
7649ee7
5b5e77e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.openmrs.module.reporting.report; | ||
|
||
import java.util.List; | ||
|
||
public class ReportRequestDTO { | ||
|
||
private List<ReportRequest> reportRequests; | ||
|
||
private Long reportRequestCount; | ||
|
||
public ReportRequestDTO(List<ReportRequest> reportRequests, Long reportRequestCount) { | ||
this.reportRequests = reportRequests; | ||
this.reportRequestCount = reportRequestCount; | ||
} | ||
|
||
public List<ReportRequest> getReportRequests() { | ||
return reportRequests; | ||
} | ||
|
||
public void setReportRequests(List<ReportRequest> reportRequests) { | ||
this.reportRequests = reportRequests; | ||
} | ||
|
||
public Long getReportRequestCount() { | ||
return reportRequestCount; | ||
} | ||
|
||
public void setReportRequestCount(Long reportRequestCount) { | ||
this.reportRequestCount = reportRequestCount; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import org.openmrs.module.reporting.report.ReportProcessorConfiguration; | ||
import org.openmrs.module.reporting.report.ReportRequest; | ||
import org.openmrs.module.reporting.report.ReportRequest.Status; | ||
import org.openmrs.module.reporting.report.ReportRequestDTO; | ||
import org.openmrs.module.reporting.report.definition.ReportDefinition; | ||
import org.openmrs.module.reporting.report.processor.ReportProcessor; | ||
import org.openmrs.module.reporting.report.renderer.RenderingMode; | ||
|
@@ -140,6 +141,12 @@ public interface ReportService extends OpenmrsService { | |
@Transactional(readOnly = true) | ||
public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Integer mostRecentNum, Status...statuses); | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add method and param descriptions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some JavaDocs, also to related methods. |
||
* @return {@link ReportRequestDTO} object which contains report requests and total count data | ||
*/ | ||
@Transactional(readOnly = true) | ||
ReportRequestDTO getReportsWithPagination(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Integer pageNumber, Integer pageSize, Status...statuses); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the since annotation? https://wiki.openmrs.org/display/docs/Java+Conventions#JavaConventions-NewPublicMethodsandClasses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the new method name, does it mean we already have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two We'll change the name to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Annotation added, method name changed. |
||
|
||
/** | ||
* Deletes the passed {@link ReportRequest} | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,15 @@ | |
import org.hibernate.Query; | ||
import org.hibernate.criterion.Expression; | ||
import org.hibernate.criterion.Order; | ||
import org.hibernate.criterion.Projections; | ||
import org.hibernate.criterion.Restrictions; | ||
import org.openmrs.api.db.DAOException; | ||
import org.openmrs.api.db.hibernate.DbSessionFactory; | ||
import org.openmrs.module.reporting.report.ReportDesign; | ||
import org.openmrs.module.reporting.report.ReportProcessorConfiguration; | ||
import org.openmrs.module.reporting.report.ReportRequest; | ||
import org.openmrs.module.reporting.report.ReportRequest.Status; | ||
import org.openmrs.module.reporting.report.ReportRequestDTO; | ||
import org.openmrs.module.reporting.report.definition.ReportDefinition; | ||
import org.openmrs.module.reporting.report.renderer.ReportRenderer; | ||
|
||
|
@@ -214,7 +216,44 @@ public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition, | |
} | ||
return c.list(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a method here that returns an Integer called "getReportRequestCount" or something, that takes in your parameters and returns the rowcount projection only, then modify the below method to just return the List that match your parameters including the pageNumber and pageSize. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the method, also removed the "pagination concept", and replaced with more general first result and max results - the page calculation will be added to reporting-rest. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good, thanks @pwargulak |
||
|
||
/** | ||
* @see ReportDAO#getReportsWithPagination(ReportDefinition, Date, Date, Integer, Integer, Status...) | ||
*/ | ||
public ReportRequestDTO getReportsWithPagination(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Integer pageNumber, Integer pageSize, Status...statuses) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are returning requests, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to |
||
Criteria c = sessionFactory.getCurrentSession().createCriteria(ReportRequest.class); | ||
|
||
if (reportDefinition != null) { | ||
c.add(Restrictions.eq("reportDefinition.definition", reportDefinition.getUuid())); | ||
} | ||
if (requestOnOrAfter != null) { | ||
c.add(Restrictions.ge("requestDate", requestOnOrAfter)); | ||
} | ||
if (requestOnOrBefore != null) { | ||
c.add(Restrictions.le("requestDate", requestOnOrBefore)); | ||
} | ||
if (statuses != null && statuses.length > 0) { | ||
c.add(Restrictions.in("status", statuses)); | ||
} | ||
c.addOrder(Order.desc("evaluateCompleteDatetime")); | ||
c.addOrder(Order.desc("evaluateStartDatetime")); | ||
c.addOrder(Order.desc("priority")); | ||
c.addOrder(Order.desc("requestDate")); | ||
|
||
c.setProjection(Projections.rowCount()); | ||
Long count = (Long) c.uniqueResult(); | ||
c.setProjection(null); | ||
|
||
if (pageNumber != null && pageSize != null) { | ||
c.setFirstResult((pageNumber - 1) * pageSize); | ||
c.setMaxResults(pageSize); | ||
} | ||
|
||
List<ReportRequest> reportRequests = c.list(); | ||
|
||
return new ReportRequestDTO(reportRequests, count); | ||
} | ||
|
||
/** | ||
* @see ReportDAO#purgeReportRequest(ReportRequest) | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import org.openmrs.module.reporting.report.ReportProcessorConfiguration; | ||
import org.openmrs.module.reporting.report.ReportRequest; | ||
import org.openmrs.module.reporting.report.ReportRequest.Status; | ||
import org.openmrs.module.reporting.report.ReportRequestDTO; | ||
import org.openmrs.module.reporting.report.definition.ReportDefinition; | ||
import org.openmrs.module.reporting.report.renderer.ReportRenderer; | ||
|
||
|
@@ -123,6 +124,11 @@ public List<ReportDesign> getReportDesigns(ReportDefinition reportDefinition, Cl | |
*/ | ||
public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Integer mostRecentNum, Status...statuses); | ||
|
||
/** | ||
* @return {@link ReportRequestDTO} object which contains report requests and total count data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also document this fully? Or at least use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added see |
||
*/ | ||
ReportRequestDTO getReportsWithPagination(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Integer pageNumber, Integer pageSize, Status...statuses); | ||
|
||
/** | ||
* Deletes the passed {@link ReportRequest} | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just get the reportRequestsCount from reportRequests.size()? Or can we change the variable names to make things clearer? 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the class name to
ReportRequestPageDTO
andreportRequestsCount
tototalCount
, so hopefully it should be easily read as "this is some subset of report requests and total count indicates the size of total set"/ " one page from totalCount items".