summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-02-24 21:18:34 +0000
committerOlivier Lamy <olamy@apache.org>2012-02-24 21:18:34 +0000
commitf1f0ceaf47e692c20a110a8f67990b5edcc5d707 (patch)
tree68eee3a8907589d5c6d6ad3252c6fd975b2f37b0 /archiva-modules/archiva-web
parentb4bd369412569dec700aa9187a6b009cae0ba771 (diff)
downloadarchiva-f1f0ceaf47e692c20a110a8f67990b5edcc5d707.tar.gz
archiva-f1f0ceaf47e692c20a110a8f67990b5edcc5d707.zip
[MRM-1573] improve browse service with returning ProjectVersionMetadata (so add some annotation for REST exchange)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1293423 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java14
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java153
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js15
5 files changed, 181 insertions, 9 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
index d28c32ed1..2dd898627 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
@@ -45,6 +45,10 @@
<artifactId>archiva-policies</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>metadata-model</artifactId>
+ </dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
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 15d6b4c9c..758a52c94 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
@@ -18,6 +18,7 @@ package org.apache.archiva.rest.api.services;
* under the License.
*/
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.rest.api.model.BrowseResult;
import org.apache.archiva.rest.api.model.VersionsList;
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
@@ -26,7 +27,6 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
/**
@@ -50,10 +50,18 @@ public interface BrowseService
BrowseResult browseGroupId( @PathParam( "groupId" ) String groupId )
throws ArchivaRestServiceException;
- @Path( "browseGroupId" )
+ @Path( "versionsList/{g}/{a}" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true, noPermission = false )
- VersionsList getVersionsList( @QueryParam( "g" ) String groupId, @QueryParam( "a" ) String artifactId )
+ VersionsList getVersionsList( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId )
+ throws ArchivaRestServiceException;
+
+ @Path( "projectVersionMetadata/{g}/{a}" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ @RedbackAuthorization( noRestriction = true, noPermission = false )
+ ProjectVersionMetadata getProjectVersionMetadata( @PathParam( "g" ) String groupId,
+ @PathParam( "a" ) String artifactId )
throws ArchivaRestServiceException;
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
index 8bdd8d35e..2b85bdc61 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
@@ -46,6 +46,10 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
+ <artifactId>metadata-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
<scope>runtime</scope>
</dependency>
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 360868142..c6f2d7869 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
@@ -18,15 +18,18 @@ package org.apache.archiva.rest.services;
* under the License.
*/
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.archiva.rest.api.model.BrowseResult;
import org.apache.archiva.rest.api.model.BrowseResultEntry;
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.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.ws.rs.core.Response;
@@ -170,8 +173,23 @@ public class DefaultBrowseService
return new VersionsList();
}
- RepositorySession repositorySession = repositorySessionFactory.createSession();
+ try
+ {
+ return new VersionsList( new ArrayList<String>( getVersions( selectedRepos, groupId, artifactId ) ) );
+ }
+ catch ( MetadataResolutionException e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(),
+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() );
+ }
+ }
+
+ private Set<String> getVersions( List<String> selectedRepos, String groupId, String artifactId )
+ throws MetadataResolutionException
+
+ {
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
MetadataResolver metadataResolver = repositorySession.getResolver();
@@ -184,7 +202,132 @@ public class DefaultBrowseService
metadataResolver.resolveProjectVersions( repositorySession, repoId, groupId, artifactId ) );
}
- return new VersionsList( new ArrayList<String>( versions ) );
+ return versions;
+ }
+ finally
+ {
+ repositorySession.close();
+ }
+ }
+
+ public ProjectVersionMetadata getProjectVersionMetadata( String groupId, String artifactId )
+ throws ArchivaRestServiceException
+ {
+
+ List<String> selectedRepos = getObservableRepos();
+
+ if ( CollectionUtils.isEmpty( selectedRepos ) )
+ {
+ // FIXME 403 ???
+ return null;
+ }
+
+ RepositorySession repositorySession = null;
+ try
+ {
+
+ Set<String> projectVersions = getVersions( selectedRepos, groupId, artifactId );
+
+ repositorySession = repositorySessionFactory.createSession();
+
+ MetadataResolver metadataResolver = repositorySession.getResolver();
+
+ ProjectVersionMetadata sharedModel = new ProjectVersionMetadata();
+
+ MavenProjectFacet mavenFacet = new MavenProjectFacet();
+ mavenFacet.setGroupId( groupId );
+ mavenFacet.setArtifactId( artifactId );
+ sharedModel.addFacet( mavenFacet );
+
+ boolean isFirstVersion = true;
+
+ for ( String version : projectVersions )
+ {
+ ProjectVersionMetadata versionMetadata = null;
+ for ( String repoId : selectedRepos )
+ {
+ if ( versionMetadata == null )
+ {
+ try
+ {
+ versionMetadata =
+ metadataResolver.resolveProjectVersion( repositorySession, repoId, groupId, artifactId,
+ version );
+ }
+ catch ( MetadataResolutionException e )
+ {
+ log.error( "Skipping invalid metadata while compiling shared model for " + groupId + ":"
+ + artifactId + " in repo " + repoId + ": " + e.getMessage() );
+ }
+ }
+ }
+
+ if ( versionMetadata == null )
+ {
+ continue;
+ }
+
+ if ( isFirstVersion )
+ {
+ sharedModel = versionMetadata;
+ sharedModel.setId( null );
+ }
+ else
+ {
+ MavenProjectFacet versionMetadataMavenFacet =
+ (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
+ if ( versionMetadataMavenFacet != null )
+ {
+ if ( mavenFacet.getPackaging() != null && !StringUtils.equalsIgnoreCase(
+ mavenFacet.getPackaging(), versionMetadataMavenFacet.getPackaging() ) )
+ {
+ mavenFacet.setPackaging( null );
+ }
+ }
+
+ if ( sharedModel.getName() != null && !StringUtils.equalsIgnoreCase( sharedModel.getName(),
+ versionMetadata.getName() ) )
+ {
+ sharedModel.setName( "" );
+ }
+
+ if ( sharedModel.getDescription() != null && !StringUtils.equalsIgnoreCase(
+ sharedModel.getDescription(), versionMetadata.getDescription() ) )
+ {
+ sharedModel.setDescription( null );
+ }
+
+ if ( sharedModel.getIssueManagement() != null && versionMetadata.getIssueManagement() != null
+ && !StringUtils.equalsIgnoreCase( sharedModel.getIssueManagement().getUrl(),
+ versionMetadata.getIssueManagement().getUrl() ) )
+ {
+ sharedModel.setIssueManagement( null );
+ }
+
+ if ( sharedModel.getCiManagement() != null && versionMetadata.getCiManagement() != null
+ && !StringUtils.equalsIgnoreCase( sharedModel.getCiManagement().getUrl(),
+ versionMetadata.getCiManagement().getUrl() ) )
+ {
+ sharedModel.setCiManagement( null );
+ }
+
+ if ( sharedModel.getOrganization() != null && versionMetadata.getOrganization() != null
+ && !StringUtils.equalsIgnoreCase( sharedModel.getOrganization().getName(),
+ versionMetadata.getOrganization().getName() ) )
+ {
+ sharedModel.setOrganization( null );
+ }
+
+ if ( sharedModel.getUrl() != null && !StringUtils.equalsIgnoreCase( sharedModel.getUrl(),
+ versionMetadata.getUrl() ) )
+ {
+ sharedModel.setUrl( null );
+ }
+ }
+
+ isFirstVersion = false;
+ }
+ return sharedModel;
}
catch ( MetadataResolutionException e )
{
@@ -193,9 +336,11 @@ public class DefaultBrowseService
}
finally
{
- repositorySession.close();
+ if ( repositorySession != null )
+ {
+ repositorySession.close();
+ }
}
-
}
//---------------------------
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 9a641848f..3a2ab5b50 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
@@ -42,7 +42,7 @@ $(function() {
displayProjectEntry=function(id){
$.log("displayProjectEntry:"+id);
- var url = "restServices/archivaServices/browseService/browseGroupId?g=org.apache.maven&a=maven-archiver";
+ var url = "restServices/archivaServices/browseService/versionsList/org.apache.maven/maven-archiver";
$.ajax(url, {
type: "GET",
@@ -50,7 +50,18 @@ $(function() {
success: function(data) {
}
- });
+ });
+
+ url = "restServices/archivaServices/browseService/projectVersionMetadata/org.apache.maven/maven-archiver";
+
+ $.ajax(url, {
+ type: "GET",
+ dataType: 'json',
+ success: function(data) {
+
+ }
+ });
+
}
breadCrumbEntries=function(){