logoutdhaval commented on code in PR #2310:
URL: https://github.com/apache/fineract/pull/2310#discussion_r865645158
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadReportingServiceImpl.java:
##########
@@ -161,16 +167,48 @@ public GenericResultsetData
retrieveGenericResultset(final String name, final St
final long startTime = System.currentTimeMillis();
LOG.info("STARTING REPORT: {} Type: {}", name, type);
-
- final String sql = getSQLtoRun(name, type, queryParams,
isSelfServiceUserReport);
-
- final GenericResultsetData result =
this.genericDataService.fillGenericResultSet(sql);
+ final StringBuilder sqlStringBuilder = new StringBuilder(200);
+ sqlStringBuilder.append(getSQLtoRun(name, type, queryParams,
isSelfServiceUserReport));
+ final GenericResultsetData result;
+ boolean isPaginationAllowed =
Boolean.parseBoolean(queryParams.get(ReportingConstants.IS_PAGINATION_ALLOWED));
+
+ if (isPaginationAllowed) {
+ result = retrieveGenericResultsetWithPagination(sqlStringBuilder,
queryParams);
+ } else {
+ result =
this.genericDataService.fillGenericResultSet(sqlStringBuilder.toString());
+ }
final long elapsed = System.currentTimeMillis() - startTime;
LOG.info("FINISHING Report/Request Name: {} - {} Elapsed Time:
{}", name, type, elapsed);
return result;
}
+ public GenericResultsetData retrieveGenericResultsetWithPagination(final
StringBuilder sqlStringBuilder,
+ final Map<String, String> queryParams) {
+ final GenericResultsetData result;
+ final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+
+ final DataValidatorBuilder baseDataValidator = new
DataValidatorBuilder(dataValidationErrors);
+
baseDataValidator.reset().parameter(PAGE_NO).value(queryParams.get(PAGE_NO)).notNull().throwValidationErrors();
+
+
baseDataValidator.reset().parameter(PAGINATION_ORDER_BY).value(queryParams.get(PAGINATION_ORDER_BY)).ignoreIfNull()
+
.matchesRegularExpression(ORDER_BY_REGEX_PATTERN).throwValidationErrors();
+ int pageSize =
this.configurationDomainService.reportsPaginationNumberOfItemsPerPage();
+
+ Page<GenericResultsetData> reportData =
this.paginationHelper.fetchPage(this.jdbcTemplate, sqlStringBuilder.toString(),
null,
+ new ReportMapper(sqlStringBuilder));
+ int pageNo =
Integer.parseInt(queryParams.get(ReportingConstants.PAGE_NO));
+
+ pageNo = pageNo * pageSize;
+ sqlStringBuilder.append(" order by
").append(queryParams.get(PAGINATION_ORDER_BY));
+ sqlStringBuilder.append(" ");
+ sqlStringBuilder.append(sqlGenerator.limit(pageSize, pageNo));
+ result =
this.genericDataService.fillGenericResultSet(sqlStringBuilder.toString());
+ result.setTotalItems(reportData.getTotalFilteredRecords());
Review Comment:
totalItems and recordsPerPage required for frontend and we are not getting
this from the sql.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]