mirror of
https://github.com/apache/archiva.git
synced 2025-02-28 13:39:13 +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.metadata.model.ProjectVersionMetadata;
|
||||||
import org.apache.archiva.rest.api.model.Artifact;
|
import org.apache.archiva.rest.api.model.Artifact;
|
||||||
import org.apache.archiva.rest.api.model.BrowseResult;
|
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.TreeEntry;
|
||||||
import org.apache.archiva.rest.api.model.VersionsList;
|
import org.apache.archiva.rest.api.model.VersionsList;
|
||||||
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
|
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
|
||||||
@ -35,7 +36,6 @@
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
@ -123,9 +123,8 @@ List<Artifact> getDependees( @PathParam( "g" ) String groupId, @PathParam( "a" )
|
|||||||
@GET
|
@GET
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
||||||
Map<String, String> getMetadatas( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId,
|
List<Entry> getMetadatas( @PathParam( "g" ) String groupId, @PathParam( "a" ) String artifactId,
|
||||||
@PathParam( "v" ) String version,
|
@PathParam( "v" ) String version, @QueryParam( "repositoryId" ) String repositoryId )
|
||||||
@QueryParam( "repositoryId" ) String repositoryId )
|
|
||||||
throws ArchivaRestServiceException;
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
@Path( "metadata/{g}/{a}/{v}/{key}/{value}" )
|
@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.Artifact;
|
||||||
import org.apache.archiva.rest.api.model.BrowseResult;
|
import org.apache.archiva.rest.api.model.BrowseResult;
|
||||||
import org.apache.archiva.rest.api.model.BrowseResultEntry;
|
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.TreeEntry;
|
||||||
import org.apache.archiva.rest.api.model.VersionsList;
|
import org.apache.archiva.rest.api.model.VersionsList;
|
||||||
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
||||||
@ -563,23 +564,30 @@ public List<Artifact> getDependees( String groupId, String artifactId, String ve
|
|||||||
return artifacts;
|
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
|
throws ArchivaRestServiceException
|
||||||
{
|
{
|
||||||
ProjectVersionMetadata projectVersionMetadata =
|
ProjectVersionMetadata projectVersionMetadata =
|
||||||
getProjectMetadata( groupId, artifactId, version, repositoryId );
|
getProjectMetadata( groupId, artifactId, version, repositoryId );
|
||||||
if ( projectVersionMetadata == null )
|
if ( projectVersionMetadata == null )
|
||||||
{
|
{
|
||||||
return Collections.emptyMap();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
MetadataFacet metadataFacet = projectVersionMetadata.getFacet( GenericMetadataFacet.FACET_ID );
|
MetadataFacet metadataFacet = projectVersionMetadata.getFacet( GenericMetadataFacet.FACET_ID );
|
||||||
|
|
||||||
if ( metadataFacet == null )
|
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,
|
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.metadata.model.ProjectVersionMetadata;
|
||||||
import org.apache.archiva.rest.api.model.BrowseResult;
|
import org.apache.archiva.rest.api.model.BrowseResult;
|
||||||
import org.apache.archiva.rest.api.model.BrowseResultEntry;
|
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.model.VersionsList;
|
||||||
import org.apache.archiva.rest.api.services.BrowseService;
|
import org.apache.archiva.rest.api.services.BrowseService;
|
||||||
import org.fest.assertions.MapAssert;
|
import org.fest.assertions.MapAssert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
@ -36,6 +39,19 @@
|
|||||||
public class BrowseServiceTest
|
public class BrowseServiceTest
|
||||||
extends AbstractArchivaRestTest
|
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
|
@Test
|
||||||
public void metadatagetthenadd()
|
public void metadatagetthenadd()
|
||||||
throws Exception
|
throws Exception
|
||||||
@ -52,13 +68,14 @@ public void metadatagetthenadd()
|
|||||||
|
|
||||||
BrowseService browseService = getBrowseService( authorizationHeader, false );
|
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();
|
assertThat( metadatas ).isNotNull().isEmpty();
|
||||||
|
|
||||||
browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
|
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" ) );
|
assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
|
||||||
|
|
||||||
@ -83,19 +100,20 @@ public void metadatagetthenaddthendelete()
|
|||||||
|
|
||||||
BrowseService browseService = getBrowseService( authorizationHeader, false );
|
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();
|
assertThat( metadatas ).isNotNull().isEmpty();
|
||||||
|
|
||||||
browseService.addMetadata( "commons-cli", "commons-cli", "1.0", "wine", "bordeaux", testRepoId );
|
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" ) );
|
assertThat( metadatas ).isNotNull().isNotEmpty().includes( MapAssert.entry( "wine", "bordeaux" ) );
|
||||||
|
|
||||||
browseService.deleteMetadata( "commons-cli", "commons-cli", "1.0", "wine", testRepoId );
|
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();
|
assertThat( metadatas ).isNotNull().isEmpty();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user