Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

pwargulak
Copy link
Contributor

@pwargulak pwargulak commented Feb 20, 2024

Summary

This change extends ReportService with new method getReportsWithPagination used to read ReportRequests for specific report, dates, statuses paginated for performance gains.
It was done as part of making of O3 Reports Admin pages.

See the related issue.

Issue

https://openmrs.atlassian.net/browse/REPORT-906

@pwargulak
Copy link
Contributor Author

@druchniewicz CC

* @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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The 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 getReports method without pagination?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two getReportRequests methods without pagination, both return a List.
The getReportsWithPagination returns 'wrapper' object - a reason for different name.

We'll change the name to getReportRequestsWithPagination as suggested in some of the later comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation added, method name changed.

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

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add method and param descriptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some JavaDocs, also to related methods.

/**
* @see ReportDAO#getReportsWithPagination(ReportDefinition, Date, Date, Integer, Integer, Status...)
*/
public ReportRequestDTO getReportsWithPagination(ReportDefinition reportDefinition, Date requestOnOrAfter, Date requestOnOrBefore, Integer pageNumber, Integer pageSize, Status...statuses) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are returning requests, getReportRequests looks better than getReports. Not so? 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to getReportRequestsWithPagination, although the suffix WithPagination might not be great.

@dkayiwa
Copy link
Member

dkayiwa commented Feb 20, 2024

What do you think of adding some tests?

@pwargulak
Copy link
Contributor Author

What do you think of adding some tests?

Added couple of tests.

<reporting_report_request id="1" uuid="h8a82b63-1066-4c1d-9b43-b405851fc467"
Copy link
Member

@dkayiwa dkayiwa Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intentionally change the formatting of these xml dataset files? I notice that you reformatted quite a number of them. I thought you would just add your new records and leave the rest intact. 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added 4th reporting_report_request to all datasets (one for each openMRSMinorVersion) and intentionally formatted the reporting_report_request elements group to have the same style as reporting_report_design elements group just a line above - IMO made sense to do.

*/
@Transactional(readOnly = true)
public ReportRequestDTO getReportRequestsWithPagination(ReportDefinition reportDefinition, Date requestOnOrAfter,
Date requestOnOrBefore, Integer pageNumber, Integer pageSize, Status...statuses);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you look into this formatting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it back into one line.

@@ -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
Copy link
Member

@dkayiwa dkayiwa Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also document this fully? Or at least use a @see annotation pointing to where it is properly documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added see

private long reportRequestCount;

public ReportRequestDTO(List<ReportRequest> reportRequests, long reportRequestCount) {
this.reportRequests = reportRequests;
Copy link
Member

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? 😊

Copy link
Contributor Author

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 and reportRequestsCount to totalCount, 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".


import java.util.List;

public class ReportRequestPageDTO {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to see us not introduce this new ReportRequestPageDTO class, but to just have separate DAO methods - one to get a count of all requests that match the criteria, and one to get the current list of requests that match the criteria. Creating a separate shared method to create the common criteria that would be used would be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -214,7 +216,45 @@ public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition,
}
return c.list();
}

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks @pwargulak

Copy link
Member

@mseaton mseaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me @pwargulak , thanks for the rework. I made a few minor comments related to the javadoc that seemed inaccurate, but otherwise I think this is good to go.

* @param requestOnOrBefore a Date used to limit result to ReportRequests which ware requested on or before
* (lower or equal filter), nullable
* @param firstResult the first result to be retrieved, not null
* @param maxResults a limit upon the number of Report Requests to be retrieved, not null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maxResults does appear that it can be nullable, based on the dao implementation...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* (greater or equal filter), nullable
* @param requestOnOrBefore a Date used to limit result to ReportRequests which ware requested on or before
* (lower or equal filter), nullable
* @param firstResult the first result to be retrieved, not null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The firstResult does appear that it can be nullable, based on the dao implementation...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -214,7 +216,45 @@ public List<ReportRequest> getReportRequests(ReportDefinition reportDefinition,
}
return c.list();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks @pwargulak

Copy link
Member

@mseaton mseaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready to merge @pwargulak , but all changes made to the reporting module should have a corresponding ticket in the reporting module JIRA project, and the commit message should link back to that ticket, rather than to an O3 ticket. Can you do that?

@pwargulak pwargulak changed the title O3-1494: Added method to get report requests with pagination REPORT-906: Add pagination support to ReportRequest read methods Mar 13, 2024
@pwargulak
Copy link
Contributor Author

@pwargulak
Copy link
Contributor Author

Moved to #251 to indicate real source of the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants