code cleanup

This commit is contained in:
Martin Stockhammer 2021-12-24 11:13:43 +01:00
parent c818808b7c
commit 78413e37c4
1 changed files with 18 additions and 19 deletions

View File

@ -92,9 +92,9 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
QUERY_HELPER.addNullsafeFieldComparator( "name", ManagedRepository::getName ); QUERY_HELPER.addNullsafeFieldComparator( "name", ManagedRepository::getName );
} }
private ManagedRepositoryAdmin managedRepositoryAdmin; private final ManagedRepositoryAdmin managedRepositoryAdmin;
private RepositoryRegistry repositoryRegistry; private final RepositoryRegistry repositoryRegistry;
private SecuritySystem securitySystem; private final SecuritySystem securitySystem;
public DefaultMavenManagedRepositoryService( SecuritySystem securitySystem, public DefaultMavenManagedRepositoryService( SecuritySystem securitySystem,
RepositoryRegistry repositoryRegistry, RepositoryRegistry repositoryRegistry,
@ -133,7 +133,7 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
final Comparator<ManagedRepository> comparator = QUERY_HELPER.getComparator( orderBy, order ); final Comparator<ManagedRepository> comparator = QUERY_HELPER.getComparator( orderBy, order );
int totalCount = Math.toIntExact( repos.stream( ).filter( queryFilter ).count( ) ); int totalCount = Math.toIntExact( repos.stream( ).filter( queryFilter ).count( ) );
return PagedResult.of( totalCount, offset, limit, repos.stream( ).filter( queryFilter ).sorted( comparator ) return PagedResult.of( totalCount, offset, limit, repos.stream( ).filter( queryFilter ).sorted( comparator )
.map(mr -> MavenManagedRepository.of(mr)).skip( offset ).limit( limit ).collect( Collectors.toList( ) ) ); .map( MavenManagedRepository::of ).skip( offset ).limit( limit ).collect( Collectors.toList( ) ) );
} }
catch (ArithmeticException e) { catch (ArithmeticException e) {
log.error( "Invalid number of repositories detected." ); log.error( "Invalid number of repositories detected." );
@ -157,13 +157,9 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
@Override @Override
public Response deleteManagedRepository( String repositoryId, Boolean deleteContent ) throws ArchivaRestServiceException public Response deleteManagedRepository( String repositoryId, Boolean deleteContent ) throws ArchivaRestServiceException
{ {
ManagedRepository repo = repositoryRegistry.getManagedRepository( repositoryId ); MavenManagedRepository repo = getManagedRepository( repositoryId );
if (repo==null) { if (repo != null)
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId ), 404 ); {
}
if (repo.getType()!=RepositoryType.MAVEN) {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_WRONG_TYPE, repositoryId, repo.getType().name() ), 404 );
}
try try
{ {
managedRepositoryAdmin.deleteManagedRepository( repositoryId, getAuditInformation( ), deleteContent ); managedRepositoryAdmin.deleteManagedRepository( repositoryId, getAuditInformation( ), deleteContent );
@ -173,6 +169,9 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
{ {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_DELETE_FAILED, e.getMessage( ) ) ); throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_DELETE_FAILED, e.getMessage( ) ) );
} }
} else {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId ), 404 );
}
} }
private org.apache.archiva.admin.model.beans.ManagedRepository convert(MavenManagedRepository repository) { private org.apache.archiva.admin.model.beans.ManagedRepository convert(MavenManagedRepository repository) {
@ -306,7 +305,7 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
} }
private void checkAuthority(final String userName, final String srcRepositoryId, final String dstRepositoryId ) throws ArchivaRestServiceException { private void checkAuthority(final String userName, final String srcRepositoryId, final String dstRepositoryId ) throws ArchivaRestServiceException {
User user = null; User user;
try try
{ {
user = securitySystem.getUserManager().findUser( userName ); user = securitySystem.getUserManager().findUser( userName );