mirror of https://github.com/apache/archiva.git
add a method to retrieve all groupIds available in indexs: available in REST services
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1181731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a975a8b1d1
commit
8daf53e0f0
|
@ -0,0 +1,53 @@
|
||||||
|
package org.apache.archiva.rest.api.model;
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olivier Lamy
|
||||||
|
* @since 1.4-M1
|
||||||
|
*/
|
||||||
|
@XmlRootElement( name = "groupIdList" )
|
||||||
|
public class GroupIdList
|
||||||
|
implements Serializable
|
||||||
|
{
|
||||||
|
private List<String> groupIds;
|
||||||
|
public GroupIdList ( )
|
||||||
|
{
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupIdList ( List<String> groupIds )
|
||||||
|
{
|
||||||
|
this.groupIds = groupIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getGroupIds()
|
||||||
|
{
|
||||||
|
return groupIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupIds(List<String> groupIds)
|
||||||
|
{
|
||||||
|
this.groupIds = groupIds;
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ package org.apache.archiva.rest.api.services;
|
||||||
|
|
||||||
import org.apache.archiva.rest.api.model.Artifact;
|
import org.apache.archiva.rest.api.model.Artifact;
|
||||||
import org.apache.archiva.rest.api.model.Dependency;
|
import org.apache.archiva.rest.api.model.Dependency;
|
||||||
|
import org.apache.archiva.rest.api.model.GroupIdList;
|
||||||
import org.apache.archiva.rest.api.model.SearchRequest;
|
import org.apache.archiva.rest.api.model.SearchRequest;
|
||||||
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
|
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
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.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Path( "/searchService/" )
|
@Path( "/searchService/" )
|
||||||
|
@ -48,14 +50,14 @@ public interface SearchService
|
||||||
@Path( "quickSearch" )
|
@Path( "quickSearch" )
|
||||||
@GET
|
@GET
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
@RedbackAuthorization( noPermission = true, noRestriction = false )
|
||||||
List<Artifact> quickSearch( @QueryParam( "queryString" ) String queryString )
|
List<Artifact> quickSearch( @QueryParam( "queryString" ) String queryString )
|
||||||
throws ArchivaRestServiceException;
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
@Path( "getArtifactVersions" )
|
@Path( "getArtifactVersions" )
|
||||||
@GET
|
@GET
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
@RedbackAuthorization( noPermission = true, noRestriction = false )
|
||||||
List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId,
|
List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId,
|
||||||
@QueryParam( "artifactId" ) String artifactId,
|
@QueryParam( "artifactId" ) String artifactId,
|
||||||
@QueryParam( "packaging" ) String packaging )
|
@QueryParam( "packaging" ) String packaging )
|
||||||
|
@ -64,10 +66,17 @@ public interface SearchService
|
||||||
@Path( "searchArtifacts" )
|
@Path( "searchArtifacts" )
|
||||||
@POST
|
@POST
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
@RedbackAuthorization( noPermission = true, noRestriction = false )
|
||||||
List<Artifact> searchArtifacts( SearchRequest searchRequest )
|
List<Artifact> searchArtifacts( SearchRequest searchRequest )
|
||||||
throws ArchivaRestServiceException;
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
|
@Path( "getAllGroupIds" )
|
||||||
|
@GET
|
||||||
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
|
@RedbackAuthorization( noPermission = true, noRestriction = false )
|
||||||
|
GroupIdList getAllGroupIds( @QueryParam( "selectedRepos" ) List<String> selectedRepos )
|
||||||
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
@Path( "getDependencies" )
|
@Path( "getDependencies" )
|
||||||
@GET
|
@GET
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.archiva.indexer.search.SearchResultLimits;
|
||||||
import org.apache.archiva.indexer.search.SearchResults;
|
import org.apache.archiva.indexer.search.SearchResults;
|
||||||
import org.apache.archiva.rest.api.model.Artifact;
|
import org.apache.archiva.rest.api.model.Artifact;
|
||||||
import org.apache.archiva.rest.api.model.Dependency;
|
import org.apache.archiva.rest.api.model.Dependency;
|
||||||
|
import org.apache.archiva.rest.api.model.GroupIdList;
|
||||||
import org.apache.archiva.rest.api.model.SearchRequest;
|
import org.apache.archiva.rest.api.model.SearchRequest;
|
||||||
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
||||||
import org.apache.archiva.rest.api.services.SearchService;
|
import org.apache.archiva.rest.api.services.SearchService;
|
||||||
|
@ -36,6 +37,7 @@ import org.apache.archiva.security.AccessDeniedException;
|
||||||
import org.apache.archiva.security.ArchivaSecurityException;
|
import org.apache.archiva.security.ArchivaSecurityException;
|
||||||
import org.apache.archiva.security.PrincipalNotFoundException;
|
import org.apache.archiva.security.PrincipalNotFoundException;
|
||||||
import org.apache.archiva.security.UserRepositories;
|
import org.apache.archiva.security.UserRepositories;
|
||||||
|
import org.apache.commons.collections.ListUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.codehaus.plexus.redback.users.UserManager;
|
import org.codehaus.plexus.redback.users.UserManager;
|
||||||
import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
|
import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
|
||||||
|
@ -47,6 +49,7 @@ import org.springframework.stereotype.Service;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -137,6 +140,27 @@ public class DefaultSearchService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GroupIdList getAllGroupIds(List<String> selectedRepos)
|
||||||
|
throws ArchivaRestServiceException
|
||||||
|
{
|
||||||
|
List<String> observableRepos = getObservableRepos();
|
||||||
|
List<String> repos = ListUtils.intersection( observableRepos, selectedRepos );
|
||||||
|
if (repos == null || repos.isEmpty())
|
||||||
|
{
|
||||||
|
return new GroupIdList( Collections.<String>emptyList() );
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new GroupIdList( new ArrayList<String>( repositorySearch.getAllGroupIds( getPrincipal(), repos ) ) );
|
||||||
|
}
|
||||||
|
catch ( RepositorySearchException e )
|
||||||
|
{
|
||||||
|
log.error( e.getMessage(), e );
|
||||||
|
throw new ArchivaRestServiceException( e.getMessage() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public List<Dependency> getDependencies( String groupId, String artifactId, String version )
|
public List<Dependency> getDependencies( String groupId, String artifactId, String version )
|
||||||
throws ArchivaRestServiceException
|
throws ArchivaRestServiceException
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,10 +23,13 @@ import org.apache.archiva.rest.api.model.Artifact;
|
||||||
import org.apache.archiva.rest.api.model.SearchRequest;
|
import org.apache.archiva.rest.api.model.SearchRequest;
|
||||||
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
|
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
|
||||||
import org.apache.archiva.rest.api.services.SearchService;
|
import org.apache.archiva.rest.api.services.SearchService;
|
||||||
|
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -219,6 +222,30 @@ public class SearchServiceTest
|
||||||
deleteTestRepo( testRepoId, targetRepo );
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllGroupIds()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
String testRepoId = "test-repo";
|
||||||
|
// force guest user creation if not exists
|
||||||
|
if ( getUserService( authorizationHeader ).getGuestUser() == null )
|
||||||
|
{
|
||||||
|
assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
|
||||||
|
}
|
||||||
|
|
||||||
|
File targetRepo = createAndIndexRepo( testRepoId );
|
||||||
|
|
||||||
|
SearchService searchService = getSearchService( authorizationHeader );
|
||||||
|
|
||||||
|
Collection<String> groupIds = searchService.getAllGroupIds( Arrays.asList( testRepoId ) ).getGroupIds();
|
||||||
|
log.info( "groupIds " + groupIds );
|
||||||
|
assertFalse( groupIds.isEmpty() );
|
||||||
|
assertTrue( groupIds.contains( "commons-cli") );
|
||||||
|
assertTrue( groupIds.contains( "org.apache.felix" ) );
|
||||||
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
|
}
|
||||||
|
|
||||||
private File createAndIndexRepo( String testRepoId )
|
private File createAndIndexRepo( String testRepoId )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -244,7 +271,9 @@ public class SearchServiceTest
|
||||||
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
||||||
service.addManagedRepository( managedRepository );
|
service.addManagedRepository( managedRepository );
|
||||||
|
|
||||||
getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
|
getRoleManagementService( authorizationHeader ).assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin" );
|
||||||
|
|
||||||
|
getRepositoriesService(authorizationHeader).scanRepositoryNow( testRepoId, true );
|
||||||
|
|
||||||
return targetRepo;
|
return targetRepo;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue