1 package com.dotmarketing.factories; 2 3 import java.util.List ; 4 5 import com.dotmarketing.cms.factories.PublicCompanyFactory; 6 import com.dotmarketing.cms.factories.PublicUserFactory; 7 import com.dotmarketing.util.Config; 8 import com.dotmarketing.util.Logger; 9 import com.liferay.portal.ejb.GroupLocalManagerUtil; 10 import com.liferay.portal.ejb.GroupManagerUtil; 11 import com.liferay.portal.ejb.LayoutLocalManagerUtil; 12 import com.liferay.portal.ejb.RoleLocalManagerUtil; 13 import com.liferay.portal.model.Group; 14 import com.liferay.portal.model.Layout; 15 import com.liferay.portal.model.Role; 16 import com.liferay.portal.model.User; 17 18 22 public class LayoutFactory { 23 24 public static void createDefaultLayouts() { 25 Role role = RoleFactory.getRoleByName(Config.getStringProperty("CMS_USER_ROLE")); 26 Group group = GroupFactory.getGroupByName(Config.getStringProperty("CMS_USER_GROUP")); 27 28 29 _createWebsiteLayout(role, group, null); 30 _createContentLayout(role, group, null); 31 32 33 role = RoleFactory.getRoleByName(Config.getStringProperty("CMS_ADMINISTRATOR_ROLE")); 34 group = GroupFactory.getGroupByName(Config.getStringProperty("CMS_ADMIN_GROUP")); 35 36 37 User user = PublicUserFactory.getUserByUserId(PublicCompanyFactory.getDefaultCompanyId() + ".1"); 38 if (user.isNew()) { 39 user = null; 40 } 41 _createWebsiteLayout(role, group, user); 42 _createContentLayout(role, group, user); 43 _createCMSAdminLayout(role, group, user); 44 _createStructureLayout(role, group, user); 45 46 47 role = RoleFactory.getRoleByName(Config.getStringProperty("EVENTS_USER")); 48 group = GroupFactory.getGroupByName(Config.getStringProperty("EVENTS_USER_GROUP")); 49 _createEventsUserLayout(role, group, null); 50 51 52 role = RoleFactory.getRoleByName(Config.getStringProperty("EVENTS_ADMINISTRATOR")); 53 group = GroupFactory.getGroupByName(Config.getStringProperty("EVENTS_ADMIN_GROUP")); 54 _createEventsAdminLayout(role, group, user); 55 } 56 57 private static void _createWebsiteLayout(Role role, Group group, User user) { 58 String _layoutName = "Website"; 59 60 try { 61 boolean layoutExists = false; 62 63 List <Layout> layouts = GroupManagerUtil.getLayouts(group.getGroupId()); 64 for (Layout lay : layouts) { 65 if (_layoutName.equals(lay.getName())) { 66 layoutExists = true; 67 } 68 } 69 if (!layoutExists) { 70 String [] portlets = portlets = new String [] { "EXT_BROWSER" }; 71 Layout layout = new Layout(); 72 73 layout = LayoutLocalManagerUtil.addGroupLayout(group.getGroupId(), _layoutName, portlets); 74 LayoutLocalManagerUtil.updateLayout(layout.getPrimaryKey(), _layoutName, "w,", "", "", "EXT_BROWSER,", "", 75 "", "", ""); 76 77 } 78 79 RoleLocalManagerUtil.addGroup(role.getRoleId(), group); 80 81 if (user != null) { 82 GroupLocalManagerUtil.addUser(group.getGroupId(), user.getUserId()); 83 } 84 85 } catch (Exception e) { 86 Logger.debug(GroupFactory.class, "_createWebsiteLayout: Errors with layout: " + e); 87 } 88 89 } 90 91 private static void _createContentLayout(Role role, Group group, User user) { 92 String _layoutName = "Content"; 93 94 try { 95 boolean layoutExists = false; 96 97 List <Layout> layouts = GroupManagerUtil.getLayouts(group.getGroupId()); 98 for (Layout lay : layouts) { 99 if (_layoutName.equals(lay.getName())) { 100 layoutExists = true; 101 } 102 } 103 if (!layoutExists) { 104 String [] portlets = portlets = new String [] { "EXT_11" }; 105 Layout layout = new Layout(); 106 107 layout = LayoutLocalManagerUtil.addGroupLayout(group.getGroupId(), _layoutName, portlets); 108 LayoutLocalManagerUtil.updateLayout(layout.getPrimaryKey(), _layoutName, "w,", "", "", "EXT_11,", "", 109 "", "", ""); 110 111 } 112 113 RoleLocalManagerUtil.addGroup(role.getRoleId(), group); 114 if (user != null) { 115 GroupLocalManagerUtil.addUser(group.getGroupId(), user.getUserId()); 116 } 117 } catch (Exception e) { 118 Logger.debug(GroupFactory.class, "_createContentLayout: Errors with layout : " + _layoutName, e); 119 } 120 121 } 122 123 private static void _createCMSAdminLayout(Role role, Group group, User user) { 124 String _layoutName = "CMS Admin"; 125 126 try { 127 boolean layoutExists = false; 128 129 List <Layout> layouts = GroupManagerUtil.getLayouts(group.getGroupId()); 130 for (Layout lay : layouts) { 131 if (_layoutName.equals(lay.getName())) { 132 layoutExists = true; 133 } 134 } 135 if (!layoutExists) { 136 String [] portlets = portlets = new String [] { "9", "EXT_USERMANAGER", 137 "EXT_VIRTUAL_LINKS", "EXT_LANG", "EXT_4", "EXT_CMS_MAINTENANCE" }; 138 Layout layout = new Layout(); 139 layout = LayoutLocalManagerUtil.addGroupLayout(group.getGroupId(), _layoutName, portlets); 140 LayoutLocalManagerUtil.updateLayout(layout.getPrimaryKey(), _layoutName, "n1,w,", "9,EXT_LANG", "", 141 "EXT_USERMANAGER,EXT_VIRTUAL_LINKS,EXT_CMS_MAINTENANCE,", "", "", "", ""); 142 } 143 RoleLocalManagerUtil.addGroup(role.getRoleId(), group); 144 145 146 if (user != null) { 147 GroupLocalManagerUtil.addUser(group.getGroupId(), user.getUserId()); 148 } 149 } catch (Exception e) { 150 Logger.debug(GroupFactory.class, "_createCMSAdminLayout: Errors with layout : " + _layoutName, e); 151 } 152 153 } 154 155 private static void _createMarketingLayout(Role role, Group group, User user) { 156 String _layoutName = "Marketing"; 157 158 try { 159 boolean layoutExists = false; 160 161 List <Layout> layouts = GroupManagerUtil.getLayouts(group.getGroupId()); 162 for (Layout lay : layouts) { 163 if (_layoutName.equals(lay.getName())) { 164 layoutExists = true; 165 } 166 } 167 if (!layoutExists) { 168 String [] portlets = portlets = new String [] { "EXT_19", "EXT_16", "", 169 "EXT_WEBFORMS", "EXT_VIRTUAL_LINKS" }; 170 Layout layout = new Layout(); 171 layout = LayoutLocalManagerUtil.addGroupLayout(group.getGroupId(), _layoutName, portlets); 172 LayoutLocalManagerUtil.updateLayout(layout.getPrimaryKey(), _layoutName, "n1,w,", 173 "EXT_WEBFORMS", "", "EXT_19,EXT_16,EXT_VIRTUAL_LINKS,", "", 174 "", "", ""); 175 } 176 RoleLocalManagerUtil.addGroup(role.getRoleId(), group); 177 178 if (user != null) { 179 GroupLocalManagerUtil.addUser(group.getGroupId(), user.getUserId()); 180 } 181 } catch (Exception e) { 182 Logger.debug(GroupFactory.class, "_createWebsiteLayout: Errors with layout : " + _layoutName, e); 183 } 184 185 } 186 187 private static void _createEventsAdminLayout(Role role, Group group, User user) { 188 String _layoutName = "Events"; 189 190 try { 191 boolean layoutExists = false; 192 193 List <Layout> layouts = GroupManagerUtil.getLayouts(group.getGroupId()); 194 for (Layout lay : layouts) { 195 if (_layoutName.equals(lay.getName())) { 196 layoutExists = true; 197 } 198 } 199 if (!layoutExists) { 200 String [] portlets = portlets = new String [] { "EXT_FACILITY", "EXT_EVENTS","EXT_EVENTSAPPROVAL"}; 201 Layout layout = new Layout(); 202 layout = LayoutLocalManagerUtil.addGroupLayout(group.getGroupId(), _layoutName, portlets); 203 LayoutLocalManagerUtil.updateLayout(layout.getPrimaryKey(), _layoutName, "n1,w,", 204 "EXT_FACILITY,", "", "EXT_EVENTS,EXT_EVENTSAPPROVAL", "", 205 "", "", ""); 206 } 207 RoleLocalManagerUtil.addGroup(role.getRoleId(), group); 208 209 210 if (user != null) { 211 GroupLocalManagerUtil.addUser(group.getGroupId(), user.getUserId()); 212 } 213 } catch (Exception e) { 214 Logger.debug(GroupFactory.class, "_createWebsiteLayout: Errors with layout : " + _layoutName, e); 215 } 216 217 } 218 219 private static void _createEventsUserLayout(Role role, Group group, User user) { 220 String _layoutName = "Events"; 221 222 try { 223 boolean layoutExists = false; 224 225 List <Layout> layouts = GroupManagerUtil.getLayouts(group.getGroupId()); 226 for (Layout lay : layouts) { 227 if (_layoutName.equals(lay.getName())) { 228 layoutExists = true; 229 } 230 } 231 if (!layoutExists) { 232 String [] portlets = portlets = new String [] { "EXT_EVENTS"}; 233 Layout layout = new Layout(); 234 layout = LayoutLocalManagerUtil.addGroupLayout(group.getGroupId(), _layoutName, portlets); 235 LayoutLocalManagerUtil.updateLayout(layout.getPrimaryKey(), _layoutName, "w,", 236 "", "", "EXT_EVENTS,", "", 237 "", "", ""); 238 } 239 RoleLocalManagerUtil.addGroup(role.getRoleId(), group); 240 241 242 if (user != null) { 243 GroupLocalManagerUtil.addUser(group.getGroupId(), user.getUserId()); 244 } 245 } catch (Exception e) { 246 Logger.debug(GroupFactory.class, "_createWebsiteLayout: Errors with layout : " + _layoutName, e); 247 } 248 249 } 250 251 private static void _createStructureLayout(Role role, Group group, User user) { 252 String _layoutName = "Structures"; 253 254 try { 255 boolean layoutExists = false; 256 257 List <Layout> layouts = GroupManagerUtil.getLayouts(group.getGroupId()); 258 for (Layout lay : layouts) { 259 if (_layoutName.equals(lay.getName())) { 260 layoutExists = true; 261 } 262 } 263 if (!layoutExists) { 264 String [] portlets = portlets = new String [] { "EXT_6","EXT_VIRTUAL_LINKS", "EXT_LANG", "EXT_4", "EXT_STRUCTURE" }; 265 Layout layout = new Layout(); 266 layout = LayoutLocalManagerUtil.addGroupLayout(group.getGroupId(), _layoutName, portlets); 267 LayoutLocalManagerUtil.updateLayout(layout.getPrimaryKey(), _layoutName, "n1,w,", 268 "EXT_4,EXT_LANG,EXT_6", "", "EXT_STRUCTURE,EXT_VIRTUAL_LINKS,", "", 269 "", "", ""); 270 } 271 RoleLocalManagerUtil.addGroup(role.getRoleId(), group); 272 273 274 if (user != null) { 275 GroupLocalManagerUtil.addUser(group.getGroupId(), user.getUserId()); 276 } 277 } catch (Exception e) { 278 Logger.debug(GroupFactory.class, "_createWebsiteLayout: Errors with layout : " + _layoutName, e); 279 } 280 281 } 282 283 } | Popular Tags |