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;
endDateInDF = cal.getTime();
}
- range[0] = ( page - 1 ) * rowCount;
- range[1] = ( page * rowCount ) + 1;
-
Collection<String> repos = getManagableRepositories();
if ( !repository.equals( ALL_REPOSITORIES ) )
{
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()
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;
</tr>
</c:forEach>
</table>
-
- <s:set name="page" value="page"/>
- <c:if test="${page > 1}"><a href="<s:property value='prev' />"><<</a></c:if>
- <strong>Page: </strong>${page}
- <s:set name="isLastPage" value="isLastPage"/>
- <c:if test="${!isLastPage}"><a href="<s:property value='next' />">>></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}"><<</a></c:if>
+ <strong>Page: </strong>${page}
+ <s:set name="isLastPage" value="isLastPage"/>
+ <c:if test="${!isLastPage}"><a href="${nextPageUrl}">>></a></c:if>
+
</c:if>
</div>