1 16 package com.blandware.atleap.service.core.impl; 17 18 import com.blandware.atleap.common.util.PartialCollection; 19 import com.blandware.atleap.common.util.QueryInfo; 20 import com.blandware.atleap.model.core.Role; 21 import com.blandware.atleap.persistence.core.RoleDAO; 22 import com.blandware.atleap.service.core.RoleManager; 23 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 24 import com.blandware.atleap.service.exception.BeanNotFoundException; 25 26 35 public class RoleManagerImpl extends BaseManagerImpl implements RoleManager { 36 37 40 protected RoleDAO roleDAO; 41 42 47 public void setRoleDAO(RoleDAO dao) { 48 this.roleDAO = dao; 49 } 50 51 53 56 public void createRole(Role role) throws BeanAlreadyExistsException { 57 if ( log.isDebugEnabled() ) { 58 log.debug("Creating new Role [roleName=" + role.getName() + "]..."); 59 } 60 61 Role tmp = roleDAO.retrieveRole(role.getName()); 63 if ( tmp != null ) { 64 String errorMessage = "Role with the name '" + role.getName() + "' already exists"; 66 if ( log.isErrorEnabled() ) { 67 log.error(errorMessage); 68 } 69 throw new BeanAlreadyExistsException(errorMessage); 70 } 71 tmp = roleDAO.findRoleByTitle(role.getTitle()); 72 if ( tmp != null ) { 73 String errorMessage = "Role with the title '" + role.getTitle() + "' already exists"; 75 if ( log.isErrorEnabled() ) { 76 log.error(errorMessage); 77 } 78 throw new BeanAlreadyExistsException(errorMessage); 79 } 80 roleDAO.createRole(role); 81 82 if ( log.isDebugEnabled() ) { 83 log.debug("New role has been created succesfully"); 84 } 85 } 86 87 90 public Role retrieveRole(String roleName) { 91 Role role = null; 92 role = roleDAO.retrieveRole(roleName); 93 return role; 94 } 95 96 99 public void updateRole(Role role) throws BeanAlreadyExistsException { 100 101 roleDAO.removeFromCache(role); 103 if ( log.isDebugEnabled() ) { 104 log.debug("Updating Role [roleName=" + role.getName() + "]..."); 105 } 106 107 if ( roleDAO.hasDuplicates(role) ) { 108 throw new BeanAlreadyExistsException("Role with the same title already exists"); 109 } 110 111 roleDAO.updateRole(role); 112 113 if ( log.isDebugEnabled() ) { 114 log.debug("Role has been updated succesfully"); 115 } 116 } 117 118 121 public void deleteRole(String roleName) throws BeanNotFoundException { 122 Role role = roleDAO.retrieveRole(roleName); 123 if ( role == null ) { 124 String errorMessage = "No role with ID=" + role + "could be found"; 125 throw new BeanNotFoundException(errorMessage); 126 } 127 roleDAO.deleteRole(role); 128 } 129 130 132 135 public PartialCollection listRoles(QueryInfo queryInfo) { 136 return roleDAO.listRoles(queryInfo); 137 } 138 139 } | Popular Tags |