1 package com.dotmarketing.factories; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import com.dotmarketing.cms.factories.PublicCompanyFactory; 7 import com.dotmarketing.util.Config; 8 import com.dotmarketing.util.Logger; 9 import com.dotmarketing.util.UtilMethods; 10 import com.liferay.portal.ejb.GroupLocalManagerUtil; 11 import com.liferay.portal.ejb.UserLocalManagerUtil; 12 import com.liferay.portal.model.Group; 13 import com.liferay.portal.model.User; 14 15 19 public class GroupFactory { 20 21 @SuppressWarnings ("unchecked") 22 public static List <Group> getAllGroupsForUser(String userId) { 23 List <Group> myGroups = new ArrayList <Group>(); 24 25 try { 27 myGroups = UserLocalManagerUtil.getGroups(userId); 28 } catch (Exception e) { 29 } 30 31 return myGroups; 32 33 } 34 35 @SuppressWarnings ("unchecked") 36 public static List <User> getAllUsersInGroup(String groupId) { 37 List users = new ArrayList (); 38 try { 39 users = GroupLocalManagerUtil.getUsers(groupId); 40 } catch (Exception e) { 41 Logger.debug(GroupFactory.class, "getAllUsersInGroup: Errors getting users for groupId: " + groupId); 42 } 43 return users; 44 } 45 46 public static Group getGroupByName(String groupName) { 47 Group group = new Group(); 48 try { 49 group = GroupLocalManagerUtil.getGroupByName(com.dotmarketing.cms.factories.PublicCompanyFactory 50 .getDefaultCompany().getCompanyId(), groupName); 51 } catch (Exception e) { 52 Logger.debug(GroupFactory.class, "getGroupByName: Errors getting group: " + groupName); 53 } 54 return group; 55 } 56 57 public static void createDefaultGroups() { 58 59 String [] groups = { "CMS_USER_GROUP", "CMS_ADMIN_GROUP", "MARKETING_ADMIN_GROUP", "EVENTS_ADMIN_GROUP", 60 "EVENTS_USER_GROUP" }; 61 62 for (int i = 0; i < groups.length; i++) { 63 String x = Config.getStringProperty(groups[i]); 64 if (UtilMethods.isSet(x)) { 65 Group test = getGroupByName(x); 66 if (test.getGroupId() == null) { 67 Logger.debug(GroupFactory.class, "Group" + x + " doesn't exist. Creating it!"); 68 try { 69 GroupLocalManagerUtil.addGroup(PublicCompanyFactory.getDefaultCompanyId(), x); 70 } catch (Exception e) { 71 Logger.debug(GroupFactory.class, "createDefaultGroups: Errors with group: " + x); 72 } 73 } 74 } 75 } 76 77 } 78 } | Popular Tags |