[MRM-1490] Expose Archiva services trough REST : remote repository management available tru rest service

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165278 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-05 13:25:30 +00:00
parent 45698e6363
commit 86d521a12b
10 changed files with 108 additions and 73 deletions

View File

@ -54,6 +54,14 @@ public class RemoteRepository
this.layout = layout;
}
public RemoteRepository( String id, String name, String url, String layout, String userName, String password,
int timeOut )
{
this( id, name, url, layout );
this.userName = userName;
this.password = password;
this.timeOut = timeOut;
}
public String getId()
{

View File

@ -19,7 +19,6 @@ package org.apache.archiva.rest.api.services;
* under the License.
*/
import org.apache.archiva.rest.api.model.RemoteRepository;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
@ -29,7 +28,6 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
/**
* @author Olivier Lamy
@ -39,13 +37,6 @@ import java.util.List;
public interface RepositoriesService
{
@Path( "getRemoteRepositories" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
List<RemoteRepository> getRemoteRepositories();
@Path( "scanRepository" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )

View File

@ -47,14 +47,4 @@ public abstract class AbstractRestService
String remoteAddr = redbackRequestInformation == null ? null : redbackRequestInformation.getRemoteAddr();
return new AuditInformation( user, remoteAddr );
}
public List<AuditListener> getAuditListeners()
{
return auditListeners;
}
public void setAuditListeners( List<AuditListener> auditListeners )
{
this.auditListeners = auditListeners;
}
}

View File

@ -26,7 +26,6 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.ws.rs.PathParam;
import java.util.ArrayList;
import java.util.List;
@ -58,7 +57,7 @@ public class DefaultRemoteRepositoriesService
return remoteRepositories;
}
public RemoteRepository getRemoteRepository( @PathParam( "repositoryId" ) String repositoryId )
public RemoteRepository getRemoteRepository( String repositoryId )
throws RepositoryAdminException
{
List<RemoteRepository> remoteRepositories = getRemoteRepositories();
@ -72,7 +71,7 @@ public class DefaultRemoteRepositoriesService
return null;
}
public Boolean deleteRemoteRepository( @PathParam( "repositoryId" ) String repositoryId )
public Boolean deleteRemoteRepository( String repositoryId )
throws Exception
{
return remoteRepositoryAdmin.deleteRemoteRepository( repositoryId, getAuditInformation() );

View File

@ -84,24 +84,6 @@ public class DefaultRepositoriesService
@Inject
private ManagedRepositoryAdmin managedRepositoryAdmin;
public List<RemoteRepository> getRemoteRepositories()
{
Configuration config = archivaConfiguration.getConfiguration();
List<RemoteRepositoryConfiguration> remoteRepoConfigs = config.getRemoteRepositories();
List<RemoteRepository> remoteRepos = new ArrayList<RemoteRepository>( remoteRepoConfigs.size() );
for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
{
RemoteRepository repo = new RemoteRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl(),
repoConfig.getLayout() );
remoteRepos.add( repo );
}
return remoteRepos;
}
// FIXME olamy move this to repository admin component !
public Boolean scanRepository( String repositoryId, boolean fullScan )
{

View File

@ -51,6 +51,7 @@
<ref bean="pingService#rest"/>
<ref bean="repositoriesService#rest"/>
<ref bean="managedRepositoriesService#rest"/>
<ref bean="remoteRepositoriesService#rest"/>
</jaxrs:serviceBeans>
<jaxrs:outInterceptors>

View File

@ -21,6 +21,7 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.archiva.rest.api.services.PingService;
import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.codehaus.redback.rest.services.AbstractRestServicesTest;
@ -58,6 +59,13 @@ public abstract class AbstractArchivaRestTest
{
return JAXRSClientFactory.create( "http://localhost:" + port + "/services/archivaServices/",
PingService.class );
}
protected RemoteRepositoriesService getRemoteRepositoriesService()
{
return JAXRSClientFactory.create( "http://localhost:" + port + "/services/archivaServices/",
RemoteRepositoriesService.class );
}
}

View File

@ -50,6 +50,9 @@ public class ManagedRepositoriesServiceTest
}
service.addManagedRepository( repo );
assertNotNull( service.getManagedRepository( repo.getId() ) );
service.deleteManagedRepository( repo.getId(), true );
assertNull( service.getManagedRepository( repo.getId() ) );
}
@Test
@ -78,6 +81,10 @@ public class ManagedRepositoriesServiceTest
assertNotNull( repo );
assertEquals( "toto", repo.getName() );
service.deleteManagedRepository( repo.getId(), true );
assertNull( service.getManagedRepository( repo.getId() ) );
}

View File

@ -65,5 +65,87 @@ public class RemoteRepositoriesServiceTest
}
@Test
public void addAndDeleteRemoteRepository()
throws Exception
{
RemoteRepositoriesService service = getRemoteRepositoriesService();
WebClient.client( service ).header( "Authorization", authorizationHeader );
int initialSize = service.getRemoteRepositories().size();
service.addRemoteRepository( getRemoteRepository() );
assertNotNull( service.getRemoteRepository( "id-new" ) );
assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
assertEquals( getRemoteRepository().getTimeOut(), service.getRemoteRepository( "id-new" ).getTimeOut() );
assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
service.deleteRemoteRepository( "id-new" );
assertNull( service.getRemoteRepository( "id-new" ) );
assertEquals( initialSize, service.getRemoteRepositories().size() );
}
@Test
public void addAndUpdateAndDeleteRemoteRepository()
throws Exception
{
RemoteRepositoriesService service = getRemoteRepositoriesService();
WebClient.client( service ).header( "Authorization", authorizationHeader );
int initialSize = service.getRemoteRepositories().size();
service.addRemoteRepository( getRemoteRepository() );
assertNotNull( service.getRemoteRepository( "id-new" ) );
assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
assertEquals( getRemoteRepository().getTimeOut(), service.getRemoteRepository( "id-new" ).getTimeOut() );
assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
RemoteRepository repo = getRemoteRepository();
repo.setName( "name changed" );
repo.setPassword( "new password" );
repo.setUserName( "new username" );
repo.setUrl( "http://foo.new.org" );
service.updateRemoteRepository( repo );
assertEquals( repo.getName(), service.getRemoteRepository( "id-new" ).getName() );
assertEquals( repo.getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
assertEquals( repo.getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
assertEquals( repo.getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
assertEquals( repo.getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
assertEquals( repo.getTimeOut(), service.getRemoteRepository( "id-new" ).getTimeOut() );
service.deleteRemoteRepository( "id-new" );
assertNull( service.getRemoteRepository( "id-new" ) );
assertEquals( initialSize, service.getRemoteRepositories().size() );
}
RemoteRepository getRemoteRepository()
{
return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120 );
}
}

View File

@ -20,7 +20,6 @@ package org.apache.archiva.rest.services;
*/
import org.apache.archiva.rest.api.model.ManagedRepository;
import org.apache.archiva.rest.api.model.RemoteRepository;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
@ -29,7 +28,6 @@ import org.apache.maven.archiva.common.utils.FileUtil;
import org.junit.Test;
import java.io.File;
import java.util.List;
/**
* @author Olivier Lamy
@ -38,37 +36,6 @@ public class RepositoriesServiceTest
extends AbstractArchivaRestTest
{
@Test( expected = ServerWebApplicationException.class )
public void listRemoteRepositoriesKarmaFailed()
throws Exception
{
RepositoriesService service = getRepositoriesService();
try
{
assertFalse( service.getRemoteRepositories().isEmpty() );
}
catch ( ServerWebApplicationException e )
{
assertEquals( 403, e.getStatus() );
throw e;
}
}
@Test
public void listRemoteRepositoriesKarma()
throws Exception
{
RepositoriesService service = getRepositoriesService();
WebClient.client( service ).header( "Authorization", authorizationHeader );
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
List<RemoteRepository> repos = service.getRemoteRepositories();
assertFalse( repos.isEmpty() );
log.info( "repos {}", repos );
}
@Test( expected = ServerWebApplicationException.class )
public void scanRepoKarmaFailed()
throws Exception