| 1 package com.dotmarketing.cms.factories; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import com.dotmarketing.util.Config; 7 import com.dotmarketing.util.Logger; 8 import com.liferay.portal.NoSuchRoleException; 9 import com.liferay.portal.NoSuchUserException; 10 import com.liferay.portal.SystemException; 11 import com.liferay.portal.ejb.RoleLocalManagerUtil; 12 import com.liferay.portal.ejb.RoleUtil; 13 import com.liferay.portal.model.Role; 14 import com.liferay.portal.model.User; 15 16 21 public class PublicRoleFactory extends RoleUtil { 22 23 private static Role _cmsAdminRole = null; 24 25 public static void addRoleToUser(String roleId, User user) { 26 try { 27 addUser(roleId, user); 28 } catch (NoSuchRoleException e) { 29 e.printStackTrace(); 30 } catch (NoSuchUserException e) { 31 e.printStackTrace(); 32 } catch (SystemException e) { 33 e.printStackTrace(); 34 } 35 } 36 37 public static Role findRoleByName(String name) { 38 try { 39 return findByC_N(com.dotmarketing.cms.factories.PublicCompanyFactory.getDefaultCompany().getCompanyId(), 40 name); 41 } catch (Exception ex) { 42 Logger.error(PublicRoleFactory.class, ex.getMessage(), ex); 43 return new Role(); 44 } 45 } 46 47 public static Role getCMSAdminRole() throws Exception { 48 if (_cmsAdminRole == null) { 49 50 51 _cmsAdminRole = RoleLocalManagerUtil.getRoleByName(PublicCompanyFactory.getDefaultCompanyId(), Config 52 .getStringProperty("CMS_ADMINISTRATOR_ROLE")); 53 54 } 55 56 return _cmsAdminRole; 57 } 58 59 public static boolean containsRole (Role[] roles, Role role) { 60 for (Role r : roles) { 61 if (r.getRoleId().equals(role.getRoleId())) 62 return true; 63 } 64 return false; 65 } 66 67 public static List <Role> getAllNoSystemRoles() { 68 try { 69 List <Role> listToRet = new ArrayList <Role>(); 70 List <Role> roles = findByCompanyId(PublicCompanyFactory.getDefaultCompanyId()); 71 for (Role role : roles) { 72 if (!com.liferay.portal.util.PortalUtil.isSystemRole(role.getName())) 73 listToRet.add(role); 74 } 75 return listToRet; 76 } catch (Exception ex) { 77 Logger.error(PublicRoleFactory.class, ex.getMessage(), ex); 78 return new ArrayList (); 79 } 80 } 81 82 public static List <Role> getAllRoles() { 83 try { 84 return findByCompanyId(PublicCompanyFactory.getDefaultCompanyId()); 85 } catch (Exception ex) { 86 Logger.error(PublicRoleFactory.class, ex.getMessage(), ex); 87 return new ArrayList (); 88 } 89 } 90 91 92 } 93 | Popular Tags |