Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

NEXUS-4878 - Add reason to not deletable error #340

Merged
merged 6 commits into from
Mar 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,7 @@ public synchronized void deleteRepository( String id )

if ( repository.getId().equals( shadow.getMasterRepository().getId() ) )
{
throw new ConfigurationException( "The repository with ID " + id
+ " is not deletable, it has dependant repositories!" );
throw new RepositoryDependentException( repository, shadow );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this exception gets logged for administrators, I think it is important to retain the mention of the repo ID value. Both name and id wouldn't hurt though.

Suggest this should read something more like:

"Repository [id= + id + ",name=" + repository.getName() + "] + "' cannot be deleted due to dependencies: shadow repository[id=" + shadow.getId() + ",name=" +shadow.getName()+"]."

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.sonatype.nexus.configuration.application;

import static java.lang.String.format;
import static org.sonatype.nexus.proxy.utils.RepositoryStringUtils.getHumanizedNameString;

import org.sonatype.configuration.ConfigurationException;
import org.sonatype.nexus.proxy.repository.Repository;

public class RepositoryDependentException
extends ConfigurationException
{

private static final long serialVersionUID = -2037859093869479166L;

private final Repository dependant;

private final Repository repository;

public RepositoryDependentException( Repository repository, Repository dependant )
{
super( format( "Repository %s cannot be deleted due to dependency: repository %s.",
getHumanizedNameString( repository ), getHumanizedNameString( dependant ) ) );
this.repository = repository;
this.dependant = dependant;
}

public Repository getDependant()
{
return dependant;
}

public Repository getRepository()
{
return repository;
}

public String getUIMessage()
{
return format(
"Repository '%s' cannot be deleted due to dependencies on repository '%s'.\nDependencies must be removed in order to complete this operation.",
getHumanizedNameString( repository ), getHumanizedNameString( dependant ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.sonatype.configuration.ConfigurationException;
import org.sonatype.nexus.configuration.application.RepositoryDependentException;
import org.sonatype.nexus.proxy.AccessDeniedException;
import org.sonatype.nexus.proxy.NoSuchRepositoryException;
import org.sonatype.nexus.proxy.StorageException;
Expand Down Expand Up @@ -377,12 +378,17 @@ public void delete( Context context, Request request, Response response )

response.setStatus( Status.SUCCESS_NO_CONTENT );
}
catch ( RepositoryDependentException e )
{
getLogger().info( e.getMessage() );

throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, e.getUIMessage(), e );
}
catch ( ConfigurationException e )
{
getLogger().warn( "Repository not deletable, it has dependants, id=" + repoId );
getLogger().warn( e.getMessage() );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps creating a more specific ConfigurationException here so in this case it can be logged as INFO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST,
"Repository is not deletable, it has dependants." );
throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(), e );
}
catch ( NoSuchRepositoryAccessException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,27 @@ Sonatype.repoServer.RepositoryPanel = function(config) {

Ext.extend(Sonatype.repoServer.RepositoryPanel, Sonatype.panels.GridViewer, {

deleteRecord : function(rec) {
Ext.Ajax.request({
callback : function(options, success, response) {
if (success)
{
this.dataStore.remove(rec);
}
else
{
var options = {
hideErrorStatus : true
};
Sonatype.utils.connectionError(response, 'Delete request could not be completed!', false, options);
}
},
scope : this,
method : 'DELETE',
url : rec.data.resourceURI
});
},

applyBookmark : function(bookmark) {
this.updatingBookmark = true;
if (this.groupStore.lastOptions == null)
Expand Down