Browse Source

fix deletion of project version when it's snapshot version, timestamped was not deleted

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1401075 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-1.4-M4
Olivier Lamy 11 years ago
parent
commit
bcc39e49ae

+ 18
- 5
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java View File

@@ -123,6 +123,19 @@ public interface RepositoriesService
Boolean deleteArtifact( Artifact artifact )
throws ArchivaRestServiceException;

@Path ("projectVersion/{repositoryId}/{namespace}/{projectId}/{version}")
@DELETE
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
@RedbackAuthorization (noPermission = true)
/**
* <b>permissions are checked in impl</b>
* @since 1.4-M4
*/
Boolean removeProjectVersion( @PathParam ( "repositoryId" ) String repositoryId,
@PathParam ( "namespace" ) String namespace, @PathParam ( "projectId" ) String projectId,
@PathParam ( "version" ) String version )
throws ArchivaRestServiceException;

@Path ("isAuthorizedToDeleteArtifacts/{repositoryId}")
@GET
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
@@ -141,16 +154,16 @@ public interface RepositoriesService
Boolean deleteGroupId( @QueryParam ("groupId") String groupId, @QueryParam ("repositoryId") String repositoryId )
throws ArchivaRestServiceException;

@Path ( "project/{repositoryId}/{groupId}/{projectId}" )
@Path ("project/{repositoryId}/{groupId}/{projectId}")
@DELETE
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization ( noPermission = true )
@Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
@RedbackAuthorization (noPermission = true)
/**
* <b>permissions are checked in impl</b>
* @since 1.4-M4
*/
Boolean deleteProject( @PathParam ( "groupId" ) String groupId, @PathParam ( "projectId" ) String projectId,
@PathParam ( "repositoryId" ) String repositoryId )
Boolean deleteProject( @PathParam ("groupId") String groupId, @PathParam ("projectId") String projectId,
@PathParam ("repositoryId") String repositoryId )
throws ArchivaRestServiceException;



+ 105
- 1
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java View File

@@ -600,6 +600,109 @@ public class DefaultRepositoriesService
}
}

public Boolean removeProjectVersion( String repositoryId, String namespace, String projectId, String version )
throws ArchivaRestServiceException
{
// if not a generic we can use the standard way to delete artifact
if ( !VersionUtil.isGenericSnapshot( version ) )
{
Artifact artifact = new Artifact( namespace, projectId, version );
return deleteArtifact( artifact );
}

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( namespace ) )
{
throw new ArchivaRestServiceException( "groupId cannot be null", 400, null );
}

if ( StringUtils.isEmpty( projectId ) )
{
throw new ArchivaRestServiceException( "artifactId cannot be null", 400, null );
}

if ( StringUtils.isEmpty( version ) )
{
throw new ArchivaRestServiceException( "version cannot be null", 400, null );
}

RepositorySession repositorySession = repositorySessionFactory.createSession();

try
{
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );

VersionedReference ref = new VersionedReference();
ref.setArtifactId( projectId );
ref.setGroupId( namespace );
ref.setVersion( version );

repository.deleteVersion( ref );

/*
ProjectReference projectReference = new ProjectReference();
projectReference.setGroupId( namespace );
projectReference.setArtifactId( projectId );

repository.getVersions( )
*/

ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setGroupId( namespace );
artifactReference.setArtifactId( projectId );
artifactReference.setVersion( version );

MetadataRepository metadataRepository = repositorySession.getRepository();

Set<ArtifactReference> related = repository.getRelatedArtifacts( artifactReference );
log.debug( "related: {}", related );
for ( ArtifactReference artifactRef : related )
{
repository.deleteArtifact( artifactRef );
}

Collection<ArtifactMetadata> artifacts =
metadataRepository.getArtifacts( repositoryId, namespace, projectId, version );

for ( ArtifactMetadata artifactMetadata : artifacts )
{
metadataRepository.removeArtifact( artifactMetadata, version );
}

metadataRepository.removeProjectVersion( repositoryId, namespace, projectId, version );
}
catch ( MetadataRepositoryException e )
{
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
catch ( MetadataResolutionException e )
{
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
catch ( RepositoryException e )
{
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
finally
{

repositorySession.save();

repositorySession.close();
}

return Boolean.TRUE;
}

public Boolean deleteArtifact( Artifact artifact )
throws ArchivaRestServiceException
{
@@ -632,7 +735,8 @@ public class DefaultRepositoriesService

// TODO more control on artifact fields

boolean snapshotVersion = VersionUtil.isSnapshot( artifact.getVersion() );
boolean snapshotVersion =
VersionUtil.isSnapshot( artifact.getVersion() ) | VersionUtil.isGenericSnapshot( artifact.getVersion() );

RepositorySession repositorySession = repositorySessionFactory.createSession();
try

+ 6
- 6
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js View File

@@ -270,17 +270,17 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
});
return;
}
$.log("deleteVersion:"+version+',repoId:'+repoId);
clearUserMessages();
var artifact = new Artifact(repoId,null,self.groupId,self.artifactId,repoId,version);
openDialogConfirm(function(){
var url = "restServices/archivaServices/repositoriesService/projectVersion/"+repoId;
url+="/"+encodeURIComponent(self.groupId)+"/"+encodeURIComponent(self.artifactId);
url+="/"+encodeURIComponent(version);
$("#dialog-confirm-modal-ok").button('loading');
$.ajax({
url:"restServices/archivaServices/repositoriesService/deleteArtifact",
type:"POST",
dataType:"json",
contentType: 'application/json',
data: ko.toJSON(artifact),
url:url,
type:"DELETE",
success:function(data){
self.versions.remove(version);
refreshContent();

Loading…
Cancel
Save