[MRM-1506] api to configure RemoteRepository : implementation of update method

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165210 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-05 08:53:47 +00:00
parent a79716d2eb
commit 15ce0477fe
2 changed files with 100 additions and 10 deletions

View File

@ -85,20 +85,13 @@ public class DefaultRemoteRepositoryAdmin
//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() );
RemoteRepositoryConfiguration remoteRepositoryConfiguration =
getRemoteRepositoryConfiguration( remoteRepository );
Configuration configuration = getArchivaConfiguration().getConfiguration();
configuration.addRemoteRepository( remoteRepositoryConfiguration );
saveConfiguration( configuration );
return Boolean.TRUE;
}
@ -138,6 +131,43 @@ public class DefaultRemoteRepositoryAdmin
public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
throws RepositoryAdminException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
String repositoryId = remoteRepository.getId();
triggerAuditEvent( repositoryId, null, AuditEvent.MODIFY_REMOTE_REPO, auditInformation );
// update means : remove and add
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 );
remoteRepositoryConfiguration = getRemoteRepositoryConfiguration( remoteRepository );
configuration.addRemoteRepository( remoteRepositoryConfiguration );
saveConfiguration( configuration );
return Boolean.TRUE;
}
private RemoteRepositoryConfiguration getRemoteRepositoryConfiguration( RemoteRepository remoteRepository )
{
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() );
return remoteRepositoryConfiguration;
}
}

View File

@ -92,7 +92,67 @@ public class RemoteRepositoryAdminTest
assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
}
@Test
public void addAndUpdateAndDelete()
throws Exception
{
mockAuditListener.clearEvents();
int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
RemoteRepository remoteRepository = getRemoteRepository();
remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
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() );
repo.setUserName( "foo-name-changed" );
repo.setPassword( "titi" );
repo.setUrl( "http://foo.com/maven-really-rocks" );
remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() );
repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
assertEquals( "foo-name-changed", repo.getUserName() );
assertEquals( "titi", repo.getPassword() );
assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() );
remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
assertNull( repo );
assertEquals( 3, mockAuditListener.getAuditEvents().size() );
assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get(1 ).getRemoteIP() );
assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
}