archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1165041 - in /archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src: main/java/org/apache/archiva/admin/repository/managed/ main/java/org/apache/archiva/admin/repository/remote/ test/java/org/apache/archiva/admin/reposito...
Date Sun, 04 Sep 2011 14:53:33 GMT
Author: olamy
Date: Sun Sep  4 14:53:33 2011
New Revision: 1165041

URL: http://svn.apache.org/viewvc?rev=1165041&view=rev
Log:
[MRM-1506] api to configure RemoteRepository : implementation of add and delete

Modified:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java?rev=1165041&r1=1165040&r2=1165041&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
Sun Sep  4 14:53:33 2011
@@ -19,10 +19,9 @@ package org.apache.archiva.admin.reposit
  */
 
 import org.apache.archiva.admin.AuditInformation;
+import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
-import org.apache.archiva.admin.repository.RepositoryCommonValidator;
 import org.apache.archiva.audit.AuditEvent;
-import org.apache.archiva.audit.AuditListener;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
 import org.apache.archiva.metadata.repository.RepositorySession;
@@ -34,16 +33,11 @@ import org.apache.archiva.security.Archi
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.validator.GenericValidator;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 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.registry.Registry;
-import org.codehaus.plexus.registry.RegistryException;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
 import org.codehaus.redback.components.scheduler.CronExpressionValidator;
 import org.slf4j.Logger;
@@ -67,6 +61,7 @@ import java.util.Map;
  */
 @Service( "managedRepositoryAdmin#default" )
 public class DefaultManagedRepositoryAdmin
+    extends AbstractRepositoryAdmin
     implements ManagedRepositoryAdmin
 {
 
@@ -76,12 +71,6 @@ public class DefaultManagedRepositoryAdm
 
     public static final String STAGE_REPO_ID_END = "-stage";
 
-    @Inject
-    private ArchivaConfiguration archivaConfiguration;
-
-    @Inject
-    @Named( value = "commons-configuration" )
-    private Registry registry;
 
     @Inject
     @Named( value = "archivaTaskScheduler#repository" )
@@ -93,11 +82,6 @@ public class DefaultManagedRepositoryAdm
     @Inject
     private RepositoryStatisticsManager repositoryStatisticsManager;
 
-    @Inject
-    private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
-
-    @Inject
-    private RepositoryCommonValidator repositoryCommonValidator;
 
     @Inject
     protected RoleManager roleManager;
@@ -145,7 +129,7 @@ public class DefaultManagedRepositoryAdm
         throws RepositoryAdminException
     {
 
-        repositoryCommonValidator.basicValidation( managedRepository, false );
+        getRepositoryCommonValidator().basicValidation( managedRepository, false );
         triggerAuditEvent( managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO,
auditInformation );
         return
             addManagedRepository( managedRepository.getId(), managedRepository.getLayout(),
managedRepository.getName(),
@@ -184,7 +168,7 @@ public class DefaultManagedRepositoryAdm
             throw new RepositoryAdminException( "Cron expression cannot be empty." );
         }
 
-        String repoLocation = repositoryCommonValidator.removeExpressions( location );
+        String repoLocation = getRepositoryCommonValidator().removeExpressions( location
);
 
         if ( !GenericValidator.matchRegexp( repoLocation, REPOSITORY_LOCATION_VALID_EXPRESSION
) )
         {
@@ -379,7 +363,7 @@ public class DefaultManagedRepositoryAdm
 
         // Ensure that the fields are valid.
 
-        repositoryCommonValidator.basicValidation( managedRepository, true );
+        getRepositoryCommonValidator().basicValidation( managedRepository, true );
 
         Configuration configuration = getArchivaConfiguration().getConfiguration();
 
@@ -446,38 +430,6 @@ public class DefaultManagedRepositoryAdm
     // utils methods
     //--------------------------
 
-    protected void triggerAuditEvent( String repositoryId, String resource, String action,
-                                      AuditInformation auditInformation )
-    {
-        User user = auditInformation == null ? null : auditInformation.getUser();
-        AuditEvent event =
-            new AuditEvent( repositoryId, user == null ? "null" : (String) user.getPrincipal(),
resource, action );
-        event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr()
);
-
-        for ( AuditListener listener : getAuditListeners() )
-        {
-            listener.auditEvent( event );
-        }
-
-    }
-
-
-    private void saveConfiguration( Configuration config )
-        throws RepositoryAdminException
-    {
-        try
-        {
-            getArchivaConfiguration().save( config );
-        }
-        catch ( RegistryException e )
-        {
-            throw new RepositoryAdminException( "Error occurred in the registry.", e );
-        }
-        catch ( IndeterminateConfigurationException e )
-        {
-            throw new RepositoryAdminException( "Error occurred while saving the configuration.",
e );
-        }
-    }
 
     protected void addRepository( ManagedRepositoryConfiguration repository, Configuration
configuration )
         throws RepositoryAdminException, IOException
@@ -581,15 +533,6 @@ public class DefaultManagedRepositoryAdm
     // setters/getters
     //--------------------------
 
-    public ArchivaConfiguration getArchivaConfiguration()
-    {
-        return archivaConfiguration;
-    }
-
-    public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
-    {
-        this.archivaConfiguration = archivaConfiguration;
-    }
 
     public RoleManager getRoleManager()
     {
@@ -621,15 +564,6 @@ public class DefaultManagedRepositoryAdm
         this.repositorySessionFactory = repositorySessionFactory;
     }
 
-    public List<AuditListener> getAuditListeners()
-    {
-        return auditListeners;
-    }
-
-    public void setAuditListeners( List<AuditListener> auditListeners )
-    {
-        this.auditListeners = auditListeners;
-    }
 
     public RepositoryArchivaTaskScheduler getRepositoryTaskScheduler()
     {
@@ -640,24 +574,4 @@ public class DefaultManagedRepositoryAdm
     {
         this.repositoryTaskScheduler = repositoryTaskScheduler;
     }
-
-    public Registry getRegistry()
-    {
-        return registry;
-    }
-
-    public void setRegistry( Registry registry )
-    {
-        this.registry = registry;
-    }
-
-    public RepositoryCommonValidator getRepositoryCommonValidator()
-    {
-        return repositoryCommonValidator;
-    }
-
-    public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator
)
-    {
-        this.repositoryCommonValidator = repositoryCommonValidator;
-    }
 }

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java?rev=1165041&r1=1165040&r2=1165041&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
Sun Sep  4 14:53:33 2011
@@ -18,13 +18,14 @@ package org.apache.archiva.admin.reposit
  * under the License.
  */
 
+import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
 import org.springframework.stereotype.Service;
 
-import javax.inject.Inject;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -34,16 +35,16 @@ import java.util.List;
  */
 @Service( "remoteRepositoryAdmin#default" )
 public class DefaultRemoteRepositoryAdmin
+    extends AbstractRepositoryAdmin
     implements RemoteRepositoryAdmin
 {
-    @Inject
-    private ArchivaConfiguration archivaConfiguration;
+
 
     public List<RemoteRepository> getRemoteRepositories()
         throws RepositoryAdminException
     {
         List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();
-        for ( RemoteRepositoryConfiguration repositoryConfiguration : archivaConfiguration.getConfiguration().getRemoteRepositories()
)
+        for ( RemoteRepositoryConfiguration repositoryConfiguration : getArchivaConfiguration().getConfiguration().getRemoteRepositories()
)
         {
             remoteRepositories.add(
                 new RemoteRepository( repositoryConfiguration.getId(), repositoryConfiguration.getName(),
@@ -67,16 +68,63 @@ public class DefaultRemoteRepositoryAdmi
         return null;
     }
 
-    public Boolean deleteRemoteRepository( String repositoryId )
+    public Boolean addRemoteRepository( RemoteRepository remoteRepository )
         throws RepositoryAdminException
     {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        getRepositoryCommonValidator().basicValidation( remoteRepository, false );
+
+        //TODO we can validate it's a good uri/url
+        if ( StringUtils.isEmpty( remoteRepository.getUrl() ) )
+        {
+            throw new RepositoryAdminException( "url cannot be null" );
+        }
+
+        //MRM-752 - url needs trimming
+        remoteRepository.setUrl( StringUtils.trim( remoteRepository.getUrl() ) );
+
+        RemoteRepositoryConfiguration remoteRepositoryConfiguration = new RemoteRepositoryConfiguration();
+        remoteRepositoryConfiguration.setId( remoteRepository.getId() );
+        remoteRepositoryConfiguration.setPassword( remoteRepository.getPassword() );
+        remoteRepositoryConfiguration.setTimeout( remoteRepository.getTimeout() );
+        remoteRepositoryConfiguration.setUrl( remoteRepository.getUrl() );
+        remoteRepositoryConfiguration.setUsername( remoteRepository.getUserName() );
+        remoteRepositoryConfiguration.setLayout( remoteRepository.getLayout() );
+        remoteRepositoryConfiguration.setName( remoteRepository.getName() );
+
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        configuration.addRemoteRepository( remoteRepositoryConfiguration );
+        saveConfiguration( configuration );
+        return Boolean.TRUE;
     }
 
-    public Boolean addRemoteRepository( RemoteRepository remoteRepository )
+    public Boolean deleteRemoteRepository( String repositoryId )
         throws RepositoryAdminException
     {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+        RemoteRepositoryConfiguration remoteRepositoryConfiguration =
+            configuration.getRemoteRepositoriesAsMap().get( repositoryId );
+        if ( remoteRepositoryConfiguration == null )
+        {
+            throw new RepositoryAdminException(
+                "remoteRepository with id " + repositoryId + " not exist cannot remove it"
);
+        }
+
+        configuration.removeRemoteRepository( remoteRepositoryConfiguration );
+
+        // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
+        List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
+        for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
+        {
+            if ( StringUtils.equals( proxyConnector.getTargetRepoId(), repositoryId ) )
+            {
+                configuration.removeProxyConnector( proxyConnector );
+            }
+        }
+
+        saveConfiguration( configuration );
+
+        return Boolean.TRUE;
     }
 
     public Boolean updateRemoteRepository( RemoteRepository remoteRepository )

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java?rev=1165041&r1=1165040&r2=1165041&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java
Sun Sep  4 14:53:33 2011
@@ -55,4 +55,45 @@ public class RemoteRepositoryAdminTest
         assertNull( central.getUserName() );
         assertNull( central.getPassword() );
     }
+
+    @Test
+    public void addAndDelete()
+        throws Exception
+    {
+        int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
+
+        RemoteRepository remoteRepository = getRemoteRepository();
+
+        remoteRepositoryAdmin.addRemoteRepository( remoteRepository );
+
+        assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size()
);
+
+        RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
+        assertNotNull( repo );
+        assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
+        assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
+        assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
+        assertEquals( getRemoteRepository().getName(), repo.getName() );
+        assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
+
+        remoteRepositoryAdmin.deleteRemoteRepository( "foo" );
+
+        assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
+
+        repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
+        assertNull( repo );
+    }
+
+
+    private RemoteRepository getRemoteRepository()
+    {
+        RemoteRepository remoteRepository = new RemoteRepository();
+        remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
+        remoteRepository.setTimeout( 10 );
+        remoteRepository.setName( "maven foo" );
+        remoteRepository.setUserName( "foo-name" );
+        remoteRepository.setPassword( "toto" );
+        remoteRepository.setId( "foo" );
+        return remoteRepository;
+    }
 }



Mime
View raw message