add rest service to get artifacts number per repository

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1388174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-09-20 19:42:21 +00:00
parent 18ef59174e
commit 8f64c48ccf
3 changed files with 151 additions and 88 deletions

View File

@ -106,8 +106,7 @@ public interface BrowseService
* <b>the List result has only one entry</b>
*/
List<TreeEntry> getTreeEntries( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
@PathParam ( "v" ) String version,
@QueryParam ( "repositoryId" ) String repositoryId )
@PathParam ("v") String version, @QueryParam ("repositoryId") String repositoryId )
throws ArchivaRestServiceException;
@Path ("dependees/{g}/{a}/{v}")
@ -155,8 +154,7 @@ public interface BrowseService
@PathParam ("a") String artifactId,
@PathParam ("v") String version,
@QueryParam ("c") String classifier,
@QueryParam ( "t" ) String type,
@QueryParam ( "p" ) String path,
@QueryParam ("t") String type, @QueryParam ("p") String path,
@QueryParam ("repositoryId") String repositoryId )
throws ArchivaRestServiceException;
@ -193,4 +191,19 @@ public interface BrowseService
Boolean artifactAvailable( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
@PathParam ("v") String version, @QueryParam ("repositoryId") String repositoryId )
throws ArchivaRestServiceException;
@Path ("artifactsNumber/{r}")
@GET
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@RedbackAuthorization (noPermission = true, noRestriction = true)
/**
*
* return artifacts number in a repository
* @param repositoryId
* @return
* @throws ArchivaRestServiceException
* @since 1.4-M3
*/
Integer getArtifactsNumber( @PathParam ( "r" ) String repositoryId )
throws ArchivaRestServiceException;
}

View File

@ -51,7 +51,6 @@ import org.apache.archiva.rest.api.model.Entry;
import org.apache.archiva.rest.api.model.VersionsList;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.BrowseService;
import org.apache.archiva.rest.services.utils.ArtifactBuilder;
import org.apache.archiva.rest.services.utils.ArtifactContentEntryComparator;
import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.commons.collections.CollectionUtils;
@ -62,6 +61,7 @@ import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import java.io.File;
import java.io.IOException;
@ -830,6 +830,24 @@ public class DefaultBrowseService
return false;
}
public Integer getArtifactsNumber( String repositoryId )
throws ArchivaRestServiceException
{
RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
return repositorySession.getRepository().getArtifacts( repositoryId ).size();
}
catch ( MetadataRepositoryException e )
{
throw new ArchivaRestServiceException( e.getMessage(), e );
}
finally
{
repositorySession.close();
}
}
//---------------------------
// internals
//---------------------------

View File

@ -18,8 +18,8 @@ package org.apache.archiva.rest.services;
* under the License.
*/
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.rest.api.model.ArtifactContentEntry;
import org.apache.archiva.rest.api.model.BrowseResult;
import org.apache.archiva.rest.api.model.BrowseResultEntry;
@ -428,4 +428,36 @@ public class BrowseServiceTest
}
@Test
public void artifactsNumber()
throws Exception
{
String testRepoId = "test-repo";
// force guest user creation if not exists
if ( getUserService( authorizationHeader ).getGuestUser() == null )
{
assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
}
createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath(), false );
BrowseService browseService = getBrowseService( authorizationHeader, true );
//WebClient.client( browseService ).accept( MediaType.TEXT_PLAIN );
try
{
int number = browseService.getArtifactsNumber( testRepoId );
log.info( "getArtifactsNumber: {}", number );
assertTrue( number > 1 );
}
catch ( Exception e )
{
log.error( e.getMessage(), e );
throw e;
}
}
}