]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1573] improve browse service with returning ProjectVersionMetadata (so add some...
authorOlivier Lamy <olamy@apache.org>
Fri, 24 Feb 2012 21:18:34 +0000 (21:18 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 24 Feb 2012 21:18:34 +0000 (21:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1293423 13f79535-47bb-0310-9956-ffa450edef68

15 files changed:
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/CiManagement.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Dependency.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/FacetedMetadata.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/IssueManagement.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MailingList.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacet.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Organization.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Scm.java

index d28c32ed101d433a12f620c04838a7af17b78aae..2dd89862781353bdecb20cc1fac59fcfebdff434 100644 (file)
       <artifactId>archiva-policies</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-model</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>org.codehaus.redback</groupId>
index 15d6b4c9cf76930c38e724cb79c7a5a63d80c21d..758a52c941e83333cea8f7c70cf55542fae1572a 100644 (file)
@@ -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;
 }
index 8bdd8d35e00ef12ef650533b08b9241ec0706319..2b85bdc61ecf0287bbb5e21641a94f0bfd7be6ed 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-admin-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-model</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-configuration</artifactId>
index 360868142f0d58b7023f7050078af8cc61948963..c6f2d78692036757a13bf633f0f03dcb6ffed6af 100644 (file)
@@ -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();
+            }
         }
-
     }
 
     //---------------------------
index 9a641848f4af39b090cbbcdbf1a0790141917540..3a2ab5b503ef6ad370955e114bc02e18f4f33eb2 100644 (file)
@@ -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(){
index bbee4efcf0b814fc7599a9087226f0467265b57b..d58936d77de7cd6086a9464b8448328cadfaf9e5 100644 (file)
@@ -19,11 +19,14 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  * Information about the CI system used by the project.
  *
  * @todo considering moving this to a facet - avoid referring to it externally
  */
+@XmlRootElement( name = "ciManagement" )
 public class CiManagement
 {
     /**
index a2658769ddb0a0e1affaf51f4d03d338a21645aa..772984fd9b4bde9a20fd8138b47c327c8f87f5ee 100644 (file)
@@ -19,11 +19,14 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  * Information about a dependency that this project has on another project or artifact.
  *
  * @todo will be reviewing what is appropriate for the base here - rest should be in a maven dependency facet - avoid details on it externally
  */
+@XmlRootElement( name = "dependency" )
 public class Dependency
 {
     /**
index 5e7d82d3c50c9a545444719f54d49b2ab883f026..387813e36f09b3a3e7eee97ecbc09677505d6f04 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlElement;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -77,7 +78,7 @@ public abstract class FacetedMetadata
 
     /**
      * Get all available facets as a Map (typically used by bean rendering, such as in Archiva's JSPs).
-
+     *
      * @return the map of facets
      * @see #facets
      */
index 83eecda0d398fbec92cfd60c30f30a51cad692be..12137ba43a4e27b2982f439d0de3ce7bb7e27815 100644 (file)
@@ -19,11 +19,14 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  * Information about the issue management system used by the project.
  *
  * @todo considering moving this to a facet - avoid referring to it externally
  */
+@XmlRootElement( name = "issueManagement" )
 public class IssueManagement
 {
     /**
index b1ce93b779108f21758464c445ab48b93c2efeea..5fbb28015c2290416c29ffe517d3c8d634a3c294 100644 (file)
@@ -19,9 +19,12 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  * A description of a particular license used by a project.
  */
+@XmlRootElement( name = "license" )
 public class License
 {
     /**
index 129358d4ab692220da81606111a7215b977fc489..922e2d5d867d17f140ade5aae43e77c5173f687e 100644 (file)
@@ -1,5 +1,6 @@
 package org.apache.archiva.metadata.model;
 
+import javax.xml.bind.annotation.XmlRootElement;
 import java.util.List;
 
 /*
@@ -26,6 +27,7 @@ import java.util.List;
  *
  * @todo considering moving this to a facet - avoid referring to it externally
  */
+@XmlRootElement( name = "mailingList" )
 public class MailingList
 {
     /**
index ebc3dd2ff289825047a2dfd37e6403941928d65f..d146efd2d21ccf89307b817203361995eec8c417 100644 (file)
@@ -19,14 +19,20 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import java.util.Map;
 
+@XmlRootElement( name = "metadataFacet" )
 public interface MetadataFacet
 {
+    @XmlElement(name = "facetId")
     String getFacetId();
 
+    @XmlElement(name = "name")
     String getName();
 
+    @XmlElement(name = "properties")
     Map<String, String> toProperties();
 
     void fromProperties( Map<String, String> properties );
index f3d841d4cf921b0e093726f656c7e17dd5065009..23048cbedf946c4c8585c7c04b917786b5e38b0a 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement( name = "organization" )
 public class Organization
 {
     private String name;
index b61135e783343281355d5a793bd2fe4d8db20e87..d614bc9907dd64d76812c7e53758fad1d8f210ff 100644 (file)
@@ -19,9 +19,11 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlRootElement;
 import java.util.ArrayList;
 import java.util.List;
 
+@XmlRootElement( name = "projectVersionMetadata" )
 public class ProjectVersionMetadata
     extends FacetedMetadata
 {
index a3d8158fbfc59fa3aa182ced8400f66f72bbec97..5e45e931fe848f070ff7614bed43f9e91c874d4d 100644 (file)
@@ -19,6 +19,9 @@ package org.apache.archiva.metadata.model;
  * under the License.
  */
 
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement( name = "scm" )
 public class Scm
 {
     private String connection;