Reducing compiler warnings and modifying generic interfaces

This commit is contained in:
Martin Stockhammer 2018-04-08 19:29:27 +02:00
parent 87e8bba27c
commit 70b9c04294
11 changed files with 134 additions and 104 deletions

View File

@ -337,7 +337,7 @@ public class DataManagementTest
dataManagementTool.restoreUsersDatabase( manager, targetDirectory );
List<User> users = manager.getUsers();
List<? extends User> users = manager.getUsers();
assertEquals( 3, users.size() );
User user = users.get( 0 );
@ -371,7 +371,7 @@ public class DataManagementTest
private void assertEmpty( UserManager manager )
throws UserManagerException
{
List<User> users = manager.getUsers();
List<? extends User> users = manager.getUsers();
assertEquals( 0, users.size() );
}

View File

@ -283,7 +283,7 @@ public class DefaultUserService
{
try
{
List<org.apache.archiva.redback.users.User> users = userManager.getUsers();
List<? extends org.apache.archiva.redback.users.User> users = userManager.getUsers();
List<User> simpleUsers = new ArrayList<User>( users.size() );
for ( org.apache.archiva.redback.users.User user : users )

View File

@ -19,11 +19,6 @@ package org.apache.archiva.redback.keys.cached;
* under the License.
*/
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.archiva.redback.components.cache.Cache;
import org.apache.archiva.redback.keys.AbstractKeyManager;
import org.apache.archiva.redback.keys.AuthenticationKey;
@ -32,6 +27,10 @@ import org.apache.archiva.redback.keys.KeyManagerException;
import org.apache.archiva.redback.keys.KeyNotFoundException;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
/**
* CachedKeyManager
*
@ -94,7 +93,7 @@ public class CachedKeyManager
}
public AuthenticationKey findKey( String key )
throws KeyNotFoundException, KeyManagerException
throws KeyManagerException
{
try
{
@ -146,7 +145,7 @@ public class CachedKeyManager
return keysCache;
}
public void setKeysCache( Cache keysCache )
public void setKeysCache( Cache<String, AuthenticationKey> keysCache )
{
this.keysCache = keysCache;
}

View File

@ -100,10 +100,10 @@ public interface UserManager
* @return the List of {@link User} Objects.
* @throws UserManagerException
*/
List<User> getUsers()
List<? extends User> getUsers()
throws UserManagerException;
List<User> getUsers( boolean orderAscending )
List<? extends User> getUsers( boolean orderAscending )
throws UserManagerException;
/**
@ -156,13 +156,13 @@ public interface UserManager
User getGuestUser()
throws UserNotFoundException, UserManagerException;
List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
List<? extends User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
throws UserManagerException;
List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
List<? extends User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
throws UserManagerException;
List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
List<? extends User> findUsersByEmailKey( String emailKey, boolean orderAscending )
throws UserManagerException;
/**
@ -172,7 +172,7 @@ public interface UserManager
* @param query the query.
* @return a List of {@link User} objects.
*/
List<User> findUsersByQuery( UserQuery query )
List<? extends User> findUsersByQuery( UserQuery query )
throws UserManagerException;
/**

View File

@ -54,17 +54,20 @@ public class CachedUserManager
@Named(value = "cache#users")
private Cache<String, User> usersCache;
@Override
public boolean isReadOnly()
{
return userImpl.isReadOnly();
}
@Override
public User createGuestUser()
throws UserManagerException
{
return userImpl.createGuestUser();
}
@Override
public User addUser( User user )
throws UserManagerException
{
@ -75,11 +78,13 @@ public class CachedUserManager
return this.userImpl.addUser( user );
}
@Override
public void addUserManagerListener( UserManagerListener listener )
{
this.userImpl.addUserManagerListener( listener );
}
@Override
public void addUserUnchecked( User user )
throws UserManagerException
{
@ -90,6 +95,7 @@ public class CachedUserManager
this.userImpl.addUserUnchecked( user );
}
@Override
public User createUser( String username, String fullName, String emailAddress )
throws UserManagerException
{
@ -97,6 +103,7 @@ public class CachedUserManager
return this.userImpl.createUser( username, fullName, emailAddress );
}
@Override
public void deleteUser( String username )
throws UserNotFoundException, UserManagerException
{
@ -104,6 +111,7 @@ public class CachedUserManager
this.userImpl.deleteUser( username );
}
@Override
public void eraseDatabase()
{
try
@ -116,6 +124,7 @@ public class CachedUserManager
}
}
@Override
public User findUser( String username )
throws UserNotFoundException, UserManagerException
{
@ -145,6 +154,7 @@ public class CachedUserManager
return findUser( username );
}
@Override
public User getGuestUser()
throws UserNotFoundException, UserManagerException
{
@ -161,70 +171,81 @@ public class CachedUserManager
}
}
@Override
public UserQuery createUserQuery()
{
return userImpl.createUserQuery();
}
public List<User> findUsersByQuery( UserQuery query )
@Override
public List<? extends User> findUsersByQuery( UserQuery query )
throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByQuery(UserQuery)" );
return this.userImpl.findUsersByQuery( query );
}
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
@Override
public List<? extends User> findUsersByEmailKey( String emailKey, boolean orderAscending )
throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByEmailKey(String, boolean)" );
return this.userImpl.findUsersByEmailKey( emailKey, orderAscending );
}
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
@Override
public List<? extends User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByFullNameKey(String, boolean)" );
return this.userImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
}
public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
@Override
public List<? extends User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByUsernameKey(String, boolean)" );
return this.userImpl.findUsersByUsernameKey( usernameKey, orderAscending );
}
@Override
public String getId()
{
return "cached";
}
public List<User> getUsers()
@Override
public List<? extends User> getUsers()
throws UserManagerException
{
log.debug( "NOT CACHED - .getUsers()" );
return this.userImpl.getUsers();
}
public List<User> getUsers( boolean orderAscending )
@Override
public List<? extends User> getUsers( boolean orderAscending )
throws UserManagerException
{
log.debug( "NOT CACHED - .getUsers(boolean)" );
return this.userImpl.getUsers( orderAscending );
}
@Override
public void removeUserManagerListener( UserManagerListener listener )
{
this.userImpl.removeUserManagerListener( listener );
}
@Override
public User updateUser( User user )
throws UserNotFoundException, UserManagerException
{
return updateUser( user, false );
}
@Override
public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException, UserManagerException
{
@ -235,6 +256,7 @@ public class CachedUserManager
return this.userImpl.updateUser( user, passwordChangeRequired );
}
@Override
public boolean userExists( String userName )
throws UserManagerException
{
@ -246,6 +268,7 @@ public class CachedUserManager
return this.userImpl.userExists( userName );
}
@Override
public void userManagerInit( boolean freshDatabase )
{
if ( userImpl instanceof UserManager )
@ -256,6 +279,7 @@ public class CachedUserManager
usersCache.clear();
}
@Override
public void userManagerUserAdded( User user )
{
if ( userImpl instanceof UserManager )
@ -269,6 +293,7 @@ public class CachedUserManager
}
}
@Override
public void userManagerUserRemoved( User user )
{
if ( userImpl instanceof UserManager )
@ -282,6 +307,7 @@ public class CachedUserManager
}
}
@Override
public void userManagerUserUpdated( User user )
{
if ( userImpl instanceof UserManager )
@ -305,7 +331,7 @@ public class CachedUserManager
this.userImpl = userImpl;
}
public Cache getUsersCache()
public Cache<String, User> getUsersCache()
{
return usersCache;
}
@ -315,16 +341,19 @@ public class CachedUserManager
this.usersCache = usersCache;
}
@Override
public void initialize()
{
// no op configurable impl do the job
}
@Override
public boolean isFinalImplementation()
{
return false;
}
@Override
public String getDescriptionKey()
{
return "archiva.redback.usermanager.cached";

View File

@ -50,6 +50,7 @@ public class ConfigurableUserManager
private UserManager userManagerImpl;
@Override
@PostConstruct
public void initialize()
{
@ -66,40 +67,47 @@ public class ConfigurableUserManager
userManagerImpl = applicationContext.getBean( "userManager#" + userManagerRole, UserManager.class );
}
@Override
public User addUser( User user )
throws UserManagerException
{
return userManagerImpl.addUser( user );
}
@Override
public void addUserUnchecked( User user )
throws UserManagerException
{
userManagerImpl.addUserUnchecked( user );
}
@Override
public User createUser( String username, String fullName, String emailAddress )
throws UserManagerException
{
return userManagerImpl.createUser( username, fullName, emailAddress );
}
@Override
public UserQuery createUserQuery()
{
return userManagerImpl.createUserQuery();
}
@Override
public void deleteUser( String username )
throws UserNotFoundException, UserManagerException
{
userManagerImpl.deleteUser( username );
}
@Override
public void eraseDatabase()
{
userManagerImpl.eraseDatabase();
}
@Override
public User findUser( String username )
throws UserManagerException, UserNotFoundException
{
@ -120,64 +128,75 @@ public class ConfigurableUserManager
return userManagerImpl.getGuestUser();
}
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
@Override
public List<? extends User> findUsersByEmailKey( String emailKey, boolean orderAscending )
throws UserManagerException
{
return userManagerImpl.findUsersByEmailKey( emailKey, orderAscending );
}
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
@Override
public List<? extends User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
throws UserManagerException
{
return userManagerImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
}
public List<User> findUsersByQuery( UserQuery query )
@Override
public List<? extends User> findUsersByQuery( UserQuery query )
throws UserManagerException
{
return userManagerImpl.findUsersByQuery( query );
}
public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
@Override
public List<? extends User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
throws UserManagerException
{
return userManagerImpl.findUsersByUsernameKey( usernameKey, orderAscending );
}
@Override
public String getId()
{
return "configurable";
}
public List<User> getUsers()
@Override
public List<? extends User> getUsers()
throws UserManagerException
{
return userManagerImpl.getUsers();
}
public List<User> getUsers( boolean orderAscending )
@Override
public List<? extends User> getUsers( boolean orderAscending )
throws UserManagerException
{
return userManagerImpl.getUsers( orderAscending );
}
@Override
public boolean isReadOnly()
{
return userManagerImpl.isReadOnly();
}
@Override
public User updateUser( User user )
throws UserNotFoundException, UserManagerException
{
return updateUser( user, false );
}
@Override
public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException, UserManagerException
{
return userManagerImpl.updateUser( user, passwordChangeRequired );
}
@Override
public boolean userExists( String userName )
throws UserManagerException
{
@ -189,6 +208,7 @@ public class ConfigurableUserManager
this.userManagerImpl = userManagerImpl;
}
@Override
public String getDescriptionKey()
{
return "archiva.redback.usermanager.configurable";

View File

@ -20,17 +20,24 @@ package org.apache.archiva.redback.users.jpa;
*/
import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.*;
import org.apache.archiva.redback.users.AbstractUserManager;
import org.apache.archiva.redback.users.Messages;
import org.apache.archiva.redback.users.PermanentUserException;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.users.UserQuery;
import org.apache.archiva.redback.users.jpa.model.JpaUser;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@ -91,17 +98,17 @@ public class JpaUserManager extends AbstractUserManager {
}
@Override
public List<User> getUsers() throws UserManagerException {
public List<? extends User> getUsers() throws UserManagerException {
final EntityManager em = getEm();
Query q= em.createQuery("SELECT x from JpaUser x");
TypedQuery<JpaUser> q= em.createQuery("SELECT x from JpaUser x", JpaUser.class);
return q.getResultList();
}
@Override
public List<User> getUsers(boolean orderAscending) throws UserManagerException {
public List<? extends User> getUsers(boolean orderAscending) throws UserManagerException {
final EntityManager em = getEm();
final String orderFlag = orderAscending ? "ASC" : "DESC";
Query q = em.createQuery("SELECT u FROM JpaUser u ORDER BY u.username "+orderFlag);
TypedQuery<JpaUser> q = em.createQuery("SELECT u FROM JpaUser u ORDER BY u.username "+orderFlag, JpaUser.class);
return q.getResultList();
}
@ -140,18 +147,18 @@ public class JpaUserManager extends AbstractUserManager {
if (user.getLastPasswordChange()==null) {
user.setLastPasswordChange(new Date());
}
em.persist((JpaUser)user);
em.persist( user );
return user;
}
@Transactional
@Override
public User updateUser(User user) throws UserNotFoundException, UserManagerException {
public User updateUser(User user) throws UserManagerException {
return updateUser(user, false);
}
@Override
public User findUser(String username) throws UserNotFoundException, UserManagerException {
public User findUser(String username) throws UserManagerException {
if (username==null) {
throw new UserNotFoundException("Username was <null>");
}
@ -168,30 +175,30 @@ public class JpaUserManager extends AbstractUserManager {
}
@Override
public User findUser(String username, boolean useCache) throws UserNotFoundException, UserManagerException {
public User findUser(String username, boolean useCache) throws UserManagerException {
return findUser(username);
}
@Override
public List<User> findUsersByUsernameKey(String usernameKey, boolean orderAscending) throws UserManagerException {
public List<? extends User> findUsersByUsernameKey(String usernameKey, boolean orderAscending) throws UserManagerException {
return findUsers("username",usernameKey,"username",orderAscending);
}
@Override
public List<User> findUsersByFullNameKey(String fullNameKey, boolean orderAscending) throws UserManagerException {
public List<? extends User> findUsersByFullNameKey(String fullNameKey, boolean orderAscending) throws UserManagerException {
return findUsers("fullName",fullNameKey,"username",orderAscending);
}
@Override
public List<User> findUsersByEmailKey(String emailKey, boolean orderAscending) throws UserManagerException {
public List<? extends User> findUsersByEmailKey(String emailKey, boolean orderAscending) throws UserManagerException {
return findUsers("email",emailKey,"username", orderAscending);
}
@Override
public List<User> findUsersByQuery(final UserQuery queryParam) throws UserManagerException {
public List<? extends User> findUsersByQuery(final UserQuery queryParam) throws UserManagerException {
final EntityManager em = getEm();
final JpaUserQuery query = (JpaUserQuery)queryParam;
String orderByAttribute = "";
String orderByAttribute;
if (UserQuery.ORDER_BY_EMAIL.equals(query.getOrderBy())) {
orderByAttribute="email";
} else if (UserQuery.ORDER_BY_FULLNAME.equals(query.getOrderBy())) {
@ -240,7 +247,7 @@ public class JpaUserManager extends AbstractUserManager {
return q.getResultList();
}
private List<User> findUsers(final String attribute, final String pattern,
private List<? extends User> findUsers(final String attribute, final String pattern,
final String orderAttribute, final boolean orderAscending) {
final EntityManager em = getEm();
StringBuilder sb = new StringBuilder("SELECT u FROM JpaUser u WHERE LOWER(u.");
@ -262,7 +269,7 @@ public class JpaUserManager extends AbstractUserManager {
@Transactional
@Override
public void deleteUser(String username) throws UserNotFoundException, UserManagerException {
public void deleteUser(String username) throws UserManagerException {
final EntityManager em = getEm();
User u = findUser(username);
if (u.isPermanent()) {
@ -293,7 +300,7 @@ public class JpaUserManager extends AbstractUserManager {
log.info("USER FOUND: "+u.getUsername());
}
log.info("NEW USER "+user.getUsername());
em.persist((JpaUser)user);
em.persist( user );
}
@ -314,7 +321,7 @@ public class JpaUserManager extends AbstractUserManager {
@Transactional
@Override
public User updateUser(User user, boolean passwordChangeRequired) throws UserNotFoundException, UserManagerException {
public User updateUser(User user, boolean passwordChangeRequired) throws UserManagerException {
if ( !( user instanceof JpaUser ) )
{
throw new UserManagerException( "Unable to update user. User object " + user.getClass().getName() +

View File

@ -19,34 +19,16 @@ package org.apache.archiva.redback.users.jpa;
* under the License.
*/
import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.users.jpa.model.JpaUser;
import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
*
@ -63,12 +45,6 @@ public class JpaUserManagerTest extends AbstractUserManagerTestCase {
@Named("userManager#jpa")
UserManager jpaUserManager;
@Inject
EntityManagerFactory entityManagerFactory;
@Inject
private UserSecurityPolicy securityPolicy;
@Before
@Override

View File

@ -19,14 +19,21 @@ package org.apache.archiva.redback.users.ldap.ctl;
* under the License.
*/
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.archiva.redback.common.ldap.MappingException;
import org.apache.archiva.redback.common.ldap.user.LdapUser;
import org.apache.archiva.redback.common.ldap.user.LdapUserMapper;
import org.apache.archiva.redback.common.ldap.user.UserMapper;
import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordEncoder;
import org.apache.archiva.redback.policy.encoders.SHA1PasswordEncoder;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.users.ldap.LdapUserQuery;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
@ -40,22 +47,14 @@ import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import org.apache.archiva.redback.common.ldap.user.LdapUser;
import org.apache.archiva.redback.common.ldap.user.LdapUserMapper;
import org.apache.archiva.redback.common.ldap.user.UserMapper;
import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.policy.PasswordEncoder;
import org.apache.archiva.redback.policy.encoders.SHA1PasswordEncoder;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.common.ldap.MappingException;
import org.apache.archiva.redback.users.ldap.LdapUserQuery;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author jesse
@ -420,10 +419,10 @@ public class DefaultLdapController
if ( uniqueMemberAttr != null )
{
NamingEnumeration<String> allMembersEnum = (NamingEnumeration<String>) uniqueMemberAttr.getAll();
NamingEnumeration<?> allMembersEnum = uniqueMemberAttr.getAll();
while ( allMembersEnum.hasMore() )
{
String userName = allMembersEnum.next();
String userName = allMembersEnum.next().toString();
// uid=blabla we only want bla bla
userName = StringUtils.substringAfter( userName, "=" );
userName = StringUtils.substringBefore( userName, "," );

View File

@ -200,7 +200,7 @@ public class LdapUserManagerTest
//assertNotNull( ldapCacheService.getUser( "jesse" ) );
List<User> users = userManager.getUsers();
List<? extends User> users = userManager.getUsers();
assertNotNull( users );
@ -244,7 +244,7 @@ public class LdapUserManagerTest
assertTrue( userManager.userExists( "user10" ) );
List<User> users = userManager.getUsers();
List<? extends User> users = userManager.getUsers();
assertNotNull( users );

View File

@ -460,7 +460,7 @@ public class AbstractUserManagerTestCase
// Query with default ordering ascending
query = um.createUserQuery();
query.setOrderBy( UserQuery.ORDER_BY_EMAIL );
List<User> users = um.findUsersByQuery( query );
List<? extends User> users = um.findUsersByQuery( query );
assertEquals( 3, users.size() );
assertEquals( "admin@somedomain.com", ( (User) users.get( 0 ) ).getEmail() );