[MRM-1490] Expose Archiva services trough REST : search service more impl

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1170261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-13 17:31:27 +00:00
parent cd57d56fe9
commit 3d29a9d3f4
11 changed files with 543 additions and 139 deletions

View File

@ -381,6 +381,18 @@ public class NexusRepositorySearch
hit.setBundleExportService( artifactInfo.bundleExportService ); hit.setBundleExportService( artifactInfo.bundleExportService );
hit.setBundleSymbolicName( artifactInfo.bundleSymbolicName ); hit.setBundleSymbolicName( artifactInfo.bundleSymbolicName );
hit.setBundleVersion( artifactInfo.bundleVersion ); hit.setBundleVersion( artifactInfo.bundleVersion );
hit.setBundleDescription( artifactInfo.bundleDescription );
hit.setBundleDocUrl( artifactInfo.bundleDocUrl );
hit.setBundleRequireBundle( artifactInfo.bundleRequireBundle );
hit.setBundleImportPackage( artifactInfo.bundleImportPackage );
hit.setBundleLicense( artifactInfo.bundleLicense );
hit.setBundleName( artifactInfo.bundleName );
hit.setContext( artifactInfo.context );
hit.setGoals( artifactInfo.goals );
hit.setPrefix( artifactInfo.prefix );
// sure ??
hit.setUrl( artifactInfo.remoteUrl );
} }
results.addHit( id, hit ); results.addHit( id, hit );

View File

@ -40,42 +40,81 @@ public class SearchResultHit
// Advanced hit, reference to artifactId. // Advanced hit, reference to artifactId.
private String artifactId; private String artifactId;
// TODO: remove/deprecate this field!
private String version = "";
private String repositoryId = ""; private String repositoryId = "";
private List<String> versions = new ArrayList<String>(); private List<String> versions = new ArrayList<String>();
/**
* Plugin goal prefix (only if packaging is "maven-plugin")
*/
public String prefix;
/**
* Plugin goals (only if packaging is "maven-plugin")
*/
public List<String> goals;
/** /**
* contains osgi metadata Bundle-Version if available * contains osgi metadata Bundle-Version if available
*
* @since 1.4 * @since 1.4
*/ */
private String bundleVersion; public String bundleVersion;
/** /**
* contains osgi metadata Bundle-SymbolicName if available * contains osgi metadata Bundle-SymbolicName if available
*
* @since 1.4 * @since 1.4
*/ */
private String bundleSymbolicName; public String bundleSymbolicName;
/** /**
* contains osgi metadata Export-Package if available * contains osgi metadata Export-Package if available
*
* @since 1.4 * @since 1.4
*/ */
private String bundleExportPackage; public String bundleExportPackage;
/** /**
* contains osgi metadata Export-Service if available * contains osgi metadata Export-Service if available
*
* @since 1.4 * @since 1.4
*/ */
private String bundleExportService; public String bundleExportService;
/**
* contains osgi metadata Bundle-Description if available
* @since 1.4
*/
public String bundleDescription;
/**
* contains osgi metadata Bundle-Name if available
* @since 1.4
*/
public String bundleName;
/**
* contains osgi metadata Bundle-License if available
* @since 1.4
*/
public String bundleLicense;
/**
* contains osgi metadata Bundle-DocURL if available
* @since 1.4
*/
public String bundleDocUrl;
/**
* contains osgi metadata Import-Package if available
* @since 1.4
*/
public String bundleImportPackage;
/**
* contains osgi metadata Require-Bundle if available
* @since 1.4
*/
public String bundleRequireBundle;
public String getContext() public String getContext()
{ {
@ -122,16 +161,6 @@ public class SearchResultHit
this.groupId = groupId; this.groupId = groupId;
} }
public String getVersion()
{
return version;
}
public void setVersion(String version)
{
this.version = version;
}
public List<String> getVersions() public List<String> getVersions()
{ {
return versions; return versions;
@ -197,6 +226,86 @@ public class SearchResultHit
this.bundleExportService = bundleExportService; this.bundleExportService = bundleExportService;
} }
public String getPrefix()
{
return prefix;
}
public void setPrefix( String prefix )
{
this.prefix = prefix;
}
public List<String> getGoals()
{
return goals;
}
public void setGoals( List<String> goals )
{
this.goals = goals;
}
public String getBundleDescription()
{
return bundleDescription;
}
public void setBundleDescription( String bundleDescription )
{
this.bundleDescription = bundleDescription;
}
public String getBundleName()
{
return bundleName;
}
public void setBundleName( String bundleName )
{
this.bundleName = bundleName;
}
public String getBundleLicense()
{
return bundleLicense;
}
public void setBundleLicense( String bundleLicense )
{
this.bundleLicense = bundleLicense;
}
public String getBundleDocUrl()
{
return bundleDocUrl;
}
public void setBundleDocUrl( String bundleDocUrl )
{
this.bundleDocUrl = bundleDocUrl;
}
public String getBundleImportPackage()
{
return bundleImportPackage;
}
public void setBundleImportPackage( String bundleImportPackage )
{
this.bundleImportPackage = bundleImportPackage;
}
public String getBundleRequireBundle()
{
return bundleRequireBundle;
}
public void setBundleRequireBundle( String bundleRequireBundle )
{
this.bundleRequireBundle = bundleRequireBundle;
}
@Override @Override
public String toString() public String toString()
{ {
@ -206,13 +315,20 @@ public class SearchResultHit
sb.append( ", url='" ).append( url ).append( '\'' ); sb.append( ", url='" ).append( url ).append( '\'' );
sb.append( ", groupId='" ).append( groupId ).append( '\'' ); sb.append( ", groupId='" ).append( groupId ).append( '\'' );
sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); sb.append( ", artifactId='" ).append( artifactId ).append( '\'' );
sb.append( ", version='" ).append( version ).append( '\'' );
sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' ); sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
sb.append( ", versions=" ).append( versions ); sb.append( ", versions=" ).append( versions );
sb.append( ", prefix='" ).append( prefix ).append( '\'' );
sb.append( ", goals=" ).append( goals );
sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' ); sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' );
sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' ); sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' );
sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' );
sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' );
sb.append( ", bundleDescription='" ).append( bundleDescription ).append( '\'' );
sb.append( ", bundleName='" ).append( bundleName ).append( '\'' );
sb.append( ", bundleLicense='" ).append( bundleLicense ).append( '\'' );
sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' );
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }

View File

@ -21,22 +21,37 @@ package org.apache.archiva.rest.api.model;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
@XmlRootElement( name = "artifact" ) @XmlRootElement( name = "artifact" )
public class Artifact public class Artifact
implements Serializable implements Serializable
{ {
private String repositoryId; // The (optional) context for this result.
private String context;
// Basic hit, direct to non-artifact resource.
private String url;
// Advanced hit, reference to groupId.
private String groupId; private String groupId;
// Advanced hit, reference to artifactId.
private String artifactId; private String artifactId;
private String repositoryId;
private String version; private String version;
private String type; /**
* Plugin goal prefix (only if packaging is "maven-plugin")
*/
private String prefix;
private String url; /**
* Plugin goals (only if packaging is "maven-plugin")
*/
private List<String> goals;
/** /**
* contains osgi metadata Bundle-Version if available * contains osgi metadata Bundle-Version if available
@ -66,21 +81,54 @@ public class Artifact
*/ */
private String bundleExportService; private String bundleExportService;
/**
* contains osgi metadata Bundle-Description if available
*
* @since 1.4
*/
private String bundleDescription;
/**
* contains osgi metadata Bundle-Name if available
*
* @since 1.4
*/
private String bundleName;
/**
* contains osgi metadata Bundle-License if available
*
* @since 1.4
*/
private String bundleLicense;
/**
* contains osgi metadata Bundle-DocURL if available
*
* @since 1.4
*/
private String bundleDocUrl;
/**
* contains osgi metadata Import-Package if available
*
* @since 1.4
*/
private String bundleImportPackage;
/**
* contains osgi metadata Require-Bundle if available
*
* @since 1.4
*/
private String bundleRequireBundle;
public Artifact() public Artifact()
{ {
// no op // no op
} }
public Artifact( String repositoryId, String groupId, String artifactId, String version, String type )
{
this.repositoryId = repositoryId;
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.type = type;
}
public String getGroupId() public String getGroupId()
{ {
return groupId; return groupId;
@ -96,11 +144,6 @@ public class Artifact
return version; return version;
} }
public String getType()
{
return type;
}
public String getRepositoryId() public String getRepositoryId()
{ {
return repositoryId; return repositoryId;
@ -121,63 +164,149 @@ public class Artifact
this.version = version; this.version = version;
} }
public void setType( String type )
{
this.type = type;
}
public void setRepositoryId( String repositoryId ) public void setRepositoryId( String repositoryId )
{ {
this.repositoryId = repositoryId; this.repositoryId = repositoryId;
} }
@Override public String getContext()
public boolean equals( Object o )
{ {
if ( this == o ) return context;
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
Artifact artifact = (Artifact) o;
if ( !artifactId.equals( artifact.artifactId ) )
{
return false;
}
if ( !groupId.equals( artifact.groupId ) )
{
return false;
}
if ( !repositoryId.equals( artifact.repositoryId ) )
{
return false;
}
if ( type != null ? !type.equals( artifact.type ) : artifact.type != null )
{
return false;
}
if ( !version.equals( artifact.version ) )
{
return false;
}
return true;
} }
@Override public void setContext( String context )
public int hashCode()
{ {
int result = repositoryId.hashCode(); this.context = context;
result = 31 * result + groupId.hashCode(); }
result = 31 * result + artifactId.hashCode();
result = 31 * result + version.hashCode(); public String getUrl()
result = 31 * result + ( type != null ? type.hashCode() : 0 ); {
return result; return url;
}
public void setUrl( String url )
{
this.url = url;
}
public String getPrefix()
{
return prefix;
}
public void setPrefix( String prefix )
{
this.prefix = prefix;
}
public List<String> getGoals()
{
return goals;
}
public void setGoals( List<String> goals )
{
this.goals = goals;
}
public String getBundleVersion()
{
return bundleVersion;
}
public void setBundleVersion( String bundleVersion )
{
this.bundleVersion = bundleVersion;
}
public String getBundleSymbolicName()
{
return bundleSymbolicName;
}
public void setBundleSymbolicName( String bundleSymbolicName )
{
this.bundleSymbolicName = bundleSymbolicName;
}
public String getBundleExportPackage()
{
return bundleExportPackage;
}
public void setBundleExportPackage( String bundleExportPackage )
{
this.bundleExportPackage = bundleExportPackage;
}
public String getBundleExportService()
{
return bundleExportService;
}
public void setBundleExportService( String bundleExportService )
{
this.bundleExportService = bundleExportService;
}
public String getBundleDescription()
{
return bundleDescription;
}
public void setBundleDescription( String bundleDescription )
{
this.bundleDescription = bundleDescription;
}
public String getBundleName()
{
return bundleName;
}
public void setBundleName( String bundleName )
{
this.bundleName = bundleName;
}
public String getBundleLicense()
{
return bundleLicense;
}
public void setBundleLicense( String bundleLicense )
{
this.bundleLicense = bundleLicense;
}
public String getBundleDocUrl()
{
return bundleDocUrl;
}
public void setBundleDocUrl( String bundleDocUrl )
{
this.bundleDocUrl = bundleDocUrl;
}
public String getBundleImportPackage()
{
return bundleImportPackage;
}
public void setBundleImportPackage( String bundleImportPackage )
{
this.bundleImportPackage = bundleImportPackage;
}
public String getBundleRequireBundle()
{
return bundleRequireBundle;
}
public void setBundleRequireBundle( String bundleRequireBundle )
{
this.bundleRequireBundle = bundleRequireBundle;
} }
@Override @Override
@ -185,11 +314,24 @@ public class Artifact
{ {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append( "Artifact" ); sb.append( "Artifact" );
sb.append( "{repositoryId='" ).append( repositoryId ).append( '\'' ); sb.append( "{context='" ).append( context ).append( '\'' );
sb.append( ", url='" ).append( url ).append( '\'' );
sb.append( ", groupId='" ).append( groupId ).append( '\'' ); sb.append( ", groupId='" ).append( groupId ).append( '\'' );
sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); sb.append( ", artifactId='" ).append( artifactId ).append( '\'' );
sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
sb.append( ", version='" ).append( version ).append( '\'' ); sb.append( ", version='" ).append( version ).append( '\'' );
sb.append( ", type='" ).append( type ).append( '\'' ); sb.append( ", prefix='" ).append( prefix ).append( '\'' );
sb.append( ", goals=" ).append( goals );
sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' );
sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' );
sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' );
sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' );
sb.append( ", bundleDescription='" ).append( bundleDescription ).append( '\'' );
sb.append( ", bundleName='" ).append( bundleName ).append( '\'' );
sb.append( ", bundleLicense='" ).append( bundleLicense ).append( '\'' );
sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' );
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }

View File

@ -60,7 +60,7 @@ public interface ManagedRepositoriesService
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
Boolean deleteManagedRepository( @QueryParam( "repositoryId" ) String repositoryId, Boolean deleteManagedRepository( @QueryParam( "repositoryId" ) String repositoryId,
@QueryParam( "deleteContent" ) boolean deleteContent ) @QueryParam( "deleteContent" ) boolean deleteContent )
throws Exception; throws ArchivaRestServiceException;
@Path( "addManagedRepository" ) @Path( "addManagedRepository" )
@ -69,7 +69,7 @@ public interface ManagedRepositoriesService
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
Boolean addManagedRepository( ManagedRepository managedRepository ) Boolean addManagedRepository( ManagedRepository managedRepository )
throws Exception; throws ArchivaRestServiceException;
@Path( "updateManagedRepository" ) @Path( "updateManagedRepository" )
@ -78,7 +78,7 @@ public interface ManagedRepositoriesService
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
Boolean updateManagedRepository( ManagedRepository managedRepository ) Boolean updateManagedRepository( ManagedRepository managedRepository )
throws Exception; throws ArchivaRestServiceException;

View File

@ -50,13 +50,6 @@ public interface SearchService
List<Artifact> quickSearch( @QueryParam( "queryString" ) String queryString ) List<Artifact> quickSearch( @QueryParam( "queryString" ) String queryString )
throws ArchivaRestServiceException; throws ArchivaRestServiceException;
@Path( "getArtifactByChecksum" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noPermission = true, noRestriction = true )
List<Artifact> getArtifactByChecksum( @QueryParam( "checksum" ) String checksum )
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 } )
@ -74,4 +67,11 @@ public interface SearchService
@QueryParam( "version" ) String version ) @QueryParam( "version" ) String version )
throws ArchivaRestServiceException; throws ArchivaRestServiceException;
@Path( "getArtifactByChecksum" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noPermission = true, noRestriction = true )
List<Artifact> getArtifactByChecksum( @QueryParam( "checksum" ) String checksum )
throws ArchivaRestServiceException;
} }

View File

@ -23,6 +23,8 @@ import org.apache.archiva.audit.AuditListener;
import org.codehaus.plexus.redback.users.User; import org.codehaus.plexus.redback.users.User;
import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal; import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
import org.codehaus.redback.rest.services.RedbackRequestInformation; import org.codehaus.redback.rest.services.RedbackRequestInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,6 +39,8 @@ import java.util.List;
public abstract class AbstractRestService public abstract class AbstractRestService
{ {
protected Logger log = LoggerFactory.getLogger( getClass() );
@Inject @Inject
private List<AuditListener> auditListeners = new ArrayList<AuditListener>(); private List<AuditListener> auditListeners = new ArrayList<AuditListener>();

View File

@ -20,6 +20,7 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.rest.api.model.ManagedRepository; import org.apache.archiva.rest.api.model.ManagedRepository;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService; import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
@ -43,6 +44,10 @@ public class DefaultManagedRepositoriesService
@Inject @Inject
private ManagedRepositoryAdmin managedRepositoryAdmin; private ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
private PlexusSisuBridge plexusSisuBridge;
public List<ManagedRepository> getManagedRepositories() public List<ManagedRepository> getManagedRepositories()
throws ArchivaRestServiceException throws ArchivaRestServiceException
{ {
@ -87,14 +92,22 @@ public class DefaultManagedRepositoriesService
public Boolean deleteManagedRepository( String repoId, boolean deleteContent ) public Boolean deleteManagedRepository( String repoId, boolean deleteContent )
throws Exception throws ArchivaRestServiceException
{ {
return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent ); try
{
return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent );
}
catch ( RepositoryAdminException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage() );
}
} }
public Boolean addManagedRepository( ManagedRepository managedRepository ) public Boolean addManagedRepository( ManagedRepository managedRepository )
throws Exception throws ArchivaRestServiceException
{ {
org.apache.archiva.admin.model.managed.ManagedRepository repo = org.apache.archiva.admin.model.managed.ManagedRepository repo =
new org.apache.archiva.admin.model.managed.ManagedRepository(); new org.apache.archiva.admin.model.managed.ManagedRepository();
@ -106,13 +119,20 @@ public class DefaultManagedRepositoriesService
repo.setName( managedRepository.getName() ); repo.setName( managedRepository.getName() );
repo.setReleases( managedRepository.isReleases() ); repo.setReleases( managedRepository.isReleases() );
repo.setSnapshots( managedRepository.isSnapshots() ); repo.setSnapshots( managedRepository.isSnapshots() );
return managedRepositoryAdmin.addManagedRepository( repo, managedRepository.isStageRepoNeeded(), try
getAuditInformation() ); {
return managedRepositoryAdmin.addManagedRepository( repo, managedRepository.isStageRepoNeeded(),
getAuditInformation() );
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage() );
}
} }
public Boolean updateManagedRepository( ManagedRepository managedRepository ) public Boolean updateManagedRepository( ManagedRepository managedRepository )
throws Exception throws ArchivaRestServiceException
{ {
org.apache.archiva.admin.model.managed.ManagedRepository repo = org.apache.archiva.admin.model.managed.ManagedRepository repo =
new org.apache.archiva.admin.model.managed.ManagedRepository(); new org.apache.archiva.admin.model.managed.ManagedRepository();
@ -124,9 +144,16 @@ public class DefaultManagedRepositoriesService
repo.setName( managedRepository.getName() ); repo.setName( managedRepository.getName() );
repo.setReleases( managedRepository.isReleases() ); repo.setReleases( managedRepository.isReleases() );
repo.setSnapshots( managedRepository.isSnapshots() ); repo.setSnapshots( managedRepository.isSnapshots() );
return managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.isStageRepoNeeded(), try
getAuditInformation(), {
managedRepository.isResetStats() ); return managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.isStageRepoNeeded(),
getAuditInformation(),
managedRepository.isResetStats() );
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage() );
}
} }
} }

View File

@ -126,6 +126,7 @@ public class DefaultRepositoriesService
mavenIndexerUtils.getAllIndexCreators() ) ); mavenIndexerUtils.getAllIndexCreators() ) );
ArtifactIndexingTask task = ArtifactIndexingTask task =
new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context ); new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context );
task.setExecuteOnEntireRepo( true ); task.setExecuteOnEntireRepo( true );
task.setOnlyUpdate( false ); task.setOnlyUpdate( false );
@ -134,6 +135,7 @@ public class DefaultRepositoriesService
} }
catch ( Exception e ) catch ( Exception e )
{ {
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage() ); throw new ArchivaRestServiceException( e.getMessage() );
} }
} }

View File

@ -21,6 +21,7 @@ package org.apache.archiva.rest.services;
import net.sf.beanlib.provider.replicator.BeanReplicator; import net.sf.beanlib.provider.replicator.BeanReplicator;
import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.RepositorySearch;
import org.apache.archiva.indexer.search.RepositorySearchException; import org.apache.archiva.indexer.search.RepositorySearchException;
import org.apache.archiva.indexer.search.SearchFields;
import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResultHit;
import org.apache.archiva.indexer.search.SearchResultLimits; import org.apache.archiva.indexer.search.SearchResultLimits;
import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.indexer.search.SearchResults;
@ -85,16 +86,30 @@ public class DefaultSearchService
} }
} }
public List<Artifact> getArtifactByChecksum( String checksum )
throws ArchivaRestServiceException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public List<Artifact> getArtifactVersions( String groupId, String artifactId ) public List<Artifact> getArtifactVersions( String groupId, String artifactId )
throws ArchivaRestServiceException throws ArchivaRestServiceException
{ {
return null; //To change body of implemented methods use File | Settings | File Templates. if ( StringUtils.isBlank( groupId ) || StringUtils.isBlank( artifactId ) )
{
return Collections.emptyList();
}
SearchFields searchField = new SearchFields();
searchField.setGroupId( groupId );
searchField.setArtifactId( artifactId );
SearchResultLimits limits = new SearchResultLimits( 0 );
try
{
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
return getArtifacts( searchResults );
}
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 )
@ -103,6 +118,12 @@ public class DefaultSearchService
return null; //To change body of implemented methods use File | Settings | File Templates. return null; //To change body of implemented methods use File | Settings | File Templates.
} }
public List<Artifact> getArtifactByChecksum( String checksum )
throws ArchivaRestServiceException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
protected List<String> getObservableRepos() protected List<String> getObservableRepos()
{ {
@ -144,18 +165,45 @@ public class DefaultSearchService
return Collections.emptyList(); return Collections.emptyList();
} }
List<Artifact> artifacts = new ArrayList<Artifact>( searchResults.getReturnedHitsCount() ); List<Artifact> artifacts = new ArrayList<Artifact>( searchResults.getReturnedHitsCount() );
for ( SearchResultHit searchResultHit : searchResults.getHits() ) for ( SearchResultHit hit : searchResults.getHits() )
{ {
Artifact artifact = new BeanReplicator().replicateBean( searchResultHit, Artifact.class );
artifacts.add( artifact );
// duplicate Artifact one per available version // duplicate Artifact one per available version
if ( searchResultHit.getVersions().size() > 1 ) if ( hit.getVersions().size() > 0 )
{ {
for ( String version : searchResultHit.getVersions() ) for ( String version : hit.getVersions() )
{ {
Artifact versionned = new BeanReplicator().replicateBean( searchResultHit, Artifact.class ); /*
versionned.setVersion( version ); Artifact versionned = new Artifact( );
artifacts.add( versionned ); versionned.setArtifactId( hit.getArtifactId());
versionned.setGroupId( hit.getGroupId() );
versionned.setRepositoryId(hit.getRepositoryId() );
versionned.setBundleExportPackage( hit.getBundleExportPackage() );
versionned.setBundleExportService( hit.getBundleExportService());
versionned.setBundleSymbolicName(hit.getBundleSymbolicName() );
versionned.setBundleVersion( artifactInfo.bundleVersion );
versionned.setBundleDescription( artifactInfo.bundleDescription );
versionned.setBundleDocUrl( artifactInfo.bundleDocUrl );
versionned.setBundleRequireBundle( artifactInfo.bundleRequireBundle );
versionned.setBundleImportPackage( artifactInfo.bundleImportPackage );
versionned.setBundleLicense( artifactInfo.bundleLicense );
versionned.setBundleName( artifactInfo.bundleName );
versionned.setContext( artifactInfo.context );
versionned.setGoals( artifactInfo.goals );
versionned.setPrefix( artifactInfo.prefix );
// sure ??
versionned.setUrl( artifactInfo.remoteUrl );
*/
// FIXME archiva url ??
Artifact versionned = new BeanReplicator().replicateBean( hit, Artifact.class );
if ( StringUtils.isNotBlank( version ) )
{
versionned.setVersion( version );
artifacts.add( versionned );
}
} }
} }
} }

View File

@ -34,6 +34,8 @@ import java.util.List;
public class SearchServiceTest public class SearchServiceTest
extends AbstractArchivaRestTest extends AbstractArchivaRestTest
{ {
@Test @Test
public void quickSearchOnArtifactId() public void quickSearchOnArtifactId()
throws Exception throws Exception
@ -46,28 +48,49 @@ public class SearchServiceTest
assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
} }
createAndIndexRepo( testRepoId ); File targetRepo = createAndIndexRepo( testRepoId );
SearchService searchService = getSearchService( authorizationHeader ); SearchService searchService = getSearchService( authorizationHeader );
List<Artifact> artifacts = searchService.quickSearch( "commons-logging" ); List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
assertNotNull( artifacts ); assertNotNull( artifacts );
assertTrue( " empty results for commons-logging search", artifacts.size() > 0 ); assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
log.info( "artifacts for commons-logginf search {}", artifacts ); log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId ); deleteTestRepo( testRepoId, targetRepo );
} }
private void createAndIndexRepo( String testRepoId ) @Test
public void searchArtifactVersions()
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 );
List<Artifact> artifacts = searchService.getArtifactVersions( "commons-logging", "commons-logging" );
assertNotNull( artifacts );
assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo );
}
private File createAndIndexRepo( String testRepoId )
throws Exception throws Exception
{ {
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" ); File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
cleanupFiles( targetRepo );
if ( targetRepo.exists() )
{
FileUtils.deleteDirectory( targetRepo );
}
File sourceRepo = new File( "src/test/repo-with-osgi" ); File sourceRepo = new File( "src/test/repo-with-osgi" );
@ -76,24 +99,54 @@ public class SearchServiceTest
ManagedRepository managedRepository = new ManagedRepository(); ManagedRepository managedRepository = new ManagedRepository();
managedRepository.setId( testRepoId ); managedRepository.setId( testRepoId );
managedRepository.setName( "test repo" ); managedRepository.setName( "test repo" );
managedRepository.setCronExpression( "* * * * * ?" );
managedRepository.setScanned( false );
managedRepository.setLocation( targetRepo.getPath() ); managedRepository.setLocation( targetRepo.getPath() );
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader ); ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
service.addManagedRepository( managedRepository ); service.addManagedRepository( managedRepository );
getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true ); getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
return targetRepo;
} }
private void deleteTestRepo( String id ) private void deleteTestRepo( String id, File targetRepo )
throws Exception throws Exception
{ {
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null ) if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )
{ {
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, true ); getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, true );
} }
cleanupFiles( targetRepo );
}
private void cleanupFiles(File targetRepo)
throws Exception
{
File indexerDir = new File( targetRepo, ".indexer" );
if ( targetRepo.exists() )
{
FileUtils.deleteDirectory( targetRepo );
}
if ( indexerDir.exists() )
{
FileUtils.deleteDirectory( indexerDir );
}
File lockFile = new File( indexerDir, "write.lock" );
if ( lockFile.exists() )
{
FileUtils.forceDelete( lockFile );
}
assertFalse( targetRepo.exists() );
assertFalse( indexerDir.exists() );
assertFalse( lockFile.exists() );
} }
} }

View File

@ -38,14 +38,14 @@
<logger name="org.codehaus.redback.rest.services" > <logger name="org.codehaus.redback.rest.services" >
<level value="debug"/> <level value="ERROR"/>
</logger> </logger>
<logger name="JPOX"> <logger name="JPOX">
<level value="ERROR"/> <level value="ERROR"/>
</logger> </logger>
<logger name="org.springframework"> <logger name="org.springframework">
<level value="info"/> <level value="ERROR"/>
</logger> </logger>
<root> <root>