git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1346609 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M3
@@ -63,6 +63,14 @@ public class MockRepositorySessionFactory | |||
{ | |||
return new MetadataRepository( ) | |||
{ | |||
public void removeArtifact( String repositoryId, String namespace, String project, | |||
String projectVersion, String projectId, MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException | |||
{ | |||
} | |||
public void updateProject( String repositoryId, ProjectMetadata project ) | |||
throws MetadataRepositoryException | |||
{ |
@@ -63,6 +63,14 @@ public class MockRepositorySessionFactory | |||
{ | |||
return new MetadataRepository( ) | |||
{ | |||
public void removeArtifact( String repositoryId, String namespace, String project, | |||
String projectVersion, String projectId, MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException | |||
{ | |||
//To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
public void updateProject( String repositoryId, ProjectMetadata project ) | |||
throws MetadataRepositoryException | |||
{ |
@@ -63,30 +63,38 @@ public class MockRepositorySessionFactory | |||
{ | |||
return new MetadataRepository() | |||
{ | |||
public void removeArtifact( String repositoryId, String namespace, String project, | |||
String projectVersion, String projectId, MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException | |||
{ | |||
} | |||
public void updateProject( String repositoryId, ProjectMetadata project ) | |||
throws MetadataRepositoryException | |||
{ | |||
//To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
public void updateArtifact( String repositoryId, String namespace, String projectId, | |||
String projectVersion, ArtifactMetadata artifactMeta ) | |||
throws MetadataRepositoryException | |||
{ | |||
//To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
public void updateProjectVersion( String repositoryId, String namespace, String projectId, | |||
ProjectVersionMetadata versionMetadata ) | |||
throws MetadataRepositoryException | |||
{ | |||
//To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
public void updateNamespace( String repositoryId, String namespace ) | |||
throws MetadataRepositoryException | |||
{ | |||
//To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
public List<String> getMetadataFacets( String repositoryId, String facetId ) | |||
@@ -104,7 +112,7 @@ public class MockRepositorySessionFactory | |||
public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException | |||
{ | |||
//To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
public void removeMetadataFacets( String repositoryId, String facetId ) |
@@ -129,4 +129,15 @@ public interface RepositoriesService | |||
Boolean isAuthorizedToDeleteArtifacts( @PathParam( "repositoryId" ) String repoId ) | |||
throws ArchivaRestServiceException; | |||
@Path( "deleteGroupId" ) | |||
@GET | |||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) | |||
@RedbackAuthorization( noPermission = true ) | |||
/** | |||
* <b>permissions are checked in impl</b> | |||
* @since 1.4-M3 | |||
*/ | |||
Boolean deleteGroupId( @QueryParam( "groupId" ) String groupId ) | |||
throws ArchivaRestServiceException; | |||
} |
@@ -37,6 +37,7 @@ import org.apache.archiva.metadata.repository.MetadataRepositoryException; | |||
import org.apache.archiva.metadata.repository.MetadataResolutionException; | |||
import org.apache.archiva.metadata.repository.RepositorySession; | |||
import org.apache.archiva.metadata.repository.RepositorySessionFactory; | |||
import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; | |||
import org.apache.archiva.model.ArchivaRepositoryMetadata; | |||
import org.apache.archiva.model.ArtifactReference; | |||
import org.apache.archiva.model.VersionedReference; | |||
@@ -669,6 +670,10 @@ public class DefaultRepositoriesService | |||
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId ); | |||
MetadataRepository metadataRepository = repositorySession.getRepository(); | |||
String path = repository.toMetadataPath( ref ); | |||
if ( StringUtils.isNotBlank( artifact.getClassifier() ) ) | |||
{ | |||
if ( StringUtils.isBlank( artifact.getPackaging() ) ) | |||
@@ -684,45 +689,73 @@ public class DefaultRepositoriesService | |||
artifactReference.setType( artifact.getPackaging() ); | |||
repository.deleteArtifact( artifactReference ); | |||
// TODO cleanup facet which contains classifier information | |||
return Boolean.TRUE; | |||
} | |||
String path = repository.toMetadataPath( ref ); | |||
int index = path.lastIndexOf( '/' ); | |||
path = path.substring( 0, index ); | |||
File targetPath = new File( repoConfig.getLocation(), path ); | |||
if ( !targetPath.exists() ) | |||
else | |||
{ | |||
throw new ContentNotFoundException( | |||
artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() ); | |||
} | |||
// TODO: this should be in the storage mechanism so that it is all tied together | |||
// delete from file system | |||
repository.deleteVersion( ref ); | |||
int index = path.lastIndexOf( '/' ); | |||
path = path.substring( 0, index ); | |||
File targetPath = new File( repoConfig.getLocation(), path ); | |||
File metadataFile = getMetadata( targetPath.getAbsolutePath() ); | |||
ArchivaRepositoryMetadata metadata = getMetadata( metadataFile ); | |||
if ( !targetPath.exists() ) | |||
{ | |||
throw new ContentNotFoundException( | |||
artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() ); | |||
} | |||
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact ); | |||
// TODO: this should be in the storage mechanism so that it is all tied together | |||
// delete from file system | |||
repository.deleteVersion( ref ); | |||
MetadataRepository metadataRepository = repositorySession.getRepository(); | |||
File metadataFile = getMetadata( targetPath.getAbsolutePath() ); | |||
ArchivaRepositoryMetadata metadata = getMetadata( metadataFile ); | |||
updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact ); | |||
} | |||
Collection<ArtifactMetadata> artifacts = | |||
metadataRepository.getArtifacts( repositoryId, artifact.getGroupId(), artifact.getArtifactId(), | |||
artifact.getVersion() ); | |||
for ( ArtifactMetadata artifactMetadata : artifacts ) | |||
{ | |||
// TODO: mismatch between artifact (snapshot) version and project (base) version here | |||
if ( artifactMetadata.getVersion().equals( artifact.getVersion() ) ) | |||
{ | |||
metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(), | |||
artifactMetadata.getNamespace(), artifactMetadata.getProject(), | |||
artifact.getVersion(), artifactMetadata.getId() ); | |||
if ( StringUtils.isNotBlank( artifact.getClassifier() ) ) | |||
{ | |||
if ( StringUtils.isBlank( artifact.getPackaging() ) ) | |||
{ | |||
throw new ArchivaRestServiceException( | |||
"You must configure a type/packaging when using classifier", 400, null ); | |||
} | |||
// cleanup facet which contains classifier information | |||
MavenArtifactFacet mavenArtifactFacet = | |||
(MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID ); | |||
if ( StringUtils.equals( artifact.getClassifier(), mavenArtifactFacet.getClassifier() ) ) | |||
{ | |||
artifactMetadata.removeFacet( MavenArtifactFacet.FACET_ID ); | |||
String groupId = artifact.getGroupId(), artifactId = artifact.getArtifactId(), version = | |||
artifact.getVersion(); | |||
//metadataRepository.updateArtifact( repositoryId, groupId, artifactId, version, | |||
// artifactMetadata ); | |||
// String repositoryId, String namespace, String project, String version, String projectId, MetadataFacet metadataFacet | |||
MavenArtifactFacet mavenArtifactFacetToCompare = new MavenArtifactFacet(); | |||
mavenArtifactFacetToCompare.setClassifier( artifact.getClassifier() ); | |||
metadataRepository.removeArtifact( repositoryId, groupId, artifactId, version, | |||
mavenArtifactFacetToCompare ); | |||
metadataRepository.save(); | |||
} | |||
} | |||
else | |||
{ | |||
metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(), | |||
artifactMetadata.getNamespace(), | |||
artifactMetadata.getProject(), artifact.getVersion(), | |||
artifactMetadata.getId() ); | |||
} | |||
// TODO: move into the metadata repository proper - need to differentiate attachment of | |||
// repository metadata to an artifact | |||
for ( RepositoryListener listener : listeners ) | |||
@@ -736,11 +769,8 @@ public class DefaultRepositoriesService | |||
} | |||
} | |||
repositorySession.save(); | |||
repositorySession.close(); | |||
} | |||
catch ( ContentNotFoundException e ) | |||
{ | |||
throw new ArchivaRestServiceException( "Artifact does not exist: " + e.getMessage(), 400, e ); | |||
@@ -766,13 +796,20 @@ public class DefaultRepositoriesService | |||
throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 500, e ); | |||
} | |||
finally | |||
{ | |||
repositorySession.save(); | |||
repositorySession.close(); | |||
} | |||
return Boolean.TRUE; | |||
} | |||
public Boolean deleteGroupId( String groupId ) | |||
throws ArchivaRestServiceException | |||
{ | |||
return true; | |||
} | |||
public Boolean isAuthorizedToDeleteArtifacts( String repoId ) | |||
throws ArchivaRestServiceException | |||
{ |
@@ -22,13 +22,14 @@ package org.apache.archiva.rest.services; | |||
import org.apache.archiva.admin.model.beans.ManagedRepository; | |||
import org.apache.archiva.common.utils.FileUtil; | |||
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.VersionsList; | |||
import org.apache.archiva.rest.api.services.BrowseService; | |||
import org.apache.archiva.rest.api.services.ManagedRepositoriesService; | |||
import org.apache.archiva.rest.api.services.RepositoriesService; | |||
import org.apache.cxf.jaxrs.client.ServerWebApplicationException; | |||
import org.fest.assertions.Assertions; | |||
import org.junit.Ignore; | |||
import org.junit.Test; | |||
import java.io.File; | |||
@@ -189,7 +190,6 @@ public class RepositoriesServiceTest | |||
} | |||
@Test | |||
@Ignore | |||
public void deleteArtifactWithClassifier() | |||
throws Exception | |||
{ | |||
@@ -232,9 +232,15 @@ public class RepositoriesServiceTest | |||
artifacts = | |||
browseService.getArtifactDownloadInfos( "commons-logging", "commons-logging", "1.0.1", SOURCE_REPO_ID ); | |||
Assertions.assertThat( artifacts ).isNotNull().isEmpty(); | |||
log.info( "artifact: {}", artifacts ); | |||
Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 2 ); | |||
versionsList = browseService.getVersionsList( "commons-logging", "commons-logging", SOURCE_REPO_ID ); | |||
Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 5 ); | |||
log.info( "versionsList: {}", versionsList ); | |||
Assertions.assertThat( versionsList.getVersions() ).isNotNull().isNotEmpty().hasSize( 6 ); | |||
} | |||
finally | |||
@@ -244,6 +250,31 @@ public class RepositoriesServiceTest | |||
} | |||
@Test | |||
public void deleteGroupId() | |||
throws Exception | |||
{ | |||
initSourceTargetRepo(); | |||
try | |||
{ | |||
BrowseService browseService = getBrowseService( authorizationHeader, false ); | |||
BrowseResult browseResult = browseService.browseGroupId( "org.apache.karaf.features", SOURCE_REPO_ID ); | |||
assertNotNull( 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 ) ); | |||
log.info( "browseResult: {}", browseResult ); | |||
} | |||
finally | |||
{ | |||
cleanRepos(); | |||
} | |||
} | |||
@Test | |||
public void authorizedToDeleteArtifacts() | |||
throws Exception |
@@ -19,7 +19,6 @@ package org.apache.archiva.metadata.model; | |||
* under the License. | |||
*/ | |||
import javax.xml.bind.annotation.XmlElement; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
@@ -56,6 +55,11 @@ public abstract class FacetedMetadata | |||
return this.facets.get( facetId ); | |||
} | |||
public MetadataFacet removeFacet( String facetId ) | |||
{ | |||
return this.facets.remove( facetId ); | |||
} | |||
/** | |||
* Get all the facets available on this metadata. | |||
* |
@@ -79,6 +79,19 @@ public interface MetadataRepository | |||
void removeArtifact( String repositoryId, String namespace, String project, String version, String id ) | |||
throws MetadataRepositoryException; | |||
/** | |||
* @param repositoryId | |||
* @param namespace | |||
* @param project | |||
* @param version | |||
* @param metadataFacet will remove artifacts which have this {@link MetadataFacet} using equals | |||
* @throws MetadataRepositoryException | |||
* @since 1.4-M3 | |||
*/ | |||
void removeArtifact( String repositoryId, String namespace, String project, String version, | |||
MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException; | |||
/** | |||
* Delete a repository's metadata. This includes all associated metadata facets. | |||
* |
@@ -20,6 +20,7 @@ package org.apache.archiva.metadata.repository.storage.maven2; | |||
*/ | |||
import org.apache.archiva.metadata.model.MetadataFacet; | |||
import org.apache.commons.lang.StringUtils; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
@@ -118,4 +119,22 @@ public class MavenArtifactFacet | |||
this.buildNumber = Integer.parseInt( buildNumber ); | |||
} | |||
} | |||
@Override | |||
public boolean equals( Object o ) | |||
{ | |||
if ( this == o ) | |||
{ | |||
return true; | |||
} | |||
if ( !( o instanceof MavenArtifactFacet ) ) | |||
{ | |||
return false; | |||
} | |||
MavenArtifactFacet that = (MavenArtifactFacet) o; | |||
return StringUtils.equals( that.getClassifier(), this.classifier ); | |||
} | |||
} |
@@ -118,4 +118,43 @@ public class MavenProjectFacet | |||
this.parent = parent; | |||
} | |||
} | |||
@Override | |||
public boolean equals( Object o ) | |||
{ | |||
if ( this == o ) | |||
{ | |||
return true; | |||
} | |||
if ( !( o instanceof MavenProjectFacet ) ) | |||
{ | |||
return false; | |||
} | |||
MavenProjectFacet that = (MavenProjectFacet) o; | |||
if ( !artifactId.equals( that.artifactId ) ) | |||
{ | |||
return false; | |||
} | |||
if ( !groupId.equals( that.groupId ) ) | |||
{ | |||
return false; | |||
} | |||
if ( !packaging.equals( that.packaging ) ) | |||
{ | |||
return false; | |||
} | |||
return true; | |||
} | |||
@Override | |||
public int hashCode() | |||
{ | |||
int result = groupId.hashCode(); | |||
result = 31 * result + artifactId.hashCode(); | |||
result = 31 * result + packaging.hashCode(); | |||
return result; | |||
} | |||
} |
@@ -198,4 +198,12 @@ public class TestMetadataRepository | |||
{ | |||
return null; //To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
public void removeArtifact( String repositoryId, String namespace, String project, String projectVersion, | |||
String projectId, MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException | |||
{ | |||
//To change body of implemented methods use File | Settings | File Templates. | |||
} | |||
} |
@@ -35,8 +35,10 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata; | |||
import org.apache.archiva.metadata.model.ProjectVersionReference; | |||
import org.apache.archiva.metadata.model.Scm; | |||
import org.apache.archiva.metadata.repository.MetadataRepository; | |||
import org.apache.archiva.metadata.repository.MetadataRepositoryException; | |||
import org.apache.commons.io.FileUtils; | |||
import org.apache.commons.io.IOUtils; | |||
import org.apache.commons.lang.NotImplementedException; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
@@ -635,6 +637,23 @@ public class FileMetadataRepository | |||
} | |||
} | |||
/** | |||
* FIXME implements this !!!! | |||
* @param repositoryId | |||
* @param namespace | |||
* @param project | |||
* @param projectVersion | |||
* @param projectId | |||
* @param metadataFacet will remove artifacts which have this {@link MetadataFacet} using equals | |||
* @throws MetadataRepositoryException | |||
*/ | |||
public void removeArtifact( String repositoryId, String namespace, String project, String projectVersion, | |||
String projectId, MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException | |||
{ | |||
throw new NotImplementedException( "not implemented" ); | |||
} | |||
public void removeRepository( String repoId ) | |||
{ | |||
File dir = getDirectory( repoId ); |
@@ -194,6 +194,27 @@ public class JcrMetadataRepository | |||
node.setProperty( "version", artifactMeta.getVersion() ); | |||
// iterate over available facets to update/add/remove from the artifactMetadata | |||
for ( String facetId : metadataFacetFactories.keySet() ) | |||
{ | |||
MetadataFacet metadataFacet = artifactMeta.getFacet( facetId ); | |||
if ( node.hasNode( facetId ) ) | |||
{ | |||
node.getNode( facetId ).remove(); | |||
} | |||
if ( metadataFacet != null ) | |||
{ | |||
// recreate, to ensure properties are removed | |||
Node n = node.addNode( facetId ); | |||
n.addMixin( FACET_NODE_TYPE ); | |||
for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() ) | |||
{ | |||
n.setProperty( entry.getKey(), entry.getValue() ); | |||
} | |||
} | |||
} | |||
/* | |||
for ( MetadataFacet facet : artifactMeta.getFacetList() ) | |||
{ | |||
if ( node.hasNode( facet.getFacetId() ) ) | |||
@@ -210,6 +231,7 @@ public class JcrMetadataRepository | |||
n.setProperty( entry.getKey(), entry.getValue() ); | |||
} | |||
} | |||
*/ | |||
} | |||
catch ( RepositoryException e ) | |||
{ | |||
@@ -1011,6 +1033,40 @@ public class JcrMetadataRepository | |||
} | |||
} | |||
public void removeArtifact( String repositoryId, String namespace, String project, String projectVersion, | |||
MetadataFacet metadataFacet ) | |||
throws MetadataRepositoryException | |||
{ | |||
try | |||
{ | |||
Node root = getJcrSession().getRootNode(); | |||
String path = getProjectVersionPath( repositoryId, namespace, project, projectVersion ); | |||
if ( root.hasNode( path ) ) | |||
{ | |||
Node node = root.getNode( path ); | |||
for ( Node n : JcrUtils.getChildNodes( node ) ) | |||
{ | |||
if ( n.isNodeType( ARTIFACT_NODE_TYPE ) ) | |||
{ | |||
ArtifactMetadata artifactMetadata = getArtifactFromNode( repositoryId, n ); | |||
log.debug( "artifactMetadata: {}", artifactMetadata ); | |||
MetadataFacet metadataFacetToRemove = artifactMetadata.getFacet( metadataFacet.getFacetId() ); | |||
if ( metadataFacetToRemove != null && metadataFacet.equals( metadataFacetToRemove ) ) | |||
{ | |||
n.remove(); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
catch ( RepositoryException e ) | |||
{ | |||
throw new MetadataRepositoryException( e.getMessage(), e ); | |||
} | |||
} | |||
public Collection<ArtifactMetadata> getArtifacts( String repositoryId, String namespace, String projectId, | |||
String projectVersion ) | |||
throws MetadataResolutionException |