View Javadoc
1 package org.smartcomps.twister.util.user.priv; 2 3 import org.smartcomps.twister.common.persistence.CreationException; 4 import org.smartcomps.twister.common.persistence.DBSessionException; 5 import org.smartcomps.twister.common.persistence.FinderException; 6 import org.smartcomps.twister.common.persistence.PersistentDataAccess; 7 import org.smartcomps.twister.util.user.Role; 8 import org.smartcomps.twister.util.user.TwisterUser; 9 import org.smartcomps.twister.util.user.User; 10 import org.smartcomps.twister.util.user.exception.TwisterUserException; 11 import org.smartcomps.twister.util.user.priv.dao.UserDAO; 12 13 import java.util.*; 14 15 public class TwisterUserImpl implements TwisterUser { 16 17 public User createUser(User user) throws CreationException { 18 if (user.getRoles() == null || user.getRoles().size() == 0) { 19 throw new CreationException("User to create must have at least one role !"); 20 } 21 try { 22 UserImpl userImpl = UserConverter.userVO2userPO(user); 23 PersistentDataAccess.create(userImpl); 24 for (Iterator rolesIter = userImpl.getRoles().iterator(); rolesIter.hasNext();) { 25 RoleImpl roleImpl = (RoleImpl) rolesIter.next(); 26 PersistentDataAccess.create(roleImpl); 27 } 28 return user; 29 } catch (DBSessionException e) { 30 throw new CreationException(e); 31 } catch (FinderException e) { 32 throw new CreationException(e); 33 } 34 } 35 36 public Collection findAllUsers() throws TwisterUserException { 37 try { 38 return UserConverter.userPOs2userVOs(UserDAO.findAllUsers()); 39 } catch (DBSessionException e) { 40 throw new TwisterUserException(e); 41 } 42 } 43 44 public Collection findAllRoles() throws TwisterUserException { 45 // TODO implement me with a select DISTINCT 46 throw new UnsupportedOperationException("Implement me"); 47 } 48 49 public Collection findUsersInRole(String rolename) throws TwisterUserException { 50 Collection res; 51 try { 52 // RoleImpl roleImpl = UserDAO.findRoleByRolename(rolename); 53 // res = UserConverter.userPOs2userVOs(roleImpl.getUsersInRole()); 54 res = UserConverter.userPOs2userVOs(UserDAO.findUsersInRole(rolename)); 55 } catch (FinderException e) { 56 res = new HashSet(); 57 } catch (DBSessionException e) { 58 throw new TwisterUserException(e); 59 } 60 return res; 61 } 62 63 }

This page was automatically generated by Maven