]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1317] Pagination is broken in audit log report in trunk
authorBrett Porter <brett@apache.org>
Wed, 24 Aug 2011 13:10:10 +0000 (13:10 +0000)
committerBrett Porter <brett@apache.org>
Wed, 24 Aug 2011 13:10:10 +0000 (13:10 +0000)
Submitted by: Maria Catherine Tan

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1161083 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp

index bb6f305996e78cee85953a9d1867f550300c7b62..04e887912a6f078f643d8e571c937a18edcbf1e8 100644 (file)
@@ -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;
                     }
index 896c6ef057d1517d2edf260619be743a7cc4ab06..01617770c77620b304e3e65034472fd2b3434226 100644 (file)
@@ -80,18 +80,12 @@ public class ViewAuditLogReportAction
 
     private int page = 1;
 
-    private String prev;
-
-    private String next;
-
     protected boolean isLastPage = true;
 
     private List<AuditEvent> 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<String> 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<String> 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;
index 909aedd1a84b4a37e4658d263e9fe518ff25e5a1..6f1e93e7d66a9b30546e849636236b77b5ab7441 100644 (file)
                      </tr>                 
                    </c:forEach>
                  </table>      
-                 
-                 <s:set name="page" value="page"/>
-             <c:if test="${page > 1}"><a href="<s:property value='prev' />">&lt;&lt;</a></c:if>
-                         <strong>Page: </strong>${page}
-                 <s:set name="isLastPage" value="isLastPage"/>           
-                 <c:if test="${!isLastPage}"><a href="<s:property value='next' />">&gt;&gt;</a></c:if>
+
+          <c:set var="prevPageUrl">
+            <s:url action="viewAuditLogReport" namespace="/report">
+              <s:param name="repository" value="%{#attr.repository}" />
+              <s:param name="groupId" value="%{#attr.groupId}" />
+              <s:param name="artifactId" value="%{#attr.artifactId}" />
+              <s:param name="rowCount" value="%{#attr.rowCount}" />
+              <s:param name="page" value="%{#attr.page - 1}"/>
+              <s:param name="startDate" value="%{#attr.startDate}"/>
+              <s:param name="endDate" value="%{#attr.endDate}" />
+            </s:url>
+          </c:set>
+          <c:set var="nextPageUrl">
+            <s:url action="viewAuditLogReport" namespace="/report">
+              <s:param name="repository" value="%{#attr.repository }" />
+              <s:param name="groupId" value="%{#attr.groupId}" />
+              <s:param name="artifactId" value="%{#attr.artifactId }" />
+              <s:param name="rowCount" value="%{#attr.rowCount}" />
+              <s:param name="page" value="%{#attr.page + 1}"/>
+              <s:param name="startDate" value="%{#attr.startDate}"/>
+              <s:param name="endDate" value="%{#attr.endDate}" />
+            </s:url>
+           </c:set>
+
+           <s:set name="page" value="page"/>
+           <c:if test="${page gt 1}"><a href="${prevPageUrl}">&lt;&lt;</a></c:if>
+           <strong>Page: </strong>${page}
+           <s:set name="isLastPage" value="isLastPage"/>
+           <c:if test="${!isLastPage}"><a href="${nextPageUrl}">&gt;&gt;</a></c:if>
                </c:if>  
        </div>