Reducing other compiler warnings and changing generics usage

This commit is contained in:
Martin Stockhammer 2018-04-08 20:13:07 +02:00
parent 70b9c04294
commit 5332c5926e
7 changed files with 35 additions and 48 deletions

View File

@ -48,6 +48,8 @@ public class VelocityMailGenerator
{
private Logger log = LoggerFactory.getLogger( VelocityMailGenerator.class );
public static final String DEFAULT_ENCODING = "UTF-8";
@Inject
@Named(value = "userConfiguration#default")
private UserConfiguration config;
@ -57,6 +59,15 @@ public class VelocityMailGenerator
@Named(value = "velocityEngine#redback")
private VelocityEngine velocityEngine;
private String encoding;
private String getEncoding() {
if (this.encoding==null) {
this.encoding = config.getString( "mail.encoding", DEFAULT_ENCODING );
}
return this.encoding;
}
public String generateMail( String templateName, AuthenticationKey authkey, String baseUrl )
{
VelocityContext context = createVelocityContext( authkey, baseUrl );
@ -68,7 +79,7 @@ public String generateMail( String templateName, AuthenticationKey authkey, Stri
try
{
velocityEngine.mergeTemplate( templateFile, context, writer );
velocityEngine.mergeTemplate( templateFile, getEncoding(), context, writer );
}
catch ( ResourceNotFoundException e )
{

View File

@ -19,7 +19,6 @@
*/
import org.apache.archiva.redback.common.ldap.MappingException;
import org.apache.archiva.redback.common.ldap.connection.DefaultLdapConnection;
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
import org.apache.archiva.redback.common.ldap.connection.LdapException;
@ -51,7 +50,7 @@
public class DefaultLdapGroupMappingService
implements LdapGroupMappingService
{
private Logger log = LoggerFactory.getLogger( getClass() );
private final Logger log = LoggerFactory.getLogger( getClass() );
@Inject
@Named(value = "ldapRoleMapper#default")
@ -78,12 +77,7 @@ public StringList getLdapGroups()
context = ldapConnection.getDirContext();
return new StringList( ldapRoleMapper.getAllGroups( context ) );
}
catch ( LdapException e )
{
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
catch ( MappingException e )
catch ( LdapException | MappingException e )
{
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
@ -101,7 +95,7 @@ public List<LdapGroupMapping> getLdapGroupMappings()
try
{
Map<String, Collection<String>> map = ldapRoleMapperConfiguration.getLdapGroupMappings();
List<LdapGroupMapping> ldapGroupMappings = new ArrayList<LdapGroupMapping>( map.size() );
List<LdapGroupMapping> ldapGroupMappings = new ArrayList<>( map.size( ) );
for ( Map.Entry<String, Collection<String>> entry : map.entrySet() )
{
LdapGroupMapping ldapGroupMapping = new LdapGroupMapping( entry.getKey(), entry.getValue() );
@ -123,7 +117,7 @@ public Boolean addLdapGroupMapping( LdapGroupMapping ldapGroupMapping )
try
{
ldapRoleMapperConfiguration.addLdapMapping( ldapGroupMapping.getGroup(),
new ArrayList( ldapGroupMapping.getRoleNames() ) );
new ArrayList<>( ldapGroupMapping.getRoleNames() ) );
}
catch ( MappingException e )
{
@ -156,7 +150,7 @@ public Boolean updateLdapGroupMapping( LdapGroupMappingUpdateRequest ldapGroupMa
for ( LdapGroupMapping ldapGroupMapping : ldapGroupMappingUpdateRequest.getLdapGroupMapping() )
{
ldapRoleMapperConfiguration.updateLdapMapping( ldapGroupMapping.getGroup(),
new ArrayList( ldapGroupMapping.getRoleNames() ) );
new ArrayList<>( ldapGroupMapping.getRoleNames() ) );
}
}
catch ( MappingException e )

View File

@ -100,21 +100,21 @@ public class DefaultUserService
*/
@Inject
@Named( value = "cache#userAssignments" )
private Cache userAssignmentsCache;
private Cache<String, ? extends UserAssignment> userAssignmentsCache;
/**
* cache used for user permissions
*/
@Inject
@Named( value = "cache#userPermissions" )
private Cache userPermissionsCache;
private Cache<String, ? extends Permission> userPermissionsCache;
/**
* Cache used for users
*/
@Inject
@Named( value = "cache#users" )
private Cache usersCache;
private Cache<String, ? extends User> usersCache;
@Inject
private Mailer mailer;
@ -284,7 +284,7 @@ public List<User> getUsers()
try
{
List<? extends org.apache.archiva.redback.users.User> users = userManager.getUsers();
List<User> simpleUsers = new ArrayList<User>( users.size() );
List<User> simpleUsers = new ArrayList<>( users.size( ) );
for ( org.apache.archiva.redback.users.User user : users )
{
@ -457,17 +457,11 @@ public User createGuestUser()
roleManager.assignRole( config.getString( UserConfigurationKeys.DEFAULT_GUEST ), user.getUsername() );
return getSimpleUser( user );
}
catch ( RoleManagerException e )
catch ( RoleManagerException | UserNotFoundException e )
{
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
catch ( UserNotFoundException e )
{
// olamy I wonder how this can happen :-)
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
@ -753,7 +747,7 @@ public Boolean validateUserFromKey( String key )
return Boolean.TRUE;
}
catch ( MustChangePasswordException e )
catch ( MustChangePasswordException | AccountLockedException | AuthenticationException e )
{
throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
}
@ -772,14 +766,6 @@ public Boolean validateUserFromKey( String key )
throw new RedbackServiceException( new ErrorMessage( "cannot.find.user", new String[]{ principal } ) );
}
catch ( AccountLockedException e )
{
throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
}
catch ( AuthenticationException e )
{
throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
}
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
@ -824,7 +810,7 @@ public Collection<Operation> getUserOperations( String userName )
throws RedbackServiceException
{
Collection<Permission> permissions = getUserPermissions( userName );
List<Operation> operations = new ArrayList<Operation>( permissions.size() );
List<Operation> operations = new ArrayList<>( permissions.size( ) );
for ( Permission permission : permissions )
{
if ( permission.getOperation() != null )
@ -845,7 +831,7 @@ public Collection<Permission> getUserPermissions( String userName )
Set<? extends org.apache.archiva.redback.rbac.Permission> permissions =
rbacManager.getAssignedPermissions( userName );
// FIXME return guest permissions !!
List<Permission> userPermissions = new ArrayList<Permission>( permissions.size() );
List<Permission> userPermissions = new ArrayList<>( permissions.size( ) );
for ( org.apache.archiva.redback.rbac.Permission p : permissions )
{
Permission permission = new Permission();
@ -870,11 +856,6 @@ public Collection<Permission> getUserPermissions( String userName )
}
return userPermissions;
}
catch ( RbacObjectNotFoundException e )
{
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
catch ( RbacManagerException e )
{
log.error( e.getMessage(), e );

View File

@ -34,7 +34,7 @@
*/
public class MockUserConfiguration implements UserConfiguration {
private Map<String, Object> values = new java.util.HashMap<String,Object>();
private Map<String, Object> values = new java.util.HashMap<>( );
@SuppressWarnings("SameParameterValue")
public void addValue(String key, String value) {
@ -92,6 +92,7 @@ public boolean getBoolean(String key, boolean defaultValue) {
}
}
@SuppressWarnings( "unchecked" )
@Override
public List<String> getList(String key) {
Object value = values.get(key);

View File

@ -55,7 +55,7 @@ public void setUp()
protected void tearDown()
throws Exception
{
CacheManager.getInstance().removalAll();
CacheManager.getInstance().removeAllCaches();
super.tearDown();
}
}

View File

@ -44,7 +44,7 @@ public class CachedUserManager
implements UserManager, UserManagerListener
{
private Logger log = LoggerFactory.getLogger( getClass() );
private final Logger log = LoggerFactory.getLogger( getClass() );
@Inject
@Named(value = "userManager#default")
@ -271,7 +271,7 @@ public boolean userExists( String userName )
@Override
public void userManagerInit( boolean freshDatabase )
{
if ( userImpl instanceof UserManager )
if ( userImpl != null )
{
( (UserManagerListener) this.userImpl ).userManagerInit( freshDatabase );
}
@ -282,7 +282,7 @@ public void userManagerInit( boolean freshDatabase )
@Override
public void userManagerUserAdded( User user )
{
if ( userImpl instanceof UserManager )
if ( userImpl != null )
{
( (UserManagerListener) this.userImpl ).userManagerUserAdded( user );
}
@ -296,7 +296,7 @@ public void userManagerUserAdded( User user )
@Override
public void userManagerUserRemoved( User user )
{
if ( userImpl instanceof UserManager )
if ( userImpl != null )
{
( (UserManagerListener) this.userImpl ).userManagerUserRemoved( user );
}
@ -310,7 +310,7 @@ public void userManagerUserRemoved( User user )
@Override
public void userManagerUserUpdated( User user )
{
if ( userImpl instanceof UserManager )
if ( userImpl != null )
{
( (UserManagerListener) this.userImpl ).userManagerUserUpdated( user );
}
@ -336,7 +336,7 @@ public Cache<String, User> getUsersCache()
return usersCache;
}
public void setUsersCache( Cache usersCache )
public void setUsersCache( Cache<String, User> usersCache )
{
this.usersCache = usersCache;
}

View File

@ -66,6 +66,6 @@ public void tearDown()
@AfterClass
public static void cleanCache()
{
CacheManager.getInstance().removalAll();
CacheManager.getInstance().removeAllCaches();
}
}