mirror of
https://github.com/apache/archiva.git
synced 2025-02-28 05:29:07 +00:00
add an Entry object for REST services returning map -> ease json mapping in javascript
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1305281 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
47350400c4
commit
ef8d2cc959
@ -22,6 +22,7 @@
|
||||
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.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
@ -123,9 +123,8 @@ List<Artifact> getDependees( @PathParam( "g" ) String groupId, @PathParam( "a" )
|
||||
@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}" )
|
||||
|
@ -34,6 +34,7 @@
|
||||
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 List<Artifact> getDependees( String groupId, String artifactId, String ve
|
||||
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() );
|
||||
|
||||
for ( Map.Entry<String, String> entry : map.entrySet() )
|
||||
{
|
||||
entries.add( new Entry( entry.getKey(), entry.getValue() ) );
|
||||
}
|
||||
|
||||
return metadataFacet.toProperties();
|
||||
return entries;
|
||||
}
|
||||
|
||||
public Boolean addMetadata( String groupId, String artifactId, String version, String key, String value,
|
||||
|
@ -21,11 +21,14 @@
|
||||
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 @@
|
||||
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 void metadatagetthenadd()
|
||||
|
||||
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 void metadatagetthenaddthendelete()
|
||||
|
||||
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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user