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.managed.ManagedRepository;
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.commons.lang.StringUtils;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
if ( repositoryGroup.getRepositories().contains( repositoryId ) )
{
- log.info( "repositoryGroup {} already contains repository {} so skip adding it" );
- return Boolean.TRUE;
+ throw new RepositoryAdminException(
+ "repositoryGroup with id " + repositoryGroupId + " already contain repository with id" + repositoryId );
}
validateManagedRepositoriesExists( Arrays.asList( repositoryId ) );
if ( !repositoryGroup.getRepositories().contains( repositoryId ) )
{
- log.info( "repositoryGroup {} already contains repository {} so skip removing it" );
- return Boolean.TRUE;
+ throw new RepositoryAdminException(
+ "repositoryGroup with id " + repositoryGroupId + " doesn't not contains repository with id"
+ + repositoryId );
}
repositoryGroup.removeRepository( repositoryId );
return Boolean.TRUE;
}
+ public Map<String, RepositoryGroup> getRepositoryGroupsAsMap()
+ throws RepositoryAdminException
+ {
+ List<RepositoryGroup> repositoriesGroups = getRepositoriesGroups();
+ Map<String, RepositoryGroup> map = new HashMap<String, RepositoryGroup>( repositoriesGroups.size() );
+ for ( RepositoryGroup repositoryGroup : repositoriesGroups )
+ {
+ map.put( repositoryGroup.getId(), repositoryGroup );
+ }
+ return map;
+ }
+
+ public Map<String, List<String>> getGroupToRepositoryMap()
+ throws RepositoryAdminException
+ {
+
+ java.util.Map<String, java.util.List<String>> map = new java.util.HashMap<String, java.util.List<String>>();
+
+ for ( ManagedRepository repo : getManagedRepositoryAdmin().getManagedRepositories() )
+ {
+ for ( RepositoryGroup group : getRepositoriesGroups() )
+ {
+ if ( !group.getRepositories().contains( repo.getId() ) )
+ {
+ String groupId = group.getId();
+ java.util.List<String> repos = map.get( groupId );
+ if ( repos == null )
+ {
+ repos = new java.util.ArrayList<String>();
+ map.put( groupId, repos );
+ }
+ repos.add( repo.getId() );
+ }
+ }
+ }
+ return map;
+ }
+
+ public Map<String, List<String>> getRepositoryToGroupMap()
+ throws RepositoryAdminException
+ {
+ java.util.Map<String, java.util.List<String>> map = new java.util.HashMap<String, java.util.List<String>>();
+
+ for ( RepositoryGroup group : getRepositoriesGroups() )
+ {
+ for ( String repositoryId : group.getRepositories() )
+ {
+ java.util.List<String> groups = map.get( repositoryId );
+ if ( groups == null )
+ {
+ groups = new java.util.ArrayList<String>();
+ map.put( repositoryId, groups );
+ }
+ groups.add( group.getId() );
+ }
+ }
+ return map;
+ }
+
public Boolean validateRepositoryGroup( RepositoryGroup repositoryGroup, boolean updateMode )
throws RepositoryAdminException
{
import org.apache.archiva.admin.repository.RepositoryAdminException;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId,
AuditInformation auditInformation )
throws RepositoryAdminException;
+
+ /**
+ * @return Map with key repoGroupId and value repoGroup
+ * @throws RepositoryAdminException
+ */
+ Map<String, RepositoryGroup> getRepositoryGroupsAsMap()
+ throws RepositoryAdminException;
+
+ /**
+ * @return Map with key repoGroupId and value List of ManagedRepositories
+ * @throws RepositoryAdminException
+ */
+ Map<String, List<String>> getGroupToRepositoryMap()
+ throws RepositoryAdminException;
+
+ /**
+ * @return Map with key managedRepo id and value List of repositoryGroup ids where the repo is
+ * @throws RepositoryAdminException
+ */
+ Map<String, List<String>> getRepositoryToGroupMap()
+ throws RepositoryAdminException;
}
import com.opensymphony.xwork2.Preparable;
import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.group.RepositoryGroupAdmin;
import org.apache.archiva.admin.repository.managed.ManagedRepository;
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.remote.RemoteRepository;
@Inject
private RemoteRepositoryAdmin remoteRepositoryAdmin;
+ @Inject
+ private RepositoryGroupAdmin repositoryGroupAdmin;
+
private List<ManagedRepository> managedRepositories;
private List<RemoteRepository> remoteRepositories;
remoteRepositories = new ArrayList<RemoteRepository>( getRemoteRepositoryAdmin().getRemoteRepositories() );
managedRepositories = new ArrayList<ManagedRepository>( getManagedRepositoryAdmin().getManagedRepositories() );
- repositoryToGroupMap = config.getRepositoryToGroupMap();
+ repositoryToGroupMap = getRepositoryGroupAdmin().getRepositoryToGroupMap();
Collections.sort( managedRepositories, new RepositoryComparator() );
Collections.sort( remoteRepositories, new RepositoryComparator() );
{
this.remoteRepositoryAdmin = remoteRepositoryAdmin;
}
+
+ public RepositoryGroupAdmin getRepositoryGroupAdmin()
+ {
+ return repositoryGroupAdmin;
+ }
+
+ public void setRepositoryGroupAdmin( RepositoryGroupAdmin repositoryGroupAdmin )
+ {
+ this.repositoryGroupAdmin = repositoryGroupAdmin;
+ }
+
+ public RepositoryStatisticsManager getRepositoryStatisticsManager()
+ {
+ return repositoryStatisticsManager;
+ }
+
+ public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
+ {
+ this.repositoryStatisticsManager = repositoryStatisticsManager;
+ }
}
import com.opensymphony.xwork2.Preparable;
import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.group.RepositoryGroup;
+import org.apache.archiva.admin.repository.group.RepositoryGroupAdmin;
import org.apache.archiva.admin.repository.managed.ManagedRepository;
-import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.web.util.ContextUtils;
-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.RepositoryGroupConfiguration;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
+import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
extends AbstractRepositoriesAdminAction
implements ServletRequestAware, Preparable
{
- private RepositoryGroupConfiguration repositoryGroup;
- private Map<String, RepositoryGroupConfiguration> repositoryGroups;
+ @Inject
+ private RepositoryGroupAdmin repositoryGroupAdmin;
+
+ private RepositoryGroup repositoryGroup;
+
+ private Map<String, RepositoryGroup> repositoryGroups;
private Map<String, ManagedRepository> managedRepositories;
public void prepare()
throws RepositoryAdminException
{
- Configuration config = archivaConfiguration.getConfiguration();
- repositoryGroup = new RepositoryGroupConfiguration();
- repositoryGroups = config.getRepositoryGroupsAsMap();
+ repositoryGroup = new RepositoryGroup();
+ repositoryGroups = getRepositoryGroupAdmin().getRepositoryGroupsAsMap();
managedRepositories = getManagedRepositoryAdmin().getManagedRepositoriesAsMap();
- groupToRepositoryMap = config.getGroupToRepositoryMap();
+ groupToRepositoryMap = getRepositoryGroupAdmin().getGroupToRepositoryMap();
}
public String addRepositoryGroup()
{
- Configuration configuration = archivaConfiguration.getConfiguration();
-
- String repoGroupId = repositoryGroup.getId();
-
- if ( repoGroupId == null || "".equals( repoGroupId.trim() ) )
- {
- addActionError( "Identifier field is required." );
- return ERROR;
- }
-
- if ( repoGroupId.length() > 100 )
+ try
{
- addActionError( "Identifier [" + repoGroupId + "] is over the maximum limit of 100 characters" );
- return ERROR;
+ getRepositoryGroupAdmin().addRepositoryGroup( repositoryGroup, getAuditInformation() );
}
-
- Matcher matcher = REPO_GROUP_ID_PATTERN.matcher( repoGroupId );
- if ( !matcher.matches() )
- {
- addActionError(
- "Invalid character(s) found in identifier. Only the following characters are allowed: alphanumeric, '.', '-' and '_'" );
- return ERROR;
- }
-
- if ( StringUtils.isBlank( repoGroupId ) )
+ catch ( RepositoryAdminException e )
{
- addActionError( "You must enter a repository group id." );
+ addActionError( e.getMessage() );
return ERROR;
}
- if ( configuration.getRepositoryGroupsAsMap().containsKey( repoGroupId ) )
- {
- addActionError( "Unable to add new repository group with id [" + repoGroupId
- + "], that id already exists as a repository group." );
- return ERROR;
- }
- else if ( configuration.getManagedRepositoriesAsMap().containsKey( repoGroupId ) )
- {
- addActionError( "Unable to add new repository group with id [" + repoGroupId
- + "], that id already exists as a managed repository." );
- return ERROR;
- }
- else if ( configuration.getRemoteRepositoriesAsMap().containsKey( repoGroupId ) )
- {
- addActionError( "Unable to add new repository group with id [" + repoGroupId
- + "], that id already exists as a remote repository." );
- return ERROR;
- }
-
- configuration.addRepositoryGroup( repositoryGroup );
- triggerAuditEvent( AuditEvent.ADD_REPO_GROUP + " " + repoGroupId );
- return saveConfiguration( configuration );
+ return SUCCESS;
}
public String addRepositoryToGroup()
{
- Configuration config = archivaConfiguration.getConfiguration();
- RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
-
- validateRepository();
-
- if ( hasErrors() )
+ try
{
- return ERROR;
+ getRepositoryGroupAdmin().addRepositoryToGroup( repoGroupId, repoId, getAuditInformation() );
}
-
- if ( group.getRepositories().contains( repoId ) )
+ catch ( RepositoryAdminException e )
{
- addActionError( "Repository with id [" + repoId + "] is already in the group" );
+ addActionError( e.getMessage() );
return ERROR;
}
-
- // remove the old repository group configuration
- config.removeRepositoryGroup( group );
-
- // save repository group configuration
- group.addRepository( repoId );
- config.addRepositoryGroup( group );
-
- triggerAuditEvent( repoId, null, AuditEvent.ADD_REPO_TO_GROUP + " " + repoGroupId );
-
- return saveConfiguration( config );
+ return SUCCESS;
}
public String removeRepositoryFromGroup()
{
- Configuration config = archivaConfiguration.getConfiguration();
- RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
-
- validateRepository();
-
- if ( hasErrors() )
+ try
{
- return ERROR;
+ getRepositoryGroupAdmin().deleteRepositoryFromGroup( repoGroupId, repoId, getAuditInformation() );
}
-
- if ( !group.getRepositories().contains( repoId ) )
+ catch ( RepositoryAdminException e )
{
- addActionError( "No repository with id[" + repoId + "] found in the group" );
+ addActionError( e.getMessage() );
return ERROR;
}
-
- // remove the old repository group configuration
- config.removeRepositoryGroup( group );
-
- // save repository group configuration
- group.removeRepository( repoId );
- config.addRepositoryGroup( group );
-
- triggerAuditEvent( repoId, null, AuditEvent.DELETE_REPO_FROM_GROUP + " " + repoGroupId );
-
- return saveConfiguration( config );
+ return SUCCESS;
}
- public void validateRepository()
- {
- Configuration config = archivaConfiguration.getConfiguration();
- RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
- ManagedRepositoryConfiguration repo = config.findManagedRepositoryById( repoId );
- if ( group == null )
- {
- addActionError( "A repository group with that id does not exist." );
- }
-
- if ( repo == null )
- {
- addActionError( "A repository with that id does not exist." );
- }
- }
-
- public RepositoryGroupConfiguration getRepositoryGroup()
+ public RepositoryGroup getRepositoryGroup()
{
return repositoryGroup;
}
- public void setRepositoryGroup( RepositoryGroupConfiguration repositoryGroup )
+ public void setRepositoryGroup( RepositoryGroup repositoryGroup )
{
this.repositoryGroup = repositoryGroup;
}
- public Map<String, RepositoryGroupConfiguration> getRepositoryGroups()
+ public Map<String, RepositoryGroup> getRepositoryGroups()
{
return repositoryGroups;
}
- public void setRepositoryGroups( Map<String, RepositoryGroupConfiguration> repositoryGroups )
+ public void setRepositoryGroups( Map<String, RepositoryGroup> repositoryGroups )
{
this.repositoryGroups = repositoryGroups;
}
{
return baseUrl;
}
+
+ public RepositoryGroupAdmin getRepositoryGroupAdmin()
+ {
+ return repositoryGroupAdmin;
+ }
+
+ public void setRepositoryGroupAdmin( RepositoryGroupAdmin repositoryGroupAdmin )
+ {
+ this.repositoryGroupAdmin = repositoryGroupAdmin;
+ }
}
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
import com.opensymphony.xwork2.Action;
+import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
throws Exception
{
super.setUp();
-
- //action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" );
action = (RepositoriesAction) getActionProxy( "/admin/index.action" ).getAction();
}
ServletUnitClient sc = sr.newClient();
action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositories.action" ).getRequest() );
+
action.prepare();
String result = action.execute();
assertEquals( Action.SUCCESS, result );
import com.meterware.servletunit.ServletUnitClient;
import com.opensymphony.xwork2.Action;
import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.group.DefaultRepositoryGroupAdmin;
+import org.apache.archiva.admin.repository.group.RepositoryGroup;
+import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
action.setArchivaConfiguration( archivaConfiguration );
+ ( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).setArchivaConfiguration(
+ archivaConfiguration );
+ ( (DefaultManagedRepositoryAdmin) ( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).getManagedRepositoryAdmin() ).setArchivaConfiguration(
+ archivaConfiguration );
}
public void testSecureActionBundle()
throws SecureActionException, RepositoryAdminException
{
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( new Configuration() );
+ archivaConfigurationControl.setReturnValue( new Configuration(), 3 );
archivaConfigurationControl.replay();
action.prepare();
{
Configuration configuration = new Configuration();
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration, 2 );
+ archivaConfigurationControl.setReturnValue( configuration, 6 );
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
action.prepare();
- RepositoryGroupConfiguration repositoryGroup = action.getRepositoryGroup();
+ RepositoryGroup repositoryGroup = action.getRepositoryGroup();
repositoryGroup.setId( REPO_GROUP_ID );
String status = action.addRepositoryGroup();
assertEquals( Action.SUCCESS, status );
- assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() );
+ assertEquals( Collections.singletonList( repositoryGroup ),
+ action.getRepositoryGroupAdmin().getRepositoriesGroups() );
archivaConfigurationControl.verify();
}
{
Configuration configuration = new Configuration();
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration, 2 );
+ archivaConfigurationControl.setReturnValue( configuration, 5 );
archivaConfiguration.save( configuration );
{
Configuration configuration = new Configuration();
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration, 3 );
+ archivaConfigurationControl.setReturnValue( configuration, 8 );
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
action.prepare();
- RepositoryGroupConfiguration repositoryGroup = action.getRepositoryGroup();
+ RepositoryGroup repositoryGroup = action.getRepositoryGroup();
repositoryGroup.setId( REPO_GROUP_ID );
String status = action.addRepositoryGroup();
assertEquals( Action.SUCCESS, status );
- assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() );
+ assertEquals( Collections.singletonList( repositoryGroup ),
+ action.getRepositoryGroupAdmin().getRepositoriesGroups() );
repositoryGroup.setId( REPO_GROUP_ID );
status = action.addRepositoryGroup();
assertEquals( Action.ERROR, status );
- assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() );
+ assertEquals( Collections.singletonList( repositoryGroup ),
+ action.getRepositoryGroupAdmin().getRepositoriesGroups() );
}
public void testGetRepositoryGroups()
Configuration configuration = createInitialConfiguration();
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration );
+ archivaConfigurationControl.setReturnValue( configuration, 6 );
archivaConfigurationControl.replay();
action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositoryGroups.action" ).getRequest() );
assertEquals( 1, action.getRepositoryGroups().size() );
assertEquals( 2, action.getManagedRepositories().size() );
- RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
+ RepositoryGroup repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
assertEquals( 1, repoGroup.getRepositories().size() );
assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) );
Configuration configuration = createInitialConfiguration();
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration, 6 );
+ archivaConfigurationControl.setReturnValue( configuration, 17 );
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
assertEquals( 1, action.getRepositoryGroups().size() );
assertEquals( 2, action.getManagedRepositories().size() );
- RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
+ RepositoryGroup repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
assertEquals( 1, repoGroup.getRepositories().size() );
assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) );
Configuration configuration = createInitialConfiguration();
archivaConfiguration.getConfiguration();
- archivaConfigurationControl.setReturnValue( configuration, 6 );
+ archivaConfigurationControl.setReturnValue( configuration, 13 );
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
assertEquals( 1, action.getRepositoryGroups().size() );
assertEquals( 2, action.getManagedRepositories().size() );
- RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
+ RepositoryGroup repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
assertEquals( 1, repoGroup.getRepositories().size() );
assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) );
assertEquals( 1, action.getRepositoryGroups().size() );
assertEquals( 2, action.getManagedRepositories().size() );
- RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
+ RepositoryGroup repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
assertEquals( 1, repoGroup.getRepositories().size() );
assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) );
assertEquals( 1, action.getRepositoryGroups().size() );
assertEquals( 2, action.getManagedRepositories().size() );
- RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
+ RepositoryGroup repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID );
assertEquals( 1, repoGroup.getRepositories().size() );
assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) );
<level value="error"/>
</logger>
+ <!-- reduce noise for unit tests -->
+
+ <logger name="org.springframework">
+ <level value="error"/>
+ </logger>
+
+ <logger name="org.codehaus.plexus">
+ <level value="error"/>
+ </logger>
+
+ <logger name="org.codehaus.redback">
+ <level value="error"/>
+ </logger>
+
+ <logger name="org.apache.cxf">
+ <level value="error"/>
+ </logger>
+
+ <logger name="org.quartz">
+ <level value="error"/>
+ </logger>
+
<root>
<priority value ="info" />
<appender-ref ref="console" />