mirror of https://github.com/apache/archiva.git
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:
parent
18ef59174e
commit
8f64c48ccf
|
@ -43,154 +43,167 @@ import java.util.List;
|
|||
* @author Olivier Lamy
|
||||
* @since 1.4-M3
|
||||
*/
|
||||
@Path ( "/browseService/" )
|
||||
@Path ("/browseService/")
|
||||
public interface BrowseService
|
||||
{
|
||||
@Path ( "rootGroups" )
|
||||
@Path ("rootGroups")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
BrowseResult getRootGroups( @QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
BrowseResult getRootGroups( @QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "browseGroupId/{groupId}" )
|
||||
@Path ("browseGroupId/{groupId}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
BrowseResult browseGroupId( @PathParam ( "groupId" ) String groupId,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
BrowseResult browseGroupId( @PathParam ("groupId") String groupId,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "versionsList/{g}/{a}" )
|
||||
@Path ("versionsList/{g}/{a}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
VersionsList getVersionsList( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
VersionsList getVersionsList( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "projectVersionMetadata/{g}/{a}" )
|
||||
@Path ("projectVersionMetadata/{g}/{a}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
ProjectVersionMetadata getProjectVersionMetadata( @PathParam ( "g" ) String groupId,
|
||||
@PathParam ( "a" ) String artifactId,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
ProjectVersionMetadata getProjectVersionMetadata( @PathParam ("g") String groupId,
|
||||
@PathParam ("a") String artifactId,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "projectVersionMetadata/{g}/{a}/{v}" )
|
||||
@Path ("projectVersionMetadata/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
ProjectVersionMetadata getProjectMetadata( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
ProjectVersionMetadata getProjectMetadata( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "userRepositories" )
|
||||
@Path ("userRepositories")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
/**
|
||||
* @return List of managed repositories current user can read
|
||||
*/
|
||||
List<ManagedRepository> getUserRepositories()
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "treeEntries/{g}/{a}/{v}" )
|
||||
@Path ("treeEntries/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
/**
|
||||
* return the dependency Tree for an artifacts
|
||||
* <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 )
|
||||
List<TreeEntry> getTreeEntries( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version, @QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "dependees/{g}/{a}/{v}" )
|
||||
@Path ("dependees/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
/**
|
||||
* List of artifacts using the artifact passed in parameter.
|
||||
*/
|
||||
List<Artifact> getDependees( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version, @QueryParam ( "repositoryId" ) String repositoryId )
|
||||
List<Artifact> getDependees( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version, @QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "metadatas/{g}/{a}/{v}" )
|
||||
@Path ("metadatas/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
List<Entry> getMetadatas( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version, @QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
List<Entry> getMetadatas( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version, @QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "metadata/{g}/{a}/{v}/{key}/{value}" )
|
||||
@Path ("metadata/{g}/{a}/{v}/{key}/{value}")
|
||||
@PUT
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = false, noRestriction = false, permissions = "archiva-add-metadata" )
|
||||
Boolean addMetadata( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version, @PathParam ( "key" ) String key,
|
||||
@PathParam ( "value" ) String value, @QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = false, noRestriction = false, permissions = "archiva-add-metadata")
|
||||
Boolean addMetadata( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version, @PathParam ("key") String key,
|
||||
@PathParam ("value") String value, @QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "metadata/{g}/{a}/{v}/{key}" )
|
||||
@Path ("metadata/{g}/{a}/{v}/{key}")
|
||||
@DELETE
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = false, noRestriction = false, permissions = "archiva-add-metadata" )
|
||||
Boolean deleteMetadata( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version, @PathParam ( "key" ) String key,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = false, noRestriction = false, permissions = "archiva-add-metadata")
|
||||
Boolean deleteMetadata( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version, @PathParam ("key") String key,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "artifactContentEntries/{g}/{a}/{v}" )
|
||||
@Path ("artifactContentEntries/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
List<ArtifactContentEntry> getArtifactContentEntries( @PathParam ( "g" ) String groupId,
|
||||
@PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version,
|
||||
@QueryParam ( "c" ) String classifier,
|
||||
@QueryParam ( "t" ) String type,
|
||||
@QueryParam ( "p" ) String path,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
List<ArtifactContentEntry> getArtifactContentEntries( @PathParam ("g") String groupId,
|
||||
@PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version,
|
||||
@QueryParam ("c") String classifier,
|
||||
@QueryParam ("t") String type, @QueryParam ("p") String path,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "artifactDownloadInfos/{g}/{a}/{v}" )
|
||||
@Path ("artifactDownloadInfos/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
List<Artifact> getArtifactDownloadInfos( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
List<Artifact> getArtifactDownloadInfos( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "artifactContentText/{g}/{a}/{v}" )
|
||||
@Path ("artifactContentText/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
/**
|
||||
* if path is empty content of the file is returned (for pom view)
|
||||
*/
|
||||
ArtifactContent getArtifactContentText( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version, @QueryParam ( "c" ) String classifier,
|
||||
@QueryParam ( "t" ) String type, @QueryParam ( "p" ) String path,
|
||||
@QueryParam ( "repositoryId" ) String repositoryId )
|
||||
ArtifactContent getArtifactContentText( @PathParam ("g") String groupId, @PathParam ("a") String artifactId,
|
||||
@PathParam ("v") String version, @QueryParam ("c") String classifier,
|
||||
@QueryParam ("t") String type, @QueryParam ("p") String path,
|
||||
@QueryParam ("repositoryId") String repositoryId )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path ( "artifactAvailable/{g}/{a}/{v}" )
|
||||
@Path ("artifactAvailable/{g}/{a}/{v}")
|
||||
@GET
|
||||
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization ( noPermission = true, noRestriction = true )
|
||||
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@RedbackAuthorization (noPermission = true, noRestriction = true)
|
||||
/**
|
||||
* verify if an artifact is available locally if not download from proxies will be try
|
||||
* @since 1.4-M3
|
||||
*/
|
||||
Boolean artifactAvailable( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
|
||||
@PathParam ( "v" ) String version, @QueryParam ( "repositoryId" ) String repositoryId )
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
//---------------------------
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue