From 94ece43b50b77040db97dfe4fae260e05f4f08d6 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 3 Dec 2009 03:36:57 +0000 Subject: [PATCH] [MRM-1293] some clean up in preparation for changes to repository statistics git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@886669 13f79535-47bb-0310-9956-ffa450edef68 --- .../DeleteManagedRepositoryAction.java | 3 +- .../EditManagedRepositoryAction.java | 44 ++++++++---------- .../action/reports/GenerateReportAction.java | 46 +++++++++---------- 3 files changed, 43 insertions(+), 50 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index fed1d50e7..508ea8da2 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -139,7 +139,8 @@ public class DeleteManagedRepositoryAction removeRepositoryRoles( cleanupRepository ); cleanupDatabase( cleanupRepository.getId() ); cleanupScanStats( cleanupRepository.getId() ); - + // TODO: delete all content for a repository from the content API? + List proxyConnectors = getProxyConnectors(); for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors ) { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java index f128ba152..3f3c6b240 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -19,9 +19,12 @@ package org.apache.maven.archiva.web.action.admin.repositories; * under the License. */ +import java.io.File; +import java.io.IOException; +import java.util.List; + import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Validateable; - import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -35,15 +38,10 @@ import org.apache.maven.archiva.repository.audit.AuditEvent; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.scheduler.CronExpressionValidator; -import java.io.File; -import java.io.IOException; -import java.util.List; - /** - * AddManagedRepositoryAction + * AddManagedRepositoryAction * * @version $Id$ - * * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="editManagedRepositoryAction" instantiation-strategy="per-lookup" */ public class EditManagedRepositoryAction @@ -56,7 +54,7 @@ public class EditManagedRepositoryAction private ManagedRepositoryConfiguration repository; private String repoid; - + private final String action = "editRepository"; /** @@ -90,10 +88,10 @@ public class EditManagedRepositoryAction public String confirmUpdate() { - // location was changed + // location was changed return save( true ); } - + public String commit() { ManagedRepositoryConfiguration existingConfig = @@ -102,17 +100,17 @@ public class EditManagedRepositoryAction boolean resetStats = false; // check if the location was changed - if( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) ) + if ( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) ) { resetStats = true; File dir = new File( repository.getLocation() ); - if( dir.exists() ) + if ( dir.exists() ) { return CONFIRM; } } - + return save( resetStats ); } @@ -120,7 +118,7 @@ public class EditManagedRepositoryAction { // Ensure that the fields are valid. Configuration configuration = archivaConfiguration.getConfiguration(); - + // We are in edit mode, remove the old repository configuration. removeRepository( repository.getId(), configuration ); @@ -132,7 +130,10 @@ public class EditManagedRepositoryAction triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO ); addRepositoryRoles( repository ); result = saveConfiguration( configuration ); - resetStatistics( resetStats ); + if ( resetStats ) + { + resetStatistics(); + } } catch ( IOException e ) { @@ -157,7 +158,7 @@ public class EditManagedRepositoryAction return result; } - + @Override public void validate() { @@ -169,14 +170,9 @@ public class EditManagedRepositoryAction } } - private void resetStatistics( boolean reset ) + private void resetStatistics() throws ObjectNotFoundException, ArchivaDatabaseException { - if ( !reset ) - { - return; - } - RepositoryContentStatisticsDAO repoContentStatsDao = archivaDAO.getRepositoryContentStatisticsDAO(); List contentStats = repoContentStatsDao.queryRepositoryContentStatistics( @@ -189,7 +185,7 @@ public class EditManagedRepositoryAction repoContentStatsDao.deleteRepositoryContentStatistics( stats ); } } - } + } public String getRepoid() { @@ -210,7 +206,7 @@ public class EditManagedRepositoryAction { this.repository = repository; } - + public String getAction() { return action; 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 f38012909..5bb30abf2 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 @@ -19,8 +19,21 @@ package org.apache.maven.archiva.web.action.reports; * under the License. */ -import com.opensymphony.xwork2.Preparable; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import javax.servlet.http.HttpServletRequest; +import com.opensymphony.xwork2.Preparable; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; @@ -44,29 +57,14 @@ import org.apache.maven.archiva.reporting.DataLimits; import org.apache.maven.archiva.reporting.RepositoryStatistics; import org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator; import org.apache.maven.archiva.security.ArchivaRoleConstants; -import org.codehaus.plexus.redback.rbac.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.http.HttpServletRequest; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; import org.apache.maven.archiva.web.action.PlexusActionSupport; import org.apache.struts2.interceptor.ServletRequestAware; +import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.redback.integration.interceptor.SecureAction; import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="generateReport" instantiation-strategy="per-lookup" @@ -76,19 +74,17 @@ public class GenerateReportAction implements SecureAction, ServletRequestAware, Preparable { private Logger log = LoggerFactory.getLogger( GenerateReportAction.class ); - + /** * @plexus.requirement role-hint="jdo" */ protected ArchivaDAO dao; - + /** * @plexus.requirement */ private ArchivaConfiguration archivaConfiguration; - protected Constraint constraint; - protected HttpServletRequest request; protected List reports = new ArrayList(); @@ -357,8 +353,8 @@ public class GenerateReportAction addFieldError( "startDate", "Start Date must be earlier than the End Date" ); return INPUT; } - - List contentStats = repoContentStatsDao.queryRepositoryContentStatistics( + + List contentStats = repoContentStatsDao.queryRepositoryContentStatistics( new RepositoryContentStatisticsByRepositoryConstraint( selectedRepo, startDateInDF, endDateInDF ) ); if( contentStats == null || contentStats.isEmpty() ) -- 2.39.5