From 2cc35e19fd4747bd2e7e597923284064f44835fb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 18 Dec 2012 14:20:31 +0000 Subject: [PATCH] if classifier from the search we must download the artifact with this classifier git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1423442 13f79535-47bb-0310-9956-ffa450edef68 --- .../rest/api/services/BrowseService.java | 197 ++++++++++-------- .../rest/services/DefaultBrowseService.java | 17 +- .../src/main/webapp/js/archiva/main.js | 35 +++- .../src/main/webapp/js/archiva/search.js | 5 + 4 files changed, 158 insertions(+), 96 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java index cbd784517..5cd0f50b9 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java @@ -45,61 +45,59 @@ 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; /** - * @param groupId groupId to browse + * @param groupId groupId to browse * @param repositoryId optionnal (repository to browse if null all available user repositories are used) */ - @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; /** * @return List of managed repositories current user can read */ - @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) List getUserRepositories() throws ArchivaRestServiceException; @@ -107,115 +105,130 @@ public interface BrowseService * return the dependency Tree for an artifacts * the List result has only one entry */ - @Path ("treeEntries/{g}/{a}/{v}") + @Path("treeEntries/{g}/{a}/{v}") @GET - @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @RedbackAuthorization (noPermission = true, noRestriction = true) - List getTreeEntries( @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 getTreeEntries( @PathParam("g") String groupId, @PathParam("a") String artifactId, + @PathParam("v") String version, @QueryParam("repositoryId") String repositoryId ) throws ArchivaRestServiceException; /** * List of artifacts using the artifact passed in parameter. */ - @Path ("dependees/{g}/{a}/{v}") + @Path("dependees/{g}/{a}/{v}") @GET - @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @RedbackAuthorization (noPermission = true, noRestriction = true) - List getDependees( @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 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 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 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( "importMetadata" ) + @Path("importMetadata") @POST - @RedbackAuthorization( noPermission = false, noRestriction = false, permissions = "archiva-add-metadata") - Boolean importMetadata( MetadataAddRequest metadataAddRequest, @QueryParam ("repository") String repository ) + @RedbackAuthorization(noPermission = false, noRestriction = false, permissions = "archiva-add-metadata") + Boolean importMetadata( MetadataAddRequest metadataAddRequest, @QueryParam("repository") String repository ) 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 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 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 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 getArtifactDownloadInfos( @PathParam("g") String groupId, @PathParam("a") String artifactId, + @PathParam("v") String version, + @QueryParam("repositoryId") String repositoryId ) throws ArchivaRestServiceException; /** * if path is empty content of the file is returned (for pom view) */ - @Path ("artifactContentText/{g}/{a}/{v}") + @Path("artifactContentText/{g}/{a}/{v}") @GET - @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @RedbackAuthorization (noPermission = true, noRestriction = true) - 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 ) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(noPermission = true, noRestriction = true) + 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; /** * verify if an artifact is available locally if not download from proxies will be try + * * @since 1.4-M3 */ - @Path ("artifactAvailable/{g}/{a}/{v}") + @Path("artifactAvailable/{g}/{a}/{v}") @GET - @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @RedbackAuthorization (noPermission = true, noRestriction = true) - Boolean artifactAvailable( @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) + Boolean artifactAvailable( @PathParam("g") String groupId, @PathParam("a") String artifactId, + @PathParam("v") String version, @QueryParam("repositoryId") String repositoryId ) throws ArchivaRestServiceException; /** + * verify if an artifact is available locally if not download from proxies will be try * + * @since 1.4-M4 + */ + @Path( "artifactAvailable/{g}/{a}/{v}/{c}" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( noPermission = true, noRestriction = true ) + Boolean artifactAvailable( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId, + @PathParam( "v" ) String version, @PathParam( "c" ) String classifier, + @QueryParam( "repositoryId" ) String repositoryId ) + throws ArchivaRestServiceException; + + /** * return List of all artifacts from this repository + * * @param repositoryId * @return * @throws ArchivaRestServiceException * @since 1.4-M3 */ - @Path ("artifacts/{r}") + @Path("artifacts/{r}") @GET - @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) - @RedbackAuthorization (noPermission = true, noRestriction = true) - List getArtifacts( @PathParam ( "r" ) String repositoryId ) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(noPermission = true, noRestriction = true) + List getArtifacts( @PathParam("r") String repositoryId ) throws ArchivaRestServiceException; } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 36e4ae17a..a9638b60f 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -62,6 +62,8 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import javax.inject.Named; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.io.File; import java.io.IOException; @@ -771,7 +773,8 @@ public class DefaultBrowseService return new ArtifactContent(); } - public Boolean artifactAvailable( String groupId, String artifactId, String version, String repositoryId ) + public Boolean artifactAvailable( String groupId, String artifactId, String version, String classifier, + String repositoryId ) throws ArchivaRestServiceException { List selectedRepos = getSelectedRepos( repositoryId ); @@ -793,8 +796,10 @@ public class DefaultBrowseService ManagedRepositoryContent managedRepositoryContent = repositoryContentFactory.getManagedRepositoryContent( repoId ); // FIXME default to jar which can be wrong for war zip etc.... - ArchivaArtifact archivaArtifact = - new ArchivaArtifact( groupId, artifactId, version, "", "jar", repoId ); + ArchivaArtifact archivaArtifact = new ArchivaArtifact( groupId, artifactId, version, + StringUtils.isEmpty( classifier ) + ? "" + : classifier, "jar", repoId ); File file = managedRepositoryContent.toFile( archivaArtifact ); if ( file != null && file.exists() ) @@ -831,6 +836,12 @@ public class DefaultBrowseService return false; } + public Boolean artifactAvailable( String groupId, String artifactId, String version, String repositoryId ) + throws ArchivaRestServiceException + { + return artifactAvailable( groupId, artifactId, version, null, repositoryId ); + } + public List getArtifacts( String repositoryId ) throws ArchivaRestServiceException { diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index 1dc4a36e5..1f18d8398 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -350,7 +350,8 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa goToBrowseArtifactDetail(groupId,artifactId,repositoryId);//,null,null); }); - var checkArtifactDetailContent=function(groupId,artifactId,version,repositoryId,tabToActivate,idContentToCheck,contentDisplayFn){ + + var checkArtifactDetailContent=function(groupId,artifactId,version,repositoryId,tabToActivate,idContentToCheck,contentDisplayFn,classifier){ self.activeMenuId("browse"); // no need to recalculate all stuff just activate the tab var htmlId = idContentToCheck?idContentToCheck:"browse_artifact_detail"; @@ -369,6 +370,10 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa var artifactAvailableUrl="restServices/archivaServices/browseService/artifactAvailable/"+encodeURIComponent(groupId)+"/"+encodeURIComponent(artifactId); artifactAvailableUrl+="/"+encodeURIComponent(version); + if(classifier){ + artifactAvailableUrl+="/"+encodeURIComponent(classifier); + } + var selectedRepo=getSelectedBrowsingRepository(); if (selectedRepo){ artifactAvailableUrl+="?repositoryId="+encodeURIComponent(selectedRepo); @@ -412,6 +417,24 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa checkArtifactDetailContent(groupId,artifactId,version,repositoryId,"artifact-details-info-content-a"); }); + this.get('#artifact/:groupId/:artifactId/:version/:classifier',function(context){ + var groupId= this.params.groupId; + var artifactId= this.params.artifactId; + var version= this.params.version; + var classifier= this.params.classifier; + checkArtifactDetailContent(groupId,artifactId,version,null,"artifact-details-info-content-a",null,null,classifier); + }); + + this.get('#artifact~:repositoryId/:groupId/:artifactId/:version/:classifier',function(context){ + + var repositoryId = this.params.repositoryId; + var groupId= this.params.groupId; + var artifactId= this.params.artifactId; + var version= this.params.version; + var classifier= this.params.classifier; + checkArtifactDetailContent(groupId,artifactId,version,repositoryId,"artifact-details-info-content-a",null,null,classifier); + }); + this.get('#artifact-dependencies/:groupId/:artifactId/:version',function(context){ var repositoryId = this.params.repositoryId; @@ -423,6 +446,16 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa }); + this.get('#artifact-dependencies/:groupId/:artifactId/:version',function(context){ + + var repositoryId = this.params.repositoryId; + var groupId= this.params.groupId; + var artifactId= this.params.artifactId; + var version= this.params.version; + checkArtifactDetailContent(groupId,artifactId,version,repositoryId,"artifact-details-dependencies-content-a"); + + }); + this.get('#artifact-dependencies~:repositoryId/:groupId/:artifactId/:version',function(context){ var repositoryId = this.params.repositoryId; diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js index 01cbac7c2..1ae512a97 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js @@ -964,6 +964,7 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno * @param artifactId * @param parentBrowseViewModel * @param restUrl + * @param repositoryId */ displayArtifactDetail=function(groupId,artifactId,parentBrowseViewModel,restUrl,repositoryId){ $.log("displayArtifactDetail:"+groupId+":"+artifactId); @@ -1758,6 +1759,10 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno } location+="/"+artifact.groupId+"/"+artifact.artifactId+"/"+artifact.version; + if(artifact.classifier){ + location+="/"+artifact.classifier; + } + window.sammyArchivaApplication.setLocation(location); } } -- 2.39.5