import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.Preparable;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.apache.commons.lang.time.DateUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
+
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
private List<String> availableRepositories;
- private Date startDate;
+ private String startDate;
- private Date endDate;
+ private String endDate;
private int reposSize;
private List<RepositoryStatistics> repositoryStatistics = new ArrayList<RepositoryStatistics>();
+ private DataLimits limits = new DataLimits();
+
+ private String[] datePatterns = new String[] { "MM/dd/yy", "MM/dd/yyyy", "MMMMM/dd/yyyy", "MMMMM/dd/yy",
+ "dd MMMMM yyyy", "dd/MM/yy", "dd/MM/yyyy", "yyyy/MM/dd" };
+
public void prepare()
{
repositoryIds = new ArrayList<String>();
*/
public String generateStatistics()
{
- DataLimits limits = new DataLimits();
- setDefaults();
+ if( rowCount < 10 )
+ {
+ addFieldError( "rowCount", "Row count must be larger than 10." );
+ return INPUT;
+ }
reposSize = selectedRepositories.size();
+ Date startDateInDateFormat = null;
+ Date endDateInDateFormat = null;
+
+ if( startDate == null || "".equals( startDate ) )
+ {
+ startDateInDateFormat = getDefaultStartDate();
+ }
+ else
+ {
+ try
+ {
+ startDateInDateFormat = DateUtils.parseDate( startDate, datePatterns );
+ }
+ catch ( ParseException e )
+ {
+ addFieldError( "startDate", "Invalid date format.");
+ return INPUT;
+ }
+ }
+
+ if( endDate == null || "".equals( endDate ) )
+ {
+ endDateInDateFormat = getDefaultEndDate();
+ }
+ else
+ {
+ try
+ {
+ endDateInDateFormat = DateUtils.parseDate( endDate, datePatterns );
+ }
+ catch ( ParseException e )
+ {
+ addFieldError( "endDate", "Invalid date format.");
+ return INPUT;
+ }
+ }
try
{
try
{
List contentStats = repoContentStatsDao.queryRepositoryContentStatistics(
- new RepositoryContentStatisticsByRepositoryConstraint( repo, startDate, endDate ) );
+ new RepositoryContentStatisticsByRepositoryConstraint( repo, startDateInDateFormat, endDateInDateFormat ) );
if( contentStats == null || contentStats.isEmpty() )
{
continue;
}
- repositoryStatistics.addAll( generator.generateReport( contentStats, repo, startDate, endDate, limits ) );
+ repositoryStatistics.addAll( generator.generateReport( contentStats, repo, startDateInDateFormat, endDateInDateFormat, limits ) );
}
catch ( ObjectNotFoundException oe )
{
try
{
List<RepositoryContentStatistics> contentStats = repoContentStatsDao.queryRepositoryContentStatistics(
- new RepositoryContentStatisticsByRepositoryConstraint( selectedRepo, startDate, endDate ) );
+ new RepositoryContentStatisticsByRepositoryConstraint( selectedRepo, startDateInDateFormat, endDateInDateFormat ) );
if( contentStats == null || contentStats.isEmpty() )
{
int totalPages = ( limits.getTotalCount() / limits.getPerPageCount() ) + extraPage;
limits.setCountOfPages( totalPages );
- repositoryStatistics = generator.generateReport( contentStats, selectedRepo, startDate, endDate, limits );
+ repositoryStatistics = generator.generateReport( contentStats, selectedRepo, startDateInDateFormat, endDateInDateFormat, limits );
}
catch ( ObjectNotFoundException oe )
{
{
addFieldError( "availableRepositories", "Please select a repository (or repositories) from the list." );
return INPUT;
- }
+ }
+
+ if( repositoryStatistics.isEmpty() )
+ {
+ return BLANK;
+ }
+
+ if( startDate.equals( getDefaultStartDate() ) )
+ {
+ startDate = null;
+ }
+ else
+ {
+ startDate = DateFormatUtils.format( startDateInDateFormat, "MM/dd/yyyy" );
+ }
+
+ endDate = DateFormatUtils.format( endDateInDateFormat, "MM/dd/yyyy" );
}
catch ( ArchivaReportException e )
{
return SUCCESS;
}
-
- private void setDefaults()
+
+ private Date getDefaultStartDate()
{
- if( startDate == null )
- {
- Calendar cal = Calendar.getInstance();
- cal.clear();
- cal.set( 1900, 1, 1, 0, 0, 0 );
- startDate = cal.getTime();
- }
+ Calendar cal = Calendar.getInstance();
+ cal.clear();
+ cal.set( 1900, 1, 1, 0, 0, 0 );
- if( endDate == null )
- {
- endDate = Calendar.getInstance().getTime();
- }
+ return cal.getTime();
+ }
+
+ private Date getDefaultEndDate()
+ {
+ return Calendar.getInstance().getTime();
}
public String execute()
this.availableRepositories = availableRepositories;
}
- public Date getStartDate()
+ public String getStartDate()
{
return startDate;
}
- public void setStartDate( Date startDate )
+ public void setStartDate( String startDate )
{
this.startDate = startDate;
}
- public Date getEndDate()
+ public String getEndDate()
{
return endDate;
}
- public void setEndDate( Date endDate )
+ public void setEndDate( String endDate )
{
this.endDate = endDate;
}
{
this.selectedRepo = selectedRepo;
}
+
+ public DataLimits getLimits()
+ {
+ return limits;
+ }
+
+ public void setLimits( DataLimits limits )
+ {
+ this.limits = limits;
+ }
}
<body>
<h1>Statistics Report</h1>
+<c:url var="imgNextPageUrl" value="/images/icon_next_page.gif"/>
+<c:url var="imgPrevPageUrl" value="/images/icon_prev_page.gif"/>
+<c:url var="imgPrevPageDisabledUrl" value="/images/icon_prev_page_disabled.gif"/>
+<c:url var="imgNextPageDisabledUrl" value="/images/icon_next_page_disabled.gif"/>
+
<div id="contentArea">
+
+ <%-- TODO: fix problem in date format! --%>
+
+ <%-- Pagination - start --%>
+ <p>
+
+ <%-- Set Prev & Next icons --%>
+ <c:set var="prevPageUrl">
+ <ww:url action="generateStatisticsReport" namespace="/report">
+ <ww:param name="selectedRepositories" value="%{'${selectedRepositories}'}"/>
+ <ww:param name="rowCount" value="%{'${rowCount}'}"/>
+ <ww:param name="startDate" value="%{'${startDate}'}"/>
+ <ww:param name="endDate" value="%{'${endDate}'}"/>
+ <ww:param name="page" value="%{'${page - 1}'}"/>
+ </ww:url>
+ </c:set>
+ <c:set var="nextPageUrl">
+ <ww:url action="generateStatisticsReport" namespace="/report">
+ <ww:param name="selectedRepositories" value="%{'${selectedRepositories}'}"/>
+ <ww:param name="rowCount" value="%{'${rowCount}'}"/>
+ <ww:param name="startDate" value="%{'${startDate}'}"/>
+ <ww:param name="endDate" value="%{'${endDate}'}"/>
+ <ww:param name="page" value="%{'${page + 1}'}"/>
+ </ww:url>
+ </c:set>
+
+ <c:choose>
+ <c:when test="${page == 1}">
+ <img src="${imgPrevPageDisabledUrl}"/>
+ </c:when>
+ <c:otherwise>
+ <a href="${prevPageUrl}">
+ <img src="${imgPrevPageUrl}"/>
+ </a>
+ </c:otherwise>
+ </c:choose>
+
+ <%-- Google-style pagination --%>
+ <c:choose>
+ <c:when test="${limits.countOfPages > 11}">
+ <c:choose>
+ <c:when test="${(page - 5) < 0}">
+ <c:set var="beginVal">0</c:set>
+ <c:set var="endVal">10</c:set>
+ </c:when>
+ <c:when test="${(page + 5) > (limits.countOfPages - 1)}">
+ <c:set var="beginVal">${(limits.countOfPages -1) - 10}</c:set>
+ <c:set var="endVal">${limits.countOfPages - 1}</c:set>
+ </c:when>
+ <c:otherwise>
+ <c:set var="beginVal">${page - 5}</c:set>
+ <c:set var="endVal">${page + 5}</c:set>
+ </c:otherwise>
+ </c:choose>
+ </c:when>
+ <c:otherwise>
+ <c:set var="beginVal">0</c:set>
+ <c:set var="endVal">${limits.countOfPages - 1}</c:set>
+ </c:otherwise>
+ </c:choose>
+
+ <c:forEach var="i" begin="${beginVal}" end="${endVal}">
+ <c:choose>
+ <c:when test="${i != (page - 1)}">
+ <c:set var="specificPageUrl">
+ <ww:url action="generateStatisticsReport" namespace="/report">
+ <ww:param name="selectedRepositories" value="%{'${selectedRepositories}'}"/>
+ <ww:param name="rowCount" value="%{'${rowCount}'}"/>
+ <ww:param name="startDate" value="%{'${startDate}'}"/>
+ <ww:param name="endDate" value="%{'${endDate}'}"/>
+ <ww:param name="page" value="%{'${page + 1}'}"/>
+ </ww:url>
+ </c:set>
+ <a href="${specificPageUrl}">${i + 1}</a>
+ </c:when>
+ <c:otherwise>
+ <b>${i + 1}</b>
+ </c:otherwise>
+ </c:choose>
+ </c:forEach>
+
+ <c:choose>
+ <c:when test="${page == limits.countOfPages}">
+ <img src="${imgNextPageDisabledUrl}"/>
+ </c:when>
+ <c:otherwise>
+ <a href="${nextPageUrl}">
+ <img src="${imgNextPageUrl}"/>
+ </a>
+ </c:otherwise>
+ </c:choose>
+ </p>
+ <%-- Pagination - end --%>
+
<c:choose>
- <c:when test="${reposSize > 1}">
+ <c:when test="${reposSize > 1}">
- <h1>Latest Statistics Comparison Report</h1>
- <table class="infoTable" border="1">
- <tr>
- <th>Repository</th>
- <th>Total File Count</th>
- <th>Total Size</th>
- <th>Artifact Count</th>
- <th>Group Count</th>
- <th>Project Count</th>
- <th>Plugins</th>
- <th>Archetypes</th>
- <th>Jars</th>
- <th>Wars</th>
- <th>Deployments</th>
- <th>Downloads</th>
- </tr>
+ <h1>Latest Statistics Comparison Report</h1>
+ <table class="infoTable" border="1">
+ <tr>
+ <th>Repository</th>
+ <th>Total File Count</th>
+ <th>Total Size</th>
+ <th>Artifact Count</th>
+ <th>Group Count</th>
+ <th>Project Count</th>
+ <th>Plugins</th>
+ <th>Archetypes</th>
+ <th>Jars</th>
+ <th>Wars</th>
+ <th>Deployments</th>
+ <th>Downloads</th>
+ </tr>
- <c:forEach var="stats" items="${repositoryStatistics}">
- <tr>
- <td>${stats.repositoryId}</td>
- <td align="right">${stats.fileCount}</td>
- <td align="right">${stats.totalSize}</td>
- <td align="right">${stats.artifactCount}</td>
- <td align="right">${stats.groupCount}</td>
- <td align="right">${stats.projectCount}</td>
- <td align="right">${stats.pluginCount}</td>
- <td align="right">${stats.archetypeCount}</td>
- <td align="right">${stats.jarCount}</td>
- <td align="right">${stats.warCount}</td>
- <td align="right">${stats.deploymentCount}</td>
- <td align="right">${stats.downloadCount}</td>
- </tr>
- </c:forEach>
- </table>
-
- </c:when>
- <c:otherwise>
+ <c:forEach var="stats" items="${repositoryStatistics}">
+ <tr>
+ <td>${stats.repositoryId}</td>
+ <td align="right">${stats.fileCount}</td>
+ <td align="right">${stats.totalSize}</td>
+ <td align="right">${stats.artifactCount}</td>
+ <td align="right">${stats.groupCount}</td>
+ <td align="right">${stats.projectCount}</td>
+ <td align="right">${stats.pluginCount}</td>
+ <td align="right">${stats.archetypeCount}</td>
+ <td align="right">${stats.jarCount}</td>
+ <td align="right">${stats.warCount}</td>
+ <td align="right">${stats.deploymentCount}</td>
+ <td align="right">${stats.downloadCount}</td>
+ </tr>
+ </c:forEach>
+ </table>
+ </c:when>
+ <c:otherwise>
- <h1>Statistics for Repository '${selectedRepo}'</h1>
- <table class="infoTable" border="1">
- <tr>
- <th>Date of Scan</th>
- <th>Total File Count</th>
- <th>Total Size</th>
- <th>Artifact Count</th>
- <th>Group Count</th>
- <th>Project Count</th>
- <th>Plugins</th>
- <th>Archetypes</th>
- <th>Jars</th>
- <th>Wars</th>
- <th>Deployments</th>
- <th>Downloads</th>
- </tr>
+ <h1>Statistics for Repository '${selectedRepo}'</h1>
+ <table class="infoTable" border="1">
+ <tr>
+ <th>Date of Scan</th>
+ <th>Total File Count</th>
+ <th>Total Size</th>
+ <th>Artifact Count</th>
+ <th>Group Count</th>
+ <th>Project Count</th>
+ <th>Plugins</th>
+ <th>Archetypes</th>
+ <th>Jars</th>
+ <th>Wars</th>
+ <th>Deployments</th>
+ <th>Downloads</th>
+ </tr>
- <c:forEach var="stats" items="${repositoryStatistics}">
- <tr>
- <td align="right">${stats.dateOfScan}</td>
- <td align="right">${stats.fileCount}</td>
- <td align="right">${stats.totalSize}</td>
- <td align="right">${stats.artifactCount}</td>
- <td align="right">${stats.groupCount}</td>
- <td align="right">${stats.projectCount}</td>
- <td align="right">${stats.pluginCount}</td>
- <td align="right">${stats.archetypeCount}</td>
- <td align="right">${stats.jarCount}</td>
- <td align="right">${stats.warCount}</td>
- <td align="right">${stats.deploymentCount}</td>
- <td align="right">${stats.downloadCount}</td>
- </tr>
- </c:forEach>
- </table>
-
- </c:otherwise>
+ <c:forEach var="stats" items="${repositoryStatistics}">
+ <tr>
+ <td align="right">${stats.dateOfScan}</td>
+ <td align="right">${stats.fileCount}</td>
+ <td align="right">${stats.totalSize}</td>
+ <td align="right">${stats.artifactCount}</td>
+ <td align="right">${stats.groupCount}</td>
+ <td align="right">${stats.projectCount}</td>
+ <td align="right">${stats.pluginCount}</td>
+ <td align="right">${stats.archetypeCount}</td>
+ <td align="right">${stats.jarCount}</td>
+ <td align="right">${stats.warCount}</td>
+ <td align="right">${stats.deploymentCount}</td>
+ <td align="right">${stats.downloadCount}</td>
+ </tr>
+ </c:forEach>
+ </table>
+
+ </c:otherwise>
</c:choose>
</div>