]> source.dussan.org Git - archiva.git/commitdiff
add an Entry object for REST services returning map -> ease json mapping in javascript
authorOlivier Lamy <olamy@apache.org>
Mon, 26 Mar 2012 09:54:39 +0000 (09:54 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 26 Mar 2012 09:54:39 +0000 (09:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1305281 13f79535-47bb-0310-9956-ffa450edef68

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/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java

index 5b2be0978651f16f89213fceac755915dc152ef2..332892b79106936e2fb8269ca5c7a237f6640c68 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.rest.api.model.Artifact;
 import org.apache.archiva.rest.api.model.BrowseResult;
+import org.apache.archiva.rest.api.model.Entry;
 import org.apache.archiva.rest.api.model.TreeEntry;
 import org.apache.archiva.rest.api.model.VersionsList;
 import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
@@ -35,7 +36,6 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author Olivier Lamy
@@ -123,9 +123,8 @@ public interface BrowseService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noPermission = true, noRestriction = true )
-    Map<String, String> getMetadatas( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId,
-                                      @PathParam( "v" ) String version,
-                                      @QueryParam( "repositoryId" ) String repositoryId )
+    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}" )
index 96c71208f72711b479307a435eff5e7e1d61076a..86182503cbf210cdbd9647558de2b0612d21a20f 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.archiva.rest.api.model.Artifact;
 import org.apache.archiva.rest.api.model.BrowseResult;
 import org.apache.archiva.rest.api.model.BrowseResultEntry;
+import org.apache.archiva.rest.api.model.Entry;
 import org.apache.archiva.rest.api.model.TreeEntry;
 import org.apache.archiva.rest.api.model.VersionsList;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
@@ -563,23 +564,30 @@ public class DefaultBrowseService
         return artifacts;
     }
 
-    public Map<String, String> getMetadatas( String groupId, String artifactId, String version, String repositoryId )
+    public List<Entry> getMetadatas( String groupId, String artifactId, String version, String repositoryId )
         throws ArchivaRestServiceException
     {
         ProjectVersionMetadata projectVersionMetadata =
             getProjectMetadata( groupId, artifactId, version, repositoryId );
         if ( projectVersionMetadata == null )
         {
-            return Collections.emptyMap();
+            return Collections.emptyList();
         }
         MetadataFacet metadataFacet = projectVersionMetadata.getFacet( GenericMetadataFacet.FACET_ID );
 
         if ( metadataFacet == null )
         {
-            return Collections.emptyMap();
+            return Collections.emptyList();
         }
+        Map<String, String> map = metadataFacet.toProperties();
+        List<Entry> entries = new ArrayList<Entry>( map.size() );
 
-        return metadataFacet.toProperties();
+        for ( Map.Entry<String, String> entry : map.entrySet() )
+        {
+            entries.add( new Entry( entry.getKey(), entry.getValue() ) );
+        }
+
+        return entries;
     }
 
     public Boolean addMetadata( String groupId, String artifactId, String version, String key, String value,
index a573ba6ce1085b305f4cb6cd95e8dd97d5ffcb5b..2416461187e11ba0e32a9478bfc52233f7c61d93 100644 (file)
@@ -21,11 +21,14 @@ package org.apache.archiva.rest.services;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.rest.api.model.BrowseResult;
 import org.apache.archiva.rest.api.model.BrowseResultEntry;
+import org.apache.archiva.rest.api.model.Entry;
 import org.apache.archiva.rest.api.model.VersionsList;
 import org.apache.archiva.rest.api.services.BrowseService;
 import org.fest.assertions.MapAssert;
 import org.junit.Test;
 
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -36,6 +39,19 @@ import static org.fest.assertions.Assertions.assertThat;
 public class BrowseServiceTest
     extends AbstractArchivaRestTest
 {
+
+    Map<String, String> toMap( List<Entry> entries )
+    {
+        Map<String, String> map = new HashMap<String, String>( entries.size() );
+
+        for ( Entry entry : entries )
+        {
+            map.put( entry.getKey(), entry.getValue() );
+        }
+
+        return map;
+    }
+
     @Test
     public void metadatagetthenadd()
         throws Exception
@@ -52,13 +68,14 @@ public class BrowseServiceTest
 
         BrowseService browseService = getBrowseService( authorizationHeader, false );
 
-        Map<String, String> metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
+        Map<String, String> metadatas =
+            toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
 
         assertThat( metadatas ).isNotNull().isEmpty();
 
         browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
 
-        metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
+        metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
 
         assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
 
@@ -83,19 +100,20 @@ public class BrowseServiceTest
 
         BrowseService browseService = getBrowseService( authorizationHeader, false );
 
-        Map<String, String> metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
+        Map<String, String> metadatas =
+            toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
 
         assertThat( metadatas ).isNotNull().isEmpty();
 
         browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
 
-        metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
+        metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
 
         assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
 
         browseService.deleteMetadata( "commons-cli", "commons-cli", "1.0", "wine", testRepoId );
 
-        metadatas = browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId );
+        metadatas = toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) );
 
         assertThat( metadatas ).isNotNull().isEmpty();