summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java1
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java57
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java3
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java15
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java4
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/AbstractActionSupport.java180
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java12
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java121
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java22
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/resources/log4j.xml4
-rw-r--r--pom.xml2
13 files changed, 286 insertions, 143 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
index b3750ed25..e0a5b875a 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
@@ -193,6 +193,7 @@ public class DefaultArchivaConfiguration
}
Configuration config = new ConfigurationRegistryReader().read( subset );
+
config.getRepositoryGroups();
config.getRepositoryGroupsAsMap();
if ( !config.getRepositories().isEmpty() )
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
index 22f89ff8c..69eb0104e 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
@@ -263,7 +263,12 @@ public class DefaultManagedRepositoryAdmin
}
- public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation )
+ // FIXME delete stagedRepo if exists !!!!
+ // find it tru :
+ // stagingRepository =
+ // archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid + "-stage" );
+ public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
+ boolean deleteContent )
throws RepositoryAdminException
{
Configuration config = archivaConfiguration.getConfiguration();
@@ -282,6 +287,7 @@ public class DefaultManagedRepositoryAdmin
{
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository( repository.getId() );
+ log.debug( "call repositoryStatisticsManager.deleteStatistics" );
repositoryStatisticsManager.deleteStatistics( metadataRepository, repository.getId() );
repositorySession.save();
}
@@ -304,14 +310,19 @@ public class DefaultManagedRepositoryAdmin
throw new RepositoryAdminException( "Error saving configuration for delete action" + e.getMessage() );
}
- // TODO could be async ? as directory can be huge
- File dir = new File( repository.getLocation() );
- if ( !FileUtils.deleteQuietly( dir ) )
+ if ( deleteContent )
{
- throw new RepositoryAdminException( "Cannot delete repository " + dir );
+ // TODO could be async ? as directory can be huge
+ File dir = new File( repository.getLocation() );
+ if ( !FileUtils.deleteQuietly( dir ) )
+ {
+ throw new RepositoryAdminException( "Cannot delete repository " + dir );
+ }
}
- List<ProxyConnectorConfiguration> proxyConnectors = config.getProxyConnectors();
+ // olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
+ List<ProxyConnectorConfiguration> proxyConnectors =
+ new ArrayList<ProxyConnectorConfiguration>( config.getProxyConnectors() );
for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
{
if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId() ) )
@@ -408,6 +419,7 @@ public class DefaultManagedRepositoryAdmin
saveConfiguration( this.archivaConfiguration.getConfiguration() );
if ( resetStats )
{
+ log.debug( "call repositoryStatisticsManager.deleteStatistics" );
repositoryStatisticsManager.deleteStatistics( repositorySession.getRepository(),
managedRepository.getId() );
repositorySession.save();
@@ -450,7 +462,8 @@ public class DefaultManagedRepositoryAdmin
AuditInformation auditInformation )
{
User user = auditInformation == null ? null : auditInformation.getUser();
- AuditEvent event = new AuditEvent( repositoryId, user == null ? "null" : user.getUsername(), resource, action );
+ AuditEvent event =
+ new AuditEvent( repositoryId, user == null ? "null" : (String) user.getPrincipal(), resource, action );
event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() );
for ( AuditListener listener : auditListeners )
@@ -604,4 +617,34 @@ public class DefaultManagedRepositoryAdmin
{
this.roleManager = roleManager;
}
+
+ public RepositoryStatisticsManager getRepositoryStatisticsManager()
+ {
+ return repositoryStatisticsManager;
+ }
+
+ public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
+ {
+ this.repositoryStatisticsManager = repositoryStatisticsManager;
+ }
+
+ public RepositorySessionFactory getRepositorySessionFactory()
+ {
+ return repositorySessionFactory;
+ }
+
+ public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
+ {
+ this.repositorySessionFactory = repositorySessionFactory;
+ }
+
+ public List<AuditListener> getAuditListeners()
+ {
+ return auditListeners;
+ }
+
+ public void setAuditListeners( List<AuditListener> auditListeners )
+ {
+ this.auditListeners = auditListeners;
+ }
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java
index 0fc9fa1c0..5bcda0cd0 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java
@@ -21,7 +21,6 @@ package org.apache.archiva.admin.repository.managed;
import org.apache.archiva.admin.AuditInformation;
import org.apache.archiva.admin.repository.RepositoryAdminException;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import java.util.List;
@@ -37,7 +36,7 @@ public interface ManagedRepositoryAdmin
ManagedRepository getManagedRepository( String repositoryId )
throws RepositoryAdminException;
- Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation )
+ Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation, boolean deleteContent )
throws RepositoryAdminException;
Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
index 64a5eea6c..80831037b 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
@@ -102,7 +102,7 @@ public class ManagedRepositoryAdminTest
assertTrue(
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, "test-new-one" ) );
- managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation() );
+ managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), false );
repos = managedRepositoryAdmin.getManagedRepositories();
assertNotNull( repos );
@@ -169,7 +169,7 @@ public class ManagedRepositoryAdminTest
assertTrue(
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, "test-new-one" ) );
- managedRepositoryAdmin.deleteManagedRepository( repo.getId(), getFakeAuditInformation() );
+ managedRepositoryAdmin.deleteManagedRepository( repo.getId(), getFakeAuditInformation(), false );
assertFalse(
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "test-new-one" ) );
@@ -211,7 +211,16 @@ public class ManagedRepositoryAdminTest
User getFakeUser()
{
- SimpleUser user = new SimpleUser();
+ SimpleUser user = new SimpleUser()
+ {
+ @Override
+ public Object getPrincipal()
+ {
+ return "root";
+ }
+
+ };
+
user.setUsername( "root" );
user.setFullName( "The top user" );
return user;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
index fea0a7dee..a0a8ccacc 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
@@ -60,7 +60,7 @@ public interface RepositoriesService
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- Boolean deleteManagedRepository( @PathParam( "repositoryId" ) String repositoryId )
+ Boolean deleteManagedRepository( @PathParam( "repositoryId" ) String repositoryId, boolean deleteContent )
throws Exception;
@@ -69,7 +69,7 @@ public interface RepositoriesService
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- Boolean addManagedRepository( ManagedRepository managedRepository)
+ Boolean addManagedRepository( ManagedRepository managedRepository )
throws Exception;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
index f06599a5a..7abbaa22c 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
@@ -138,11 +138,11 @@ public class DefaultRepositoriesService
return null;
}
- public Boolean deleteManagedRepository( String repoId )
+ public Boolean deleteManagedRepository( String repoId, boolean deleteContent )
throws Exception
{
- return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation() );
+ return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent );
}
public List<RemoteRepository> getRemoteRepositories()
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
index be11f0a98..beb9573f7 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
@@ -118,7 +118,7 @@ public class RepositoriesServiceTest
ManagedRepository repo = getTestManagedRepository();
if ( service.getManagedRepository( repo.getId() ) != null )
{
- service.deleteManagedRepository( repo.getId() );
+ service.deleteManagedRepository( repo.getId(), true );
assertNull( service.getManagedRepository( repo.getId() ) );
}
service.addManagedRepository( repo );
@@ -135,7 +135,7 @@ public class RepositoriesServiceTest
ManagedRepository repo = getTestManagedRepository();
if ( service.getManagedRepository( repo.getId() ) != null )
{
- service.deleteManagedRepository( repo.getId() );
+ service.deleteManagedRepository( repo.getId(), true );
assertNull( service.getManagedRepository( repo.getId() ) );
}
service.addManagedRepository( repo );
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/AbstractActionSupport.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/AbstractActionSupport.java
index add5607e3..468b51087 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/AbstractActionSupport.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/AbstractActionSupport.java
@@ -19,10 +19,9 @@ package org.apache.maven.archiva.web.action;
* under the License.
*/
-import com.google.common.collect.Lists;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
-import com.opensymphony.xwork2.interceptor.ParameterNameAware;
+import org.apache.archiva.admin.AuditInformation;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.audit.Auditable;
@@ -31,6 +30,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;
+import org.codehaus.plexus.redback.users.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
@@ -40,6 +40,7 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -181,4 +182,179 @@ public abstract class AbstractActionSupport
return beans;
}
+
+ protected AuditInformation getAuditInformation()
+ {
+ AuditInformation auditInformation = new AuditInformation( new SimpleUser( getPrincipal() ), getRemoteAddr() );
+
+ return auditInformation;
+ }
+
+ /**
+ * dummy information for audit events
+ * @since 1.4
+ */
+ private static class SimpleUser
+ implements User
+ {
+
+ private String principal;
+
+ protected SimpleUser( String principal )
+ {
+ this.principal = principal;
+ }
+
+ public Object getPrincipal()
+ {
+ return this.principal;
+ }
+
+ public String getUsername()
+ {
+ return null;
+ }
+
+ public void setUsername( String name )
+ {
+
+ }
+
+ public String getFullName()
+ {
+ return null;
+ }
+
+ public void setFullName( String name )
+ {
+
+ }
+
+ public String getEmail()
+ {
+ return null;
+ }
+
+ public void setEmail( String address )
+ {
+
+ }
+
+ public String getPassword()
+ {
+ return null;
+ }
+
+ public void setPassword( String rawPassword )
+ {
+
+ }
+
+ public String getEncodedPassword()
+ {
+ return null;
+ }
+
+ public void setEncodedPassword( String encodedPassword )
+ {
+
+ }
+
+ public Date getLastPasswordChange()
+ {
+ return null;
+ }
+
+ public void setLastPasswordChange( Date passwordChangeDate )
+ {
+
+ }
+
+ public List<String> getPreviousEncodedPasswords()
+ {
+ return null;
+ }
+
+ public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
+ {
+
+ }
+
+ public void addPreviousEncodedPassword( String encodedPassword )
+ {
+
+ }
+
+ public boolean isPermanent()
+ {
+ return false;
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+
+ }
+
+ public boolean isLocked()
+ {
+ return false;
+ }
+
+ public void setLocked( boolean locked )
+ {
+
+ }
+
+ public boolean isPasswordChangeRequired()
+ {
+ return false;
+ }
+
+ public void setPasswordChangeRequired( boolean changeRequired )
+ {
+
+ }
+
+ public boolean isValidated()
+ {
+ return false;
+ }
+
+ public void setValidated( boolean valid )
+ {
+
+ }
+
+ public int getCountFailedLoginAttempts()
+ {
+ return 0;
+ }
+
+ public void setCountFailedLoginAttempts( int count )
+ {
+
+ }
+
+ public Date getAccountCreationDate()
+ {
+ return null;
+ }
+
+ public void setAccountCreationDate( Date date )
+ {
+
+ }
+
+ public Date getLastLoginDate()
+ {
+ return null;
+ }
+
+ public void setLastLoginDate( Date date )
+ {
+
+ }
+ }
+
+
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
index a5163e055..7af73b904 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
@@ -41,6 +41,7 @@ import org.codehaus.redback.rest.services.RedbackRequestInformation;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
/**
@@ -127,16 +128,6 @@ public abstract class AbstractRepositoriesAdminAction
}
- protected AuditInformation getAuditInformation()
- {
- RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
- User user = redbackRequestInformation == null ? null : redbackRequestInformation.getUser();
- String remoteAddr = redbackRequestInformation == null ? "null" : redbackRequestInformation.getRemoteAddr();
- AuditInformation auditInformation = new AuditInformation( user, remoteAddr);
-
- return auditInformation;
- }
-
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
{
return managedRepositoryAdmin;
@@ -146,4 +137,5 @@ public abstract class AbstractRepositoriesAdminAction
{
this.managedRepositoryAdmin = managedRepositoryAdmin;
}
+
}
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 7fc927b6d..6d09a066e 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
@@ -20,29 +20,17 @@ package org.apache.maven.archiva.web.action.admin.repositories;
*/
import com.opensymphony.xwork2.Preparable;
-import org.apache.archiva.audit.AuditEvent;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.archiva.metadata.repository.MetadataRepositoryException;
-import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
-import org.codehaus.plexus.redback.role.RoleManagerException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
/**
* DeleteManagedRepositoryAction
*
* @version $Id$
- * plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteManagedRepositoryAction" instantiation-strategy="per-lookup"
+ * plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteManagedRepositoryAction" instantiation-strategy="per-lookup"
*/
@Controller( "deleteManagedRepositoryAction" )
@Scope( "prototype" )
@@ -50,18 +38,17 @@ public class DeleteManagedRepositoryAction
extends AbstractManagedRepositoriesAction
implements Preparable
{
+
+ /**
+ * FIXME we must manipulate beans from repo admin api
+ * The model for this action.
+ */
private ManagedRepositoryConfiguration repository;
private ManagedRepositoryConfiguration stagingRepository;
private String repoid;
- /**
- * plexus.requirement
- */
- @Inject
- private RepositoryStatisticsManager repositoryStatisticsManager;
-
public void prepare()
{
if ( StringUtils.isNotBlank( repoid ) )
@@ -103,103 +90,22 @@ public class DeleteManagedRepositoryAction
return ERROR;
}
- String result;
+ String result = SUCCESS;
- RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
- Configuration configuration = archivaConfiguration.getConfiguration();
- if ( attachedStagingRepo != null )
- {
- cleanupRepositoryData( attachedStagingRepo, repositorySession );
- removeRepository( repoid + "-stage", configuration );
- triggerAuditEvent( repoid + "-stage", null, AuditEvent.DELETE_MANAGED_REPO );
-
- }
- cleanupRepositoryData( existingRepository, repositorySession );
- removeRepository( repoid, configuration );
- triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO );
- result = saveConfiguration( configuration );
-
- if ( result.equals( SUCCESS ) )
- {
- if ( deleteContents )
- {
- if ( attachedStagingRepo != null )
- {
- removeContents( attachedStagingRepo );
- }
- removeContents( existingRepository );
- }
- }
- }
- catch ( IOException e )
- {
- addActionError(
- "Unable to delete repository, content may already be partially removed: " + e.getMessage() );
- result = ERROR;
- }
- catch ( RoleManagerException e )
- {
- addActionError(
- "Unable to delete repository, content may already be partially removed: " + e.getMessage() );
- result = ERROR;
+ getManagedRepositoryAdmin().deleteManagedRepository( existingRepository.getId(), getAuditInformation(),
+ deleteContents );
}
- catch ( MetadataRepositoryException e )
+ catch ( RepositoryAdminException e )
{
addActionError(
"Unable to delete repository, content may already be partially removed: " + e.getMessage() );
result = ERROR;
}
- finally
- {
- repositorySession.close();
- }
-
return result;
}
- private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository,
- RepositorySession repositorySession )
- throws RoleManagerException, MetadataRepositoryException
- {
- removeRepositoryRoles( cleanupRepository );
- MetadataRepository metadataRepository = repositorySession.getRepository();
- cleanupDatabase( metadataRepository, cleanupRepository.getId() );
- repositoryStatisticsManager.deleteStatistics( metadataRepository, cleanupRepository.getId() );
- // TODO: delete all content for a repository from the content API?
- repositorySession.save();
-
- List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
- for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
- {
- if ( StringUtils.equals( proxyConnector.getSourceRepoId(), cleanupRepository.getId() ) )
- {
- archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
- }
- }
-
- Map<String, List<String>> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap();
- if ( repoToGroupMap != null )
- {
- if ( repoToGroupMap.containsKey( cleanupRepository.getId() ) )
- {
- List<String> repoGroups = repoToGroupMap.get( cleanupRepository.getId() );
- for ( String repoGroup : repoGroups )
- {
- archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository(
- cleanupRepository.getId() );
- }
- }
- }
- }
-
- private void cleanupDatabase( MetadataRepository metadataRepository, String repoId )
- throws MetadataRepositoryException
- {
- metadataRepository.removeRepository( repoId );
- }
-
public ManagedRepositoryConfiguration getRepository()
{
return repository;
@@ -219,9 +125,4 @@ public class DeleteManagedRepositoryAction
{
this.repoid = repoid;
}
-
- public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
- {
- this.repositoryStatisticsManager = repositoryStatisticsManager;
- }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
index b4e985cd4..fa67af578 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
@@ -20,6 +20,8 @@ package org.apache.maven.archiva.web.action.admin.repositories;
*/
import com.opensymphony.xwork2.Action;
+import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
+import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.repository.MetadataRepository;
@@ -38,9 +40,12 @@ import org.apache.maven.archiva.web.action.AbstractActionTestCase;
import org.apache.maven.archiva.web.action.AuditEventArgumentsMatcher;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.role.RoleManagerException;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.jdo.JdoUser;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.rest.services.RedbackRequestInformation;
import org.easymock.MockControl;
import java.io.File;
@@ -103,7 +108,6 @@ public class DeleteManagedRepositoryActionTest
repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
- action.setRepositoryStatisticsManager( repositoryStatisticsManager );
metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
@@ -111,11 +115,18 @@ public class DeleteManagedRepositoryActionTest
respositorySession = mock( RepositorySession.class );
when( respositorySession.getRepository() ).thenReturn( metadataRepository );
- //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
+
TestRepositorySessionFactory factory = new TestRepositorySessionFactory();
factory.setRepositorySession( respositorySession );
action.setRepositorySessionFactory( factory );
+ ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration );
+ ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager );
+ ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
+ repositoryStatisticsManager );
+ ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory );
+ action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
+
metadataRepositoryControl.replay();
}
@@ -229,6 +240,8 @@ public class DeleteManagedRepositoryActionTest
control.setMatcher( new AuditEventArgumentsMatcher() );
control.replay();
action.setAuditListeners( Arrays.asList( listener ) );
+
+ ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners( Arrays.asList( listener ) );
return control;
}
@@ -438,4 +451,9 @@ public class DeleteManagedRepositoryActionTest
roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
roleManagerControl.replay();
}
+
+ protected ManagedRepositoryAdmin getManagedRepositoryAdmin()
+ {
+ return applicationContext.getBean( ManagedRepositoryAdmin.class );
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/log4j.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/log4j.xml
index cbba76e6c..cfc55587e 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/log4j.xml
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/log4j.xml
@@ -44,6 +44,10 @@
<level value="error"/>
</logger>
+ <logger name="org.apache.archiva.admin.repository.managed">
+ <level value="debug"/>
+ </logger>
+
<root>
<priority value ="info" />
<appender-ref ref="console" />
diff --git a/pom.xml b/pom.xml
index 6f9f0c49f..13d6174ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1458,7 +1458,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>