From: Brett Porter Date: Wed, 24 Aug 2011 13:10:10 +0000 (+0000) Subject: [MRM-1317] Pagination is broken in audit log report in trunk X-Git-Tag: archiva-1.4-M1~488 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0699d4aaaad4dc5ef560b8d6c2bf29a631458a35;p=archiva.git [MRM-1317] Pagination is broken in audit log report in trunk Submitted by: Maria Catherine Tan git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1161083 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java index bb6f30599..04e887912 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java @@ -262,7 +262,7 @@ public class GenerateReportAction int start = rowCount * ( currentPage - 1 ); int end = ( start + rowCount ) - 1; - if ( end > stats.size() ) + if ( end >= stats.size() ) { end = stats.size() - 1; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java index 896c6ef05..01617770c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java @@ -80,18 +80,12 @@ public class ViewAuditLogReportAction private int page = 1; - private String prev; - - private String next; - protected boolean isLastPage = true; private List auditLogs; private static final String ALL_REPOSITORIES = "all"; - protected int[] range = new int[2]; - private String initial = "true"; private String headerName; @@ -183,9 +177,6 @@ public class ViewAuditLogReportAction endDateInDF = cal.getTime(); } - range[0] = ( page - 1 ) * rowCount; - range[1] = ( page * rowCount ) + 1; - Collection repos = getManagableRepositories(); if ( !repository.equals( ALL_REPOSITORIES ) ) { @@ -233,44 +224,55 @@ public class ViewAuditLogReportAction repositorySession.close(); } + headerName = HEADER_RESULTS; + if ( auditLogs.isEmpty() ) { addActionError( "No audit logs found." ); initial = "true"; + return SUCCESS; } else { initial = "false"; + return paginate(); } - - headerName = HEADER_RESULTS; - paginate(); - - return SUCCESS; } - private void paginate() + private String paginate() { - if ( auditLogs.size() <= rowCount ) + int rowCount = getRowCount(); + int extraPage = ( auditLogs.size() % rowCount ) != 0 ? 1 : 0; + int totalPages = ( auditLogs.size() / rowCount ) + extraPage; + + int currentPage = getPage(); + if ( currentPage > totalPages ) + { + addActionError( + "Error encountered while generating report :: The requested page exceeds the total number of pages." ); + return ERROR; + } + + if ( currentPage == totalPages ) { isLastPage = true; } else { isLastPage = false; - auditLogs.remove( rowCount ); } - prev = request.getRequestURL() + "?page=" + ( page - 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId - + "&artifactId=" + artifactId + "&repository=" + repository + "&startDate=" + startDate + "&endDate=" - + endDate; + int start = rowCount * ( currentPage - 1 ); + int end = ( start + rowCount ) - 1; + + if ( end >= auditLogs.size() ) + { + end = auditLogs.size() - 1; + } - next = request.getRequestURL() + "?page=" + ( page + 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId - + "&artifactId=" + artifactId + "&repository=" + repository + "&startDate=" + startDate + "&endDate=" - + endDate; + auditLogs = auditLogs.subList( start, end + 1 ); - prev = StringUtils.replace( prev, " ", "%20" ); - next = StringUtils.replace( next, " ", "%20" ); + return SUCCESS; } private List getManagableRepositories() @@ -389,26 +391,6 @@ public class ViewAuditLogReportAction this.isLastPage = isLastPage; } - public String getPrev() - { - return prev; - } - - public void setPrev( String prev ) - { - this.prev = prev; - } - - public String getNext() - { - return next; - } - - public void setNext( String next ) - { - this.next = next; - } - public String getInitial() { return initial; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp index 909aedd1a..6f1e93e7d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp @@ -134,12 +134,36 @@ - - - << - Page: ${page} - - >> + + + + + + + + + + + + + + + + + + + + + + + + + + << + Page: ${page} + + >> +