/** @author Tuomas Katva */ public class UserServiceImpl implements UserService { UserLocalService usrService = UserLocalServiceUtil.getService(); ServiceContext serviceContext = new ServiceContext(); RoleLocalService roleService = RoleLocalServiceUtil.getService(); OrganizationLocalService orgService = OrganizationLocalServiceUtil.getService(); public TtUser getLoggedInUser() { // TODO if this does not work this must be done in Vaadin application where // portlet request must be passed to PortalUtil class Long userId = serviceContext.getUserId(); TtUser usr = new TtUser(); usr.setUserId(userId); try { usr.setUserName(usrService.getUser(userId).getLogin()); } catch (Exception exp) { } throw new UnsupportedOperationException("Not supported yet."); } public List<TtRole> getAllApplicationRoles() { throw new UnsupportedOperationException("Not supported yet."); } public List<TtRole> getUserRoles(TtUser user) { List<TtRole> roles = new ArrayList<TtRole>(); try { List<com.liferay.portal.model.Role> portalRoles = roleService.getUserRoles(user.getUserId()); for (Role portalRole : portalRoles) { roles.add(UserServiceConversionHelper.convertPortalRoleToTtRole(portalRole)); } } catch (SystemException ex) { Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } return roles; } public boolean isUserInRole(TtRole role, TtUser user) { try { return roleService.hasUserRole(user.getUserId(), role.getRoleId()); } catch (SystemException ex) { Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex); return false; } } public List<TtUser> getUsersForRole(String roleName, long userId) { List<TtUser> roleUsrs = new ArrayList<TtUser>(); try { List<Organization> usrOrgs = orgService.getUserOrganizations(userId); for (Organization org : usrOrgs) { Role role = roleService.getRole(org.getCompanyId(), roleName); if (role != null) { List<User> usrs = usrService.getRoleUsers(role.getRoleId()); for (User usr : usrs) { roleUsrs.add(UserServiceConversionHelper.convertPortalUserToTtUser(usr)); } } } } catch (PortalException ex) { Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (SystemException ex) { Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } return roleUsrs; } }