[MRM-1703] Cannot delete project with the ui.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1400901 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-10-22 14:49:23 +00:00
parent 555d674987
commit 0af1bd62e7
13 changed files with 306 additions and 92 deletions

View File

@ -32,8 +32,6 @@
/**
* ManagedRepositoryContent interface for interacting with a managed repository in an abstract way,
* without the need for processing based on filesystem paths, or working with the database.
*
*
*/
public interface ManagedRepositoryContent
{
@ -57,13 +55,22 @@ void deleteArtifact( ArtifactReference artifactReference )
throws ContentNotFoundException;
/**
* @since 1.4-M3
* @param groupId
* @throws ContentNotFoundException
* @since 1.4-M3
*/
void deleteGroupId( String groupId )
throws ContentNotFoundException;
/**
*
* @param namespace groupId for maven
* @param projectId artifactId for maven
* @throws ContentNotFoundException
*/
void deleteProject( String namespace, String projectId )
throws RepositoryException;
/**
* <p>
* Convenience method to get the repository id.

View File

@ -19,16 +19,16 @@
* under the License.
*/
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
import org.apache.commons.lang.StringUtils;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,8 +38,6 @@
/**
* AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout.
*
*
*/
public abstract class AbstractDefaultRepositoryContent
{
@ -120,11 +118,15 @@ public String toPath( ArtifactReference reference )
{
throw new IllegalArgumentException( "Artifact reference cannot be null" );
}
if ( reference.getVersion() != null )
{
String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
reference.getClassifier(), reference.getType() );
}
return toPath( reference.getGroupId(), reference.getArtifactId(), null, null,
reference.getClassifier(), reference.getType() );
}
private String formatAsDirectory( String directory )
{

View File

@ -29,6 +29,7 @@
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
@ -45,8 +46,6 @@
/**
* ManagedDefaultRepositoryContent
*
*
*/
@Service ("managedRepositoryContent#default")
@Scope ("prototype")
@ -78,6 +77,36 @@ public void deleteVersion( VersionedReference reference )
}
}
public void deleteProject( String namespace, String projectId )
throws RepositoryException, ContentNotFoundException
{
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setGroupId( namespace );
artifactReference.setArtifactId( projectId );
String path = toPath( artifactReference );
File directory = new File( getRepoRoot(), path );
if ( !directory.exists() )
{
throw new ContentNotFoundException( "cannot found project " + namespace + ":" + projectId );
}
if ( directory.isDirectory() )
{
try
{
FileUtils.deleteDirectory( directory );
}
catch ( IOException e )
{
throw new RepositoryException( e.getMessage(), e );
}
}
else
{
log.warn( "project {}:{} is not a directory", namespace, projectId );
}
}
public void deleteArtifact( ArtifactReference artifactReference )
{
String path = toPath( artifactReference );

View File

@ -28,6 +28,7 @@
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
@ -128,6 +129,12 @@ private void deleteVersions( File typeDir, VersionedReference reference )
}
}
public void deleteProject( String namespace, String projectId )
throws RepositoryException
{
// TODO implements ??
}
private void deleteSupportFiles( File repoFile )
{
deleteSupportFile( repoFile, ".sha1" );

View File

@ -20,13 +20,13 @@
*/
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.repository.scanner.RepositoryScanStatistics;
import org.apache.archiva.rest.api.model.ArtifactTransferRequest;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@ -34,7 +34,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
/**
* @author Olivier Lamy
@ -139,10 +138,20 @@ Boolean isAuthorizedToDeleteArtifacts( @PathParam ( "repositoryId" ) String repo
* <b>permissions are checked in impl</b>
* @since 1.4-M3
*/
Boolean deleteGroupId( @QueryParam ( "groupId" ) String groupId,
@QueryParam ( "repositoryId" ) String repositoryId )
Boolean deleteGroupId( @QueryParam ("groupId") String groupId, @QueryParam ("repositoryId") String repositoryId )
throws ArchivaRestServiceException;
@Path ( "project/{repositoryId}/{groupId}/{projectId}" )
@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 deleteProject( @PathParam ( "groupId" ) String groupId, @PathParam ( "projectId" ) String projectId,
@PathParam ( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
}

View File

@ -851,7 +851,7 @@ public Boolean deleteGroupId( String groupId, String repositoryId )
if ( StringUtils.isEmpty( groupId ) )
{
throw new ArchivaRestServiceException( "artifact.groupId cannot be null", 400, null );
throw new ArchivaRestServiceException( "groupId cannot be null", 400, null );
}
RepositorySession repositorySession = repositorySessionFactory.createSession();
@ -886,6 +886,70 @@ public Boolean deleteGroupId( String groupId, String repositoryId )
return true;
}
public Boolean deleteProject( String groupId, String projectId, 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( "groupId cannot be null", 400, null );
}
if ( StringUtils.isEmpty( projectId ) )
{
throw new ArchivaRestServiceException( "artifactId cannot be null", 400, null );
}
RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
repository.deleteProject( groupId, projectId );
}
catch ( ContentNotFoundException e )
{
log.warn( "skip ContentNotFoundException: {}", e.getMessage() );
}
catch ( RepositoryException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
try
{
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeProject( repositoryId, groupId, projectId );
metadataRepository.save();
}
catch ( MetadataRepositoryException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
}
finally
{
repositorySession.close();
}
return true;
}
public Boolean isAuthorizedToDeleteArtifacts( String repoId )
throws ArchivaRestServiceException
{

View File

@ -195,6 +195,7 @@ function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,ko) {
}
this.save=function(){
$.log('managedrepo save');
var valid = $("#main-content").find("#managed-repository-edit-form").valid();
if (valid==false) {
return;

View File

@ -86,6 +86,55 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
return hasKarma('archiva-delete-artifact');
}
deleteProject=function(groupId,projectId){
$.log("deleteProject:"+groupId+"/"+projectId);
var repoId=getSelectedBrowsingRepository();
if(!repoId){
var escapedGroupId=escapeDot(groupId );
var selected = $("#main-content" ).find("#delete-"+escapedGroupId );
selected.attr("data-content",$.i18n.prop('projectId.delete.missing.repoId'))
selected.popover({
html:true,
template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><div class="popover-content"><p></p></div></div></div>',
placement:'top',
trigger:'manual'});
selected.popover('show');
selected.mouseover(function(){
selected.popover("destroy");
});
return;
}
var previousHash=getUrlHash();
$.log("previousHash:"+previousHash);
openDialogConfirm(function(){
$("#dialog-confirm-modal-ok").button('loading');
$.ajax({
url:"restServices/archivaServices/repositoriesService/project/"+repoId+"/"+groupId+"/"+projectId,
type:"DELETE",
dataType:"json",
success:function(data){
window.sammyArchivaApplication.setLocation(previousHash);
refreshContent();
displaySuccessMessage( $.i18n.prop("projectId.deleted", groupId,projectId));
},
error:function(data){
displayRestError(data,"user-messages");
},
complete:function(){
$("#dialog-confirm-modal-ok").button('reset');
closeDialogConfirm();
}
});
}, $.i18n.prop('ok'),
$.i18n.prop('cancel'),
$.i18n.prop('projectId.delete.confirm.title'),
$.i18n.prop('projectId.delete.confirm.save',groupId));
}
}
deleteGroupId=function(groupId){
var repoId=getSelectedBrowsingRepository();
@ -129,7 +178,7 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
$.i18n.prop('cancel'),
$.i18n.prop('groupId.delete.confirm.title'),
$.i18n.prop('groupId.delete.confirm.save',groupId));
}
}
calculateBreadCrumbEntries=function(groupId){

View File

@ -53,7 +53,7 @@
{{if browseResultEntry.project}}
{{if deleteKarma}}
<li class="browse-list-project">
<img id="delete-${browseResultEntry.name}" src="images/trash.png" data-bind="click:function(){deleteGroupId(browseResultEntry.name)}"/>
<img id="delete-${browseResultEntry.name}" src="images/trash.png" data-bind="click:function(){deleteProject(groupId,displayEntry(browseResultEntry.name))}"/>
<a href="#" data-bind="click:function(){displayProjectEntry(browseResultEntry.name)}">${displayEntry(browseResultEntry.name)}</a>
</li>
{{else}}

View File

@ -160,13 +160,12 @@ Collection<String> getProjectVersions( String repoId, String namespace, String p
throws MetadataResolutionException;
/**
*
* @param repoId
* @param namespace
* @param projectId
* @param projectVersion
* @since 1.4-M4
* @throws MetadataResolutionException
* @since 1.4-M4
*/
void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
throws MetadataRepositoryException;
@ -175,6 +174,18 @@ Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, Stri
String projectVersion )
throws MetadataResolutionException;
/**
* remove a project
* @param repositoryId
* @param namespace
* @param projectId
* @throws MetadataRepositoryException
* @since 1.4-M4
*/
void removeProject( String repositoryId, String namespace, String projectId )
throws MetadataRepositoryException;
void save();
void close()

View File

@ -1162,6 +1162,11 @@ public Collection<String> getProjectVersions( String repoId, String namespace, S
return projectVersions;
}
public void removeProject( String repositoryId, String namespace, String projectId )
throws MetadataRepositoryException
{
// TODO
}
public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
throws MetadataRepositoryException

View File

@ -62,6 +62,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -367,6 +368,35 @@ public void updateNamespace( String repositoryId, String namespace )
}
}
public void removeProject( String repositoryId, String namespace, String projectId )
throws MetadataRepositoryException
{
try
{
Node root = getJcrSession().getRootNode();
String namespacePath = getNamespacePath( repositoryId, namespace );
if ( root.hasNode( namespacePath ) )
{
Iterator<Node> nodeIterator = JcrUtils.getChildNodes( root.getNode( namespacePath ) ).iterator();
while ( nodeIterator.hasNext() )
{
Node node = nodeIterator.next();
if ( node.isNodeType( PROJECT_NODE_TYPE ) && projectId.equals( node.getName() ) )
{
node.remove();
}
}
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
}
public List<String> getMetadataFacets( String repositoryId, String facetId )
throws MetadataRepositoryException
{