*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.util.Set;
/**
- * ManagedLegacyRepositoryContent
+ * ManagedLegacyRepositoryContent
*
* @version $Id$
- *
* @todo no need to be a component when filetypes, legacy path parser is not
*/
-@Service("managedRepositoryContent#legacy")
-@Scope("prototype")
+@Service( "managedRepositoryContent#legacy" )
+@Scope( "prototype" )
public class ManagedLegacyRepositoryContent
extends AbstractLegacyRepositoryContent
implements ManagedRepositoryContent
if ( !groupDir.exists() )
{
- throw new ContentNotFoundException( "Unable to get versions using a non-existant groupId directory: "
- + groupDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
}
if ( !groupDir.isDirectory() )
{
- throw new ContentNotFoundException( "Unable to get versions using a non-directory: "
- + groupDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
}
// First gather up the versions found as artifacts in the managed repository.
if ( !repoDir.exists() )
{
- throw new ContentNotFoundException( "Unable to get related artifacts using a non-existant directory: "
- + repoDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
- throw new ContentNotFoundException( "Unable to get related artifacts using a non-directory: "
- + repoDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
}
Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
if ( !groupDir.exists() )
{
- throw new ContentNotFoundException( "Unable to get versions using a non-existant groupId directory: "
- + groupDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
}
if ( !groupDir.isDirectory() )
{
- throw new ContentNotFoundException( "Unable to get versions using a non-directory: "
- + groupDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
if ( !groupDir.exists() )
{
- throw new ContentNotFoundException( "Unable to get versions using a non-existant groupId directory: "
- + groupDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
}
if ( !groupDir.isDirectory() )
{
- throw new ContentNotFoundException( "Unable to get versions using a non-directory: "
- + groupDir.getAbsolutePath() );
+ throw new ContentNotFoundException(
+ "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
/**
* Convert a path to an artifact reference.
- *
+ *
* @param path the path to convert. (relative or full location path)
* @throws LayoutException if the path cannot be converted to an artifact reference.
*/
return super.toArtifactReference( path );
}
-
+
public File toFile( ArchivaArtifact reference )
{
return new File( repository.getLocation(), toPath( reference ) );
}
}
}
-
+
public void setFileTypes( FileTypes fileTypes )
{
this.filetypes = fileTypes;
{
// TODO implements for legacy ??
}
+
+ public void deleteGroupId( String groupId )
+ throws ContentNotFoundException
+ {
+ // TODO implements for legacy ??
+ }
}
return Boolean.TRUE;
}
- public Boolean deleteGroupId( String groupId )
+ public Boolean deleteGroupId( String groupId, String repositoryId )
throws ArchivaRestServiceException
{
+ if ( StringUtils.isEmpty( repositoryId ) )
+ {
+ throw new ArchivaRestServiceException( "repositoryId cannot be null", 400, null );
+ }
+
+ if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )
+ {
+ throw new ArchivaRestServiceException( "not authorized to delete artifacts", 403, null );
+ }
+
+ if ( StringUtils.isEmpty( groupId ) )
+ {
+ throw new ArchivaRestServiceException( "artifact.groupId cannot be null", 400, null );
+ }
+
+ try
+ {
+ ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
+
+ repository.deleteGroupId( groupId );
+
+ }
+ catch ( RepositoryException e )
+ {
+ log.error( e.getMessage(), e );
+ throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
+ }
return true;
}
assertNotNull( browseResult );
+ log.info( "browseResult: {}", browseResult );
+
Assertions.assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isNotEmpty().contains(
new BrowseResultEntry( "org.apache.karaf.features.org.apache.karaf.features.command", true ),
new BrowseResultEntry( "org.apache.karaf.features.org.apache.karaf.features.core", true ) );
+ File directory =
+ new File( "target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.command" );
+
+ assertTrue( "directory not exists", directory.exists() );
+
+ RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
+ repositoriesService.deleteGroupId( "org.apache.karaf.features", SOURCE_REPO_ID );
+
+ assertFalse( "directory not exists", directory.exists() );
+
+ browseResult = browseService.browseGroupId( "org.apache.karaf.features", SOURCE_REPO_ID );
+
+ assertNotNull( browseResult );
+
+ Assertions.assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isEmpty();
+
log.info( "browseResult: {}", browseResult );
}
finally