--- /dev/null
+/**\r
+ * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.\r
+ *\r
+ * This library is free software; you can redistribute it and/or modify it under\r
+ * the terms of the GNU Lesser General Public License as published by the Free\r
+ * Software Foundation; either version 2.1 of the License, or (at your option)\r
+ * any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\r
+ * details.\r
+ */\r
+\r
+package com.liferay.portal.service.impl;\r
+\r
+import com.liferay.portal.DuplicateGroupException;\r
+import com.liferay.portal.GroupFriendlyURLException;\r
+import com.liferay.portal.GroupNameException;\r
+import com.liferay.portal.NoSuchGroupException;\r
+import com.liferay.portal.NoSuchLayoutSetException;\r
+import com.liferay.portal.NoSuchUserException;\r
+import com.liferay.portal.RequiredGroupException;\r
+import com.liferay.portal.kernel.cache.ThreadLocalCachable;\r
+import com.liferay.portal.kernel.dao.orm.QueryUtil;\r
+import com.liferay.portal.kernel.exception.PortalException;\r
+import com.liferay.portal.kernel.exception.SystemException;\r
+import com.liferay.portal.kernel.language.LanguageUtil;\r
+import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;\r
+import com.liferay.portal.kernel.log.Log;\r
+import com.liferay.portal.kernel.log.LogFactoryUtil;\r
+import com.liferay.portal.kernel.messaging.DestinationNames;\r
+import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;\r
+import com.liferay.portal.kernel.scheduler.StorageType;\r
+import com.liferay.portal.kernel.spring.aop.Skip;\r
+import com.liferay.portal.kernel.staging.StagingUtil;\r
+import com.liferay.portal.kernel.transaction.Propagation;\r
+import com.liferay.portal.kernel.transaction.Transactional;\r
+import com.liferay.portal.kernel.util.FileUtil;\r
+import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;\r
+import com.liferay.portal.kernel.util.GetterUtil;\r
+import com.liferay.portal.kernel.util.OrderByComparator;\r
+import com.liferay.portal.kernel.util.ParamUtil;\r
+import com.liferay.portal.kernel.util.PropsKeys;\r
+import com.liferay.portal.kernel.util.StringPool;\r
+import com.liferay.portal.kernel.util.StringUtil;\r
+import com.liferay.portal.kernel.util.UniqueList;\r
+import com.liferay.portal.kernel.util.Validator;\r
+import com.liferay.portal.model.Account;\r
+import com.liferay.portal.model.Company;\r
+import com.liferay.portal.model.Group;\r
+import com.liferay.portal.model.GroupConstants;\r
+import com.liferay.portal.model.Layout;\r
+import com.liferay.portal.model.LayoutConstants;\r
+import com.liferay.portal.model.LayoutPrototype;\r
+import com.liferay.portal.model.LayoutSet;\r
+import com.liferay.portal.model.LayoutSetPrototype;\r
+import com.liferay.portal.model.LayoutTypePortlet;\r
+import com.liferay.portal.model.Organization;\r
+import com.liferay.portal.model.Portlet;\r
+import com.liferay.portal.model.Resource;\r
+import com.liferay.portal.model.ResourceConstants;\r
+import com.liferay.portal.model.ResourcePermission;\r
+import com.liferay.portal.model.Role;\r
+import com.liferay.portal.model.RoleConstants;\r
+import com.liferay.portal.model.User;\r
+import com.liferay.portal.model.UserGroup;\r
+import com.liferay.portal.model.UserPersonalSite;\r
+import com.liferay.portal.model.impl.LayoutImpl;\r
+import com.liferay.portal.security.permission.ActionKeys;\r
+import com.liferay.portal.security.permission.PermissionCacheUtil;\r
+import com.liferay.portal.security.permission.ResourceActionsUtil;\r
+import com.liferay.portal.service.ServiceContext;\r
+import com.liferay.portal.service.base.GroupLocalServiceBaseImpl;\r
+import com.liferay.portal.theme.ThemeLoader;\r
+import com.liferay.portal.theme.ThemeLoaderFactory;\r
+import com.liferay.portal.util.PortalUtil;\r
+import com.liferay.portal.util.PortletCategoryKeys;\r
+import com.liferay.portal.util.PortletKeys;\r
+import com.liferay.portal.util.PropsUtil;\r
+import com.liferay.portal.util.PropsValues;\r
+import com.liferay.portal.util.comparator.GroupNameComparator;\r
+import com.liferay.portlet.blogs.model.BlogsEntry;\r
+import com.liferay.portlet.journal.model.JournalArticle;\r
+import com.liferay.portlet.messageboards.model.MBCategoryConstants;\r
+\r
+import java.io.File;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+import java.util.List;\r
+import java.util.Locale;\r
+import java.util.Map;\r
+\r
+/**\r
+ * The group local service is responsible for accessing, creating, modifying and\r
+ * deleting groups.\r
+ *\r
+ * <p>\r
+ * Groups are mostly used in Liferay as a resource container for permissioning\r
+ * and content scoping purposes as described in {@link\r
+ * com.liferay.portal.model.impl.GroupImpl}.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Groups are also the entity to which LayoutSets are generally associated.\r
+ * Since LayoutSets are the parent entities of Layouts (i.e. pages), no entity\r
+ * can have associated pages without also having an associated Group. This\r
+ * relationship can be depicted as ... Layout -> LayoutSet -> Group[type] [->\r
+ * Entity]. Note, the Entity part is optional.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Group has a "type" definition that is typically identified by two fields of\r
+ * the entity - <code>String className</code>, and <code>int type </code>.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * The <code>className</code> field helps create the group's association with\r
+ * other entities (e.g. Organization, User, Company, UserGroup, ... etc.). The\r
+ * value of <code>className</code> is the full name of the entity's class and\r
+ * the primary key of the associated entity instance. A site has\r
+ * <code>className="Group"</code> and has no associated entity.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * The <code>type</code> field helps distinguish between a group used strictly\r
+ * for scoping and a group that also has pages (in which case the type is\r
+ * <code>SITE</code>). For a list of types, see {@link\r
+ * com.liferay.portal.model.GroupConstants}.\r
+ * </p>\r
+ *\r
+ * <p>\r
+ * Here is a listing of how Group is related to some portal entities ...\r
+ * </p>\r
+ *\r
+ * <ul>\r
+ * <li>\r
+ * Site is a Group with <code>className="Group"</code>\r
+ * </li>\r
+ * <li>\r
+ * Company has 1 Group (this is the global scope, but never has pages)\r
+ * </li>\r
+ * <li>\r
+ * User has 1 Group (pages are optional based on the behavior configuration for\r
+ * personal pages)\r
+ * </li>\r
+ * <li>\r
+ * Layout Template (<code>LayoutPrototype</code>) has 1 Group which uses only 1\r
+ * of it's 2 LayoutSets to store a single page which can later be used to\r
+ * derive a single page in any Site\r
+ * </li>\r
+ * <li>\r
+ * Site Template (<code>LayoutSetPrototype</code>) has 1 Group which uses only\r
+ * 1 of it's 2 LayoutSets to store many pages which can later be used to derive\r
+ * entire Sites or pulled into an existing Site\r
+ * </li>\r
+ * <li>\r
+ * Organization has 1 Group, but can also be associated to a Site at any point\r
+ * in it's life cycle in order to support having pages\r
+ * </li>\r
+ * <li>\r
+ * UserGroup has 1 Group that can have pages in both of the group's LayoutSets\r
+ * which are later inherited by users assigned to the UserGroup\r
+ * </li>\r
+ * </ul>\r
+ *\r
+ * @author Brian Wing Shun Chan\r
+ * @author Alexander Chow\r
+ * @author Bruno Farache\r
+ * @author Wesley Gong\r
+ * ---------------------------------------------------------------------------------\r
+19/12/2013 Putchhat SRUN M - AAPEESC - Ajout du critere tag dans la recherche\r
+\r
+ */\r
+public class GroupLocalServiceImpl extends GroupLocalServiceBaseImpl {\r
+\r
+ public static final String ORGANIZATION_NAME_SUFFIX = " LFR_ORGANIZATION";\r
+\r
+ /**\r
+ * Constructs a group local service.\r
+ */\r
+ public GroupLocalServiceImpl() {\r
+ initImportLARFile();\r
+ }\r
+\r
+ /**\r
+ * Adds a group.\r
+ *\r
+ * @param userId the primary key of the group's creator/owner\r
+ * @param className the entity's class name\r
+ * @param classPK the primary key of the entity's instance\r
+ * @param liveGroupId the primary key of the live group\r
+ * @param name the entity's name\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param type the group's type. For more information see {@link\r
+ * com.liferay.portal.model.GroupConstants}\r
+ * @param friendlyURL the group's friendlyURL (optionally\r
+ * <code>null</code>)\r
+ * @param site whether the group is to be associated with a main site\r
+ * @param active whether the group is active\r
+ * @param serviceContext the service context to be applied (optionally\r
+ * <code>null</code>). Can set asset category IDs and asset tag\r
+ * names for the group, and whether the group is for staging.\r
+ * @return the group\r
+ * @throws PortalException if a creator could not be found, if the group's\r
+ * information was invalid, if a layout could not be found, or if a\r
+ * valid friendly URL could not be created for the group\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group addGroup(\r
+ long userId, String className, long classPK, long liveGroupId,\r
+ String name, String description, int type, String friendlyURL,\r
+ boolean site, boolean active, ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ // Group\r
+\r
+ User user = userPersistence.findByPrimaryKey(userId);\r
+ className = GetterUtil.getString(className);\r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+ String friendlyName = name;\r
+\r
+ long groupId = 0;\r
+\r
+ while (true) {\r
+ groupId = counterLocalService.increment();\r
+\r
+ User screenNameUser = userPersistence.fetchByC_SN(\r
+ user.getCompanyId(), String.valueOf(groupId));\r
+\r
+ if (screenNameUser == null) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ boolean staging = isStaging(serviceContext);\r
+\r
+ long groupClassNameId = PortalUtil.getClassNameId(Group.class);\r
+\r
+ if ((classNameId <= 0) || className.equals(Group.class.getName())) {\r
+ className = Group.class.getName();\r
+ classNameId = groupClassNameId;\r
+ classPK = groupId;\r
+ }\r
+ else if (className.equals(Organization.class.getName())) {\r
+ name = getOrgGroupName(name);\r
+ }\r
+ else if (!GroupConstants.USER_PERSONAL_SITE.equals(name)) {\r
+ name = String.valueOf(classPK);\r
+ }\r
+\r
+ if (className.equals(Organization.class.getName()) && staging) {\r
+ classPK = liveGroupId;\r
+ }\r
+\r
+ long parentGroupId = GroupConstants.DEFAULT_PARENT_GROUP_ID;\r
+\r
+ if (className.equals(Layout.class.getName())) {\r
+ Layout layout = layoutLocalService.getLayout(classPK);\r
+\r
+ parentGroupId = layout.getGroupId();\r
+ }\r
+\r
+ // On enleve les "/"\r
+ try {\r
+ friendlyName = friendlyName.replaceAll("/", "-");\r
+ }\r
+ catch(Exception exc) {\r
+ // surement une creation de user!!!\r
+ // on ne fait rien ;)\r
+ }\r
+ \r
+ friendlyURL = getFriendlyURL(\r
+ user.getCompanyId(), groupId, classNameId, classPK, friendlyName,\r
+ friendlyURL);\r
+\r
+ if (staging) {\r
+ name = name.concat(" (Staging)");\r
+ friendlyURL = friendlyURL.concat("-staging");\r
+ }\r
+\r
+ if (className.equals(Group.class.getName())) {\r
+ if (!site && (liveGroupId == 0)) {\r
+ throw new IllegalArgumentException();\r
+ }\r
+ }\r
+ else if (!className.equals(Organization.class.getName()) &&\r
+ className.startsWith("com.liferay.portal.model.")) {\r
+\r
+ if (site) {\r
+ throw new IllegalArgumentException();\r
+ }\r
+ }\r
+\r
+ if ((classNameId <= 0) || className.equals(Group.class.getName())) {\r
+ validateName(groupId, user.getCompanyId(), name, site);\r
+ }\r
+\r
+ validateFriendlyURL(\r
+ user.getCompanyId(), groupId, classNameId, classPK, friendlyURL);\r
+\r
+ Group group = groupPersistence.create(groupId);\r
+\r
+ group.setCompanyId(user.getCompanyId());\r
+ group.setCreatorUserId(userId);\r
+ group.setClassNameId(classNameId);\r
+ group.setClassPK(classPK);\r
+ group.setParentGroupId(parentGroupId);\r
+ group.setLiveGroupId(liveGroupId);\r
+ group.setName(name);\r
+ group.setDescription(description);\r
+ group.setType(type);\r
+ group.setFriendlyURL(friendlyURL);\r
+ group.setSite(site);\r
+ group.setActive(active);\r
+\r
+ if ((serviceContext != null) && (classNameId == groupClassNameId) &&\r
+ !user.isDefaultUser()) {\r
+\r
+ group.setExpandoBridgeAttributes(serviceContext);\r
+ }\r
+\r
+ groupPersistence.update(group, false);\r
+\r
+ // Layout sets\r
+\r
+ try {\r
+ layoutSetLocalService.getLayoutSet(groupId, true);\r
+ } catch (NoSuchLayoutSetException e) {\r
+ layoutSetLocalService.addLayoutSet(groupId, true);\r
+ }\r
+\r
+ try {\r
+ layoutSetLocalService.getLayoutSet(groupId, false);\r
+ } catch (NoSuchLayoutSetException e) {\r
+ layoutSetLocalService.addLayoutSet(groupId, false);\r
+ }\r
+ \r
+ //Retire pour raisons de compatibilites.\r
+ //layoutSetLocalService.addLayoutSet(groupId, true);\r
+ //layoutSetLocalService.addLayoutSet(groupId, false);\r
+\r
+ if ((classNameId == groupClassNameId) && !user.isDefaultUser()) {\r
+\r
+ // Resources\r
+\r
+ resourceLocalService.addResources(\r
+ group.getCompanyId(), 0, 0, Group.class.getName(),\r
+ group.getGroupId(), false, false, false);\r
+\r
+ // Site roles\r
+\r
+ Role role = roleLocalService.getRole(\r
+ group.getCompanyId(), RoleConstants.SITE_OWNER);\r
+\r
+ userGroupRoleLocalService.addUserGroupRoles(\r
+ userId, groupId, new long[] {role.getRoleId()});\r
+\r
+ // User\r
+\r
+ userLocalService.addGroupUsers(\r
+ group.getGroupId(), new long[] {userId});\r
+\r
+ // Asset\r
+\r
+ if (serviceContext != null) {\r
+ updateAsset(\r
+ userId, group, serviceContext.getAssetCategoryIds(),\r
+ serviceContext.getAssetTagNames());\r
+ }\r
+ }\r
+ else if (className.equals(Organization.class.getName()) &&\r
+ !user.isDefaultUser()) {\r
+\r
+ // Resources\r
+\r
+ resourceLocalService.addResources(\r
+ group.getCompanyId(), 0, 0, Group.class.getName(),\r
+ group.getGroupId(), false, false, false);\r
+ }\r
+\r
+ return group;\r
+ }\r
+\r
+ /**\r
+ * Adds the group using the default live group.\r
+ *\r
+ * @param userId the primary key of the group's creator/owner\r
+ * @param className the entity's class name\r
+ * @param classPK the primary key of the entity's instance\r
+ * @param name the entity's name\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param type the group's type. For more information see {@link\r
+ * com.liferay.portal.model.GroupConstants}\r
+ * @param friendlyURL the group's friendlyURL\r
+ * @param site whether the group is to be associated with a main site\r
+ * @param active whether the group is active\r
+ * @param serviceContext the service context to be applied (optionally\r
+ * <code>null</code>). Can set asset category IDs and asset tag\r
+ * names for the group, and whether the group is for staging.\r
+ * @return the group\r
+ * @throws PortalException if a creator could not be found, if the group's\r
+ * information was invalid, if a layout could not be found, or if a\r
+ * valid friendly URL could not be created for the group\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group addGroup(\r
+ long userId, String className, long classPK, String name,\r
+ String description, int type, String friendlyURL, boolean site,\r
+ boolean active, ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ return addGroup(\r
+ userId, className, classPK, GroupConstants.DEFAULT_LIVE_GROUP_ID,\r
+ name, description, type, friendlyURL, site, active, serviceContext);\r
+ }\r
+\r
+ /**\r
+ * Adds the groups to the role.\r
+ *\r
+ * @param roleId the primary key of the role\r
+ * @param groupIds the primary keys of the groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void addRoleGroups(long roleId, long[] groupIds)\r
+ throws SystemException {\r
+\r
+ rolePersistence.addGroups(roleId, groupIds);\r
+\r
+ PermissionCacheUtil.clearCache();\r
+ }\r
+\r
+ /**\r
+ * Adds the user to the groups.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param groupIds the primary keys of the groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void addUserGroups(long userId, long[] groupIds)\r
+ throws SystemException {\r
+\r
+ userPersistence.addGroups(userId, groupIds);\r
+\r
+ PermissionCacheUtil.clearCache();\r
+ }\r
+\r
+ /**\r
+ * Adds a company group if it does not exist. This method is typically used\r
+ * when a virtual host is added.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @throws PortalException if a default user for the company could not be\r
+ * found, if the group's information was invalid, if a layout could\r
+ * not be found, or if a valid friendly URL could not be created for\r
+ * the group\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r
+ public void checkCompanyGroup(long companyId)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(Company.class);\r
+\r
+ int count = groupPersistence.countByC_C_C(\r
+ companyId, classNameId, companyId);\r
+\r
+ if (count == 0) {\r
+ long defaultUserId = userLocalService.getDefaultUserId(companyId);\r
+\r
+ groupLocalService.addGroup(\r
+ defaultUserId, Company.class.getName(), companyId, null, null,\r
+ 0, null, false, true, null);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Creates systems groups and other related data needed by the system on the\r
+ * very first startup. Also takes care of creating the control panel groups\r
+ * and layouts.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @throws PortalException if a new system group could not be created\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)\r
+ public void checkSystemGroups(long companyId)\r
+ throws PortalException, SystemException {\r
+\r
+ String companyIdHexString = StringUtil.toHexString(companyId);\r
+\r
+ for (Group group : groupFinder.findBySystem(companyId)) {\r
+ _systemGroupsMap.put(\r
+ companyIdHexString.concat(group.getName()), group);\r
+ }\r
+\r
+ long defaultUserId = userLocalService.getDefaultUserId(companyId);\r
+\r
+ String[] systemGroups = PortalUtil.getSystemGroups();\r
+\r
+ for (String name : systemGroups) {\r
+ String groupCacheKey = companyIdHexString.concat(name);\r
+\r
+ Group group = _systemGroupsMap.get(groupCacheKey);\r
+\r
+ if (group == null) {\r
+ group = groupPersistence.fetchByC_N(companyId, name);\r
+ }\r
+\r
+ if (group == null) {\r
+ String className = null;\r
+ long classPK = 0;\r
+ int type = GroupConstants.TYPE_SITE_OPEN;\r
+ String friendlyURL = null;\r
+ boolean site = true;\r
+\r
+ if (name.equals(GroupConstants.CONTROL_PANEL)) {\r
+ type = GroupConstants.TYPE_SITE_PRIVATE;\r
+ friendlyURL = GroupConstants.CONTROL_PANEL_FRIENDLY_URL;\r
+ }\r
+ else if (name.equals(GroupConstants.GUEST)) {\r
+ friendlyURL = "/guest";\r
+ }\r
+ else if (name.equals(GroupConstants.USER_PERSONAL_SITE)) {\r
+ className = UserPersonalSite.class.getName();\r
+ classPK = defaultUserId;\r
+ type = GroupConstants.TYPE_SITE_PRIVATE;\r
+ friendlyURL =\r
+ GroupConstants.USER_PERSONAL_SITE_FRIENDLY_URL;\r
+ site = false;\r
+ }\r
+\r
+ group = groupLocalService.addGroup(\r
+ defaultUserId, className, classPK, name, null, type,\r
+ friendlyURL, site, true, null);\r
+\r
+ if (name.equals(GroupConstants.USER_PERSONAL_SITE)) {\r
+ initUserPersonalSitePermissions(group);\r
+ }\r
+ }\r
+\r
+ if (group.isControlPanel()) {\r
+ LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(\r
+ group.getGroupId(), true);\r
+\r
+ if (layoutSet.getPageCount() == 0) {\r
+ addControlPanelLayouts(group);\r
+ }\r
+ }\r
+\r
+ if (group.getName().equals(GroupConstants.GUEST)) {\r
+ LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(\r
+ group.getGroupId(), false);\r
+\r
+ if (layoutSet.getPageCount() == 0) {\r
+ addDefaultGuestPublicLayouts(group);\r
+ }\r
+ }\r
+\r
+ _systemGroupsMap.put(groupCacheKey, group);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Deletes the group and its associated data.\r
+ *\r
+ * <p>\r
+ * The group is unstaged and its assets and resources including layouts,\r
+ * membership requests, subscriptions, teams, blogs, bookmarks, calendar\r
+ * events, image gallery, journals, message boards, polls, shopping related\r
+ * entities, software catalog, and wikis are also deleted.\r
+ * </p>\r
+ *\r
+ * @param group the group\r
+ * @throws PortalException if the group was a system group, or if the user\r
+ * did not have permission to delete the group or its assets or its\r
+ * resources\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @Override\r
+ public Group deleteGroup(Group group)\r
+ throws PortalException, SystemException {\r
+\r
+ if (PortalUtil.isSystemGroup(group.getName())) {\r
+ throw new RequiredGroupException(\r
+ String.valueOf(group.getGroupId()));\r
+ }\r
+\r
+ // Layout set branches\r
+\r
+ layoutSetBranchLocalService.deleteLayoutSetBranches(\r
+ group.getGroupId(), true, true);\r
+\r
+ layoutSetBranchLocalService.deleteLayoutSetBranches(\r
+ group.getGroupId(), false, true);\r
+\r
+ // Layout sets\r
+\r
+ ServiceContext serviceContext = new ServiceContext();\r
+\r
+ try {\r
+ layoutSetLocalService.deleteLayoutSet(\r
+ group.getGroupId(), true, serviceContext);\r
+ }\r
+ catch (NoSuchLayoutSetException nslse) {\r
+ }\r
+\r
+ try {\r
+ layoutSetLocalService.deleteLayoutSet(\r
+ group.getGroupId(), false, serviceContext);\r
+ }\r
+ catch (NoSuchLayoutSetException nslse) {\r
+ }\r
+\r
+ // Group roles\r
+\r
+ userGroupRoleLocalService.deleteUserGroupRolesByGroupId(\r
+ group.getGroupId());\r
+\r
+ // User group roles\r
+\r
+ userGroupGroupRoleLocalService.deleteUserGroupGroupRolesByGroupId(\r
+ group.getGroupId());\r
+\r
+ // Membership requests\r
+\r
+ membershipRequestLocalService.deleteMembershipRequests(\r
+ group.getGroupId());\r
+\r
+ // Subscriptions\r
+\r
+ subscriptionLocalService.deleteSubscriptions(\r
+ group.getCompanyId(), BlogsEntry.class.getName(),\r
+ group.getGroupId());\r
+ subscriptionLocalService.deleteSubscriptions(\r
+ group.getCompanyId(), JournalArticle.class.getName(),\r
+ group.getGroupId());\r
+\r
+ // Teams\r
+\r
+ teamLocalService.deleteTeams(group.getGroupId());\r
+\r
+ // Staging\r
+\r
+ unscheduleStaging(group);\r
+\r
+ if (group.hasStagingGroup()) {\r
+ deleteGroup(group.getStagingGroup().getGroupId());\r
+ }\r
+\r
+ // Themes\r
+\r
+ ThemeLoader themeLoader = ThemeLoaderFactory.getDefaultThemeLoader();\r
+\r
+ if (themeLoader != null) {\r
+ String themePath =\r
+ themeLoader.getFileStorage() + StringPool.SLASH +\r
+ group.getGroupId();\r
+\r
+ FileUtil.deltree(themePath + "-private");\r
+ FileUtil.deltree(themePath + "-public");\r
+ }\r
+\r
+ // Asset\r
+\r
+ if (group.isRegularSite()) {\r
+ assetEntryLocalService.deleteEntry(\r
+ Group.class.getName(), group.getGroupId());\r
+ }\r
+\r
+ assetVocabularyLocalService.deleteVocabularies(group.getGroupId());\r
+\r
+ // Blogs\r
+\r
+ blogsEntryLocalService.deleteEntries(group.getGroupId());\r
+ blogsStatsUserLocalService.deleteStatsUserByGroupId(group.getGroupId());\r
+\r
+ // Bookmarks\r
+\r
+ bookmarksFolderLocalService.deleteFolders(group.getGroupId());\r
+\r
+ // Calendar\r
+\r
+ calEventLocalService.deleteEvents(group.getGroupId());\r
+\r
+ // Document library\r
+\r
+ // Comment this because used in user's purge, we want to control the deleted folders and associated files\r
+ //repositoryLocalService.deleteRepositories(group.getGroupId());\r
+ dlFileEntryTypeLocalService.deleteFileEntryTypes(group.getGroupId());\r
+\r
+ // Journal\r
+\r
+ journalArticleLocalService.deleteArticles(group.getGroupId());\r
+ journalTemplateLocalService.deleteTemplates(group.getGroupId());\r
+ journalStructureLocalService.deleteStructures(group.getGroupId());\r
+\r
+ // Message boards\r
+\r
+ mbBanLocalService.deleteBansByGroupId(group.getGroupId());\r
+ mbCategoryLocalService.deleteCategories(group.getGroupId());\r
+ mbStatsUserLocalService.deleteStatsUsersByGroupId(group.getGroupId());\r
+ mbThreadLocalService.deleteThreads(\r
+ group.getGroupId(), MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);\r
+\r
+ // Polls\r
+\r
+ pollsQuestionLocalService.deleteQuestions(group.getGroupId());\r
+\r
+ // Shopping\r
+\r
+ shoppingCartLocalService.deleteGroupCarts(group.getGroupId());\r
+ shoppingCategoryLocalService.deleteCategories(group.getGroupId());\r
+ shoppingCouponLocalService.deleteCoupons(group.getGroupId());\r
+ shoppingOrderLocalService.deleteOrders(group.getGroupId());\r
+\r
+ // Software catalog\r
+\r
+ scFrameworkVersionLocalService.deleteFrameworkVersions(\r
+ group.getGroupId());\r
+ scProductEntryLocalService.deleteProductEntries(group.getGroupId());\r
+\r
+ // Wiki\r
+\r
+ wikiNodeLocalService.deleteNodes(group.getGroupId());\r
+\r
+ // Resources\r
+\r
+ if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {\r
+ List<ResourcePermission> resourcePermissions =\r
+ resourcePermissionPersistence.findByC_P(\r
+ group.getCompanyId(), String.valueOf(group.getGroupId()));\r
+\r
+ for (ResourcePermission resourcePermission : resourcePermissions) {\r
+ resourcePermissionLocalService.deleteResourcePermission(\r
+ resourcePermission);\r
+ }\r
+ }\r
+ else {\r
+ List<Resource> resources = resourceFinder.findByC_P(\r
+ group.getCompanyId(), String.valueOf(group.getGroupId()));\r
+\r
+ for (Resource resource : resources) {\r
+ resourceLocalService.deleteResource(resource);\r
+ }\r
+ }\r
+\r
+ if (!group.isStagingGroup() &&\r
+ (group.isOrganization() || group.isRegularSite())) {\r
+\r
+ resourceLocalService.deleteResource(\r
+ group.getCompanyId(), Group.class.getName(),\r
+ ResourceConstants.SCOPE_INDIVIDUAL, group.getGroupId());\r
+ }\r
+\r
+ // Group\r
+\r
+ if (group.isOrganization() && group.isSite()) {\r
+ group.setSite(false);\r
+\r
+ groupPersistence.update(group, false);\r
+ }\r
+ else {\r
+ groupPersistence.remove(group);\r
+ }\r
+\r
+ // Permission cache\r
+\r
+ PermissionCacheUtil.clearCache();\r
+\r
+ return group;\r
+ }\r
+\r
+ /**\r
+ * Deletes the group and its associated data.\r
+ *\r
+ * <p>\r
+ * The group is unstaged and its assets and resources including layouts,\r
+ * membership requests, subscriptions, teams, blogs, bookmarks, calendar\r
+ * events, image gallery, journals, message boards, polls, shopping related\r
+ * entities, software catalog, and wikis are also deleted.\r
+ * </p>\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @throws PortalException if a group with the primary key could not be\r
+ * found, if the group was a system group, or if the user did not\r
+ * have permission to delete the group, its assets, or its resources\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @Override\r
+ public Group deleteGroup(long groupId)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = groupPersistence.findByPrimaryKey(groupId);\r
+\r
+ return deleteGroup(group);\r
+ }\r
+\r
+ /**\r
+ * Returns the group with the matching friendly URL.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param friendlyURL the friendly URL\r
+ * @return the group with the friendly URL, or <code>null</code> if a\r
+ * matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group fetchFriendlyURLGroup(long companyId, String friendlyURL)\r
+ throws SystemException {\r
+\r
+ if (Validator.isNull(friendlyURL)) {\r
+ return null;\r
+ }\r
+\r
+ friendlyURL = getFriendlyURL(friendlyURL);\r
+\r
+ return groupPersistence.fetchByC_F(companyId, friendlyURL);\r
+ }\r
+\r
+ /**\r
+ * Returns the group with the matching group name.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param name the group's name\r
+ * @return the group with the name and associated company, or\r
+ * <code>null</code> if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @Skip\r
+ public Group fetchGroup(long companyId, String name)\r
+ throws SystemException {\r
+\r
+ Group group = _systemGroupsMap.get(\r
+ StringUtil.toHexString(companyId).concat(name));\r
+\r
+ if (group != null) {\r
+ return group;\r
+ }\r
+\r
+ return groupLocalService.loadFetchGroup(companyId, name);\r
+ }\r
+\r
+ /**\r
+ * Returns the company group.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @return the group associated with the company\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getCompanyGroup(long companyId)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(Company.class);\r
+\r
+ return groupPersistence.findByC_C_C(companyId, classNameId, companyId);\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all the groups associated with the company.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @return the range of groups associated with the company\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getCompanyGroups(long companyId, int start, int end)\r
+ throws SystemException {\r
+\r
+ return groupPersistence.findByCompanyId(companyId, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of groups associated with the company.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @return the number of groups associated with the company\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public int getCompanyGroupsCount(long companyId) throws SystemException {\r
+ return groupPersistence.countByCompanyId(companyId);\r
+ }\r
+\r
+ /**\r
+ * Returns the group with the matching friendly URL.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param friendlyURL the group's friendlyURL\r
+ * @return the group with the friendly URL\r
+ * @throws PortalException if a matching group could not be found, or if the\r
+ * friendly URL was invalid\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getFriendlyURLGroup(long companyId, String friendlyURL)\r
+ throws PortalException, SystemException {\r
+\r
+ if (Validator.isNull(friendlyURL)) {\r
+ throw new NoSuchGroupException();\r
+ }\r
+\r
+ friendlyURL = getFriendlyURL(friendlyURL);\r
+\r
+ return groupPersistence.findByC_F(companyId, friendlyURL);\r
+ }\r
+\r
+ /**\r
+ * Returns the group with the matching primary key.\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @return the group with the primary key\r
+ * @throws PortalException if a group with the primary key could not be\r
+ * found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @Override\r
+ @ThreadLocalCachable\r
+ public Group getGroup(long groupId)\r
+ throws PortalException, SystemException {\r
+\r
+ return groupPersistence.findByPrimaryKey(groupId);\r
+ }\r
+\r
+ /**\r
+ * Returns the group with the matching group name.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param name the group's name\r
+ * @return the group with the name\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @Skip\r
+ public Group getGroup(long companyId, String name)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = _systemGroupsMap.get(\r
+ StringUtil.toHexString(companyId).concat(name));\r
+\r
+ if (group != null) {\r
+ return group;\r
+ }\r
+\r
+ return groupLocalService.loadGetGroup(companyId, name);\r
+ }\r
+\r
+ public String getGroupDescriptiveName(Group group, Locale locale)\r
+ throws PortalException, SystemException {\r
+\r
+ String name = group.getName();\r
+\r
+ if (group.isCompany()) {\r
+ name = LanguageUtil.get(locale, "global");\r
+ }\r
+ else if (group.isControlPanel()) {\r
+ name = LanguageUtil.get(locale, "control-panel");\r
+ }\r
+ else if (group.isLayout()) {\r
+ Layout layout = layoutLocalService.getLayout(group.getClassPK());\r
+\r
+ name = layout.getName(locale);\r
+ }\r
+ else if (group.isLayoutPrototype()) {\r
+ LayoutPrototype layoutPrototype =\r
+ layoutPrototypeLocalService.getLayoutPrototype(\r
+ group.getClassPK());\r
+\r
+ name = layoutPrototype.getName(locale);\r
+ }\r
+ else if (group.isLayoutSetPrototype()) {\r
+ LayoutSetPrototype layoutSetPrototype =\r
+ layoutSetPrototypePersistence.findByPrimaryKey(\r
+ group.getClassPK());\r
+\r
+ name = layoutSetPrototype.getName(locale);\r
+ }\r
+ else if (group.isOrganization()) {\r
+ long organizationId = group.getOrganizationId();\r
+\r
+ Organization organization =\r
+ organizationPersistence.findByPrimaryKey(organizationId);\r
+\r
+ name = organization.getName();\r
+ }\r
+ else if (group.isUser()) {\r
+ long userId = group.getClassPK();\r
+\r
+ User user = userPersistence.findByPrimaryKey(userId);\r
+\r
+ name = user.getFullName();\r
+ }\r
+ else if (group.isUserGroup()) {\r
+ long userGroupId = group.getClassPK();\r
+\r
+ UserGroup userGroup = userGroupPersistence.findByPrimaryKey(\r
+ userGroupId);\r
+\r
+ name = userGroup.getName();\r
+ }\r
+ else if (group.isUserPersonalSite()) {\r
+ name = LanguageUtil.get(locale, "user-personal-site");\r
+ }\r
+ else if (name.equals(GroupConstants.GUEST)) {\r
+ Company company = companyPersistence.findByPrimaryKey(\r
+ group.getCompanyId());\r
+\r
+ Account account = company.getAccount();\r
+\r
+ name = account.getName();\r
+ }\r
+\r
+ return name;\r
+ }\r
+\r
+ public String getGroupDescriptiveName(long groupId, Locale locale)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = groupPersistence.findByPrimaryKey(groupId);\r
+\r
+ return getGroupDescriptiveName(group, locale);\r
+ }\r
+\r
+ /**\r
+ * Returns the groups with the matching primary keys.\r
+ *\r
+ * @param groupIds the primary keys of the groups\r
+ * @return the groups with the primary keys\r
+ * @throws PortalException if any one of the groups could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getGroups(long[] groupIds)\r
+ throws PortalException, SystemException {\r
+\r
+ List<Group> groups = new ArrayList<Group>(groupIds.length);\r
+\r
+ for (long groupId : groupIds) {\r
+ Group group = getGroup(groupId);\r
+\r
+ groups.add(group);\r
+ }\r
+\r
+ return groups;\r
+ }\r
+\r
+ /**\r
+ * Returns the group associated with the layout.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param plid the primary key of the layout\r
+ * @return the group associated with the layout\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getLayoutGroup(long companyId, long plid)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(Layout.class);\r
+\r
+ return groupPersistence.findByC_C_C(companyId, classNameId, plid);\r
+ }\r
+\r
+ /**\r
+ * Returns the group associated with the layout prototype.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param layoutPrototypeId the primary key of the layout prototype\r
+ * @return the group associated with the layout prototype\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getLayoutPrototypeGroup(long companyId, long layoutPrototypeId)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(LayoutPrototype.class);\r
+\r
+ return groupPersistence.findByC_C_C(\r
+ companyId, classNameId, layoutPrototypeId);\r
+ }\r
+\r
+ /**\r
+ * Returns the group associated with the layout set prototype.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param layoutSetPrototypeId the primary key of the layout set prototype\r
+ * @return the group associated with the layout set prototype\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getLayoutSetPrototypeGroup(\r
+ long companyId, long layoutSetPrototypeId)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(LayoutSetPrototype.class);\r
+\r
+ return groupPersistence.findByC_C_C(\r
+ companyId, classNameId, layoutSetPrototypeId);\r
+ }\r
+\r
+ /**\r
+ * Returns all live groups.\r
+ *\r
+ * @return all live groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getLiveGroups() throws SystemException {\r
+ return groupFinder.findByLiveGroups();\r
+ }\r
+\r
+ /**\r
+ * Returns a range of all non-system groups of a specified type (className)\r
+ * that have no layouts.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param className the entity's class name\r
+ * @param privateLayout whether to include groups with private layout sets\r
+ * or non-private layout sets\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @return the range of matching groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getNoLayoutsGroups(\r
+ String className, boolean privateLayout, int start, int end)\r
+ throws SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(className);\r
+\r
+ return groupFinder.findByNoLayouts(\r
+ classNameId, privateLayout, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns all non-system groups having <code>null</code> or empty friendly\r
+ * URLs.\r
+ *\r
+ * @return the non-system groups having <code>null</code> or empty friendly\r
+ * URLs\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getNullFriendlyURLGroups() throws SystemException {\r
+ return groupFinder.findByNullFriendlyURL();\r
+ }\r
+\r
+ /**\r
+ * Returns the specified organization group.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param organizationId the primary key of the organization\r
+ * @return the group associated with the organization\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getOrganizationGroup(long companyId, long organizationId)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(Organization.class);\r
+\r
+ return groupPersistence.findByC_C_C(\r
+ companyId, classNameId, organizationId);\r
+ }\r
+\r
+ /**\r
+ * Returns the specified organization groups.\r
+ *\r
+ * @param organizations the organizations\r
+ * @return the groups associated with the organizations\r
+ */\r
+ public List<Group> getOrganizationsGroups(\r
+ List<Organization> organizations) {\r
+\r
+ List<Group> organizationGroups = new ArrayList<Group>();\r
+\r
+ for (int i = 0; i < organizations.size(); i++) {\r
+ Organization organization = organizations.get(i);\r
+\r
+ Group group = organization.getGroup();\r
+\r
+ organizationGroups.add(group);\r
+ }\r
+\r
+ return organizationGroups;\r
+ }\r
+\r
+ /**\r
+ * Returns all the groups related to the organizations.\r
+ *\r
+ * @param organizations the organizations\r
+ * @return the groups related to the organizations\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getOrganizationsRelatedGroups(\r
+ List<Organization> organizations)\r
+ throws SystemException {\r
+\r
+ List<Group> organizationGroups = new ArrayList<Group>();\r
+\r
+ for (int i = 0; i < organizations.size(); i++) {\r
+ Organization organization = organizations.get(i);\r
+\r
+ List<Group> groups = organizationPersistence.getGroups(\r
+ organization.getOrganizationId());\r
+\r
+ organizationGroups.addAll(groups);\r
+ }\r
+\r
+ return organizationGroups;\r
+ }\r
+\r
+ /**\r
+ * Returns all the groups associated with the role.\r
+ *\r
+ * @param roleId the primary key of the role\r
+ * @return the groups associated with the role\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getRoleGroups(long roleId) throws SystemException {\r
+ return rolePersistence.getGroups(roleId);\r
+ }\r
+\r
+ /**\r
+ * Returns the staging group.\r
+ *\r
+ * @param liveGroupId the primary key of the live group\r
+ * @return the staging group\r
+ * @throws PortalException if a matching staging group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getStagingGroup(long liveGroupId)\r
+ throws PortalException, SystemException {\r
+\r
+ return groupPersistence.findByLiveGroupId(liveGroupId);\r
+ }\r
+\r
+ /**\r
+ * Returns the group associated with the user.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param userId the primary key of the user\r
+ * @return the group associated with the user\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getUserGroup(long companyId, long userId)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(User.class);\r
+\r
+ return groupPersistence.findByC_C_C(companyId, classNameId, userId);\r
+ }\r
+\r
+ /**\r
+ * Returns the specified "user group" group. That is, the group that\r
+ * represents the {@link com.liferay.portal.model.UserGroup} entity.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param userGroupId the primary key of the user group\r
+ * @return the group associated with the user group\r
+ * @throws PortalException if a matching group could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group getUserGroupGroup(long companyId, long userGroupId)\r
+ throws PortalException, SystemException {\r
+\r
+ long classNameId = PortalUtil.getClassNameId(UserGroup.class);\r
+\r
+ return groupPersistence.findByC_C_C(\r
+ companyId, classNameId, userGroupId);\r
+ }\r
+\r
+ /**\r
+ * Returns all the user's site groups and immediate organization groups.\r
+ * System and staged groups are not included.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @return the user's groups and organization groups\r
+ * @throws PortalException if a user with the primary key could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getUserGroups(long userId)\r
+ throws PortalException, SystemException {\r
+\r
+ return getUserGroups(userId, false);\r
+ }\r
+\r
+ /**\r
+ * Returns all the user's site groups and immediate organization groups,\r
+ * optionally including the user's inherited organization groups and user\r
+ * groups. System and staged groups are not included.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param inherit whether to include the user's inherited organization\r
+ * groups and user groups\r
+ * @return the user's groups and immediate organization groups\r
+ * @throws PortalException if a user with the primary key could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getUserGroups(long userId, boolean inherit)\r
+ throws PortalException, SystemException {\r
+\r
+ return getUserGroups(\r
+ userId, inherit, QueryUtil.ALL_POS, QueryUtil.ALL_POS);\r
+ }\r
+\r
+ /**\r
+ * Returns a name ordered range of all the user's site groups and immediate\r
+ * organization groups, optionally including the user's inherited\r
+ * organization groups and user groups. System and staged groups are not\r
+ * included.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param inherit whether to include the user's inherited organization\r
+ * groups and user groups\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @return the range of the user's groups and immediate organization groups\r
+ * ordered by name\r
+ * @throws PortalException if a user with the primary key could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getUserGroups(\r
+ long userId, boolean inherit, int start, int end)\r
+ throws PortalException, SystemException {\r
+\r
+ if (inherit) {\r
+ User user = userPersistence.findByPrimaryKey(userId);\r
+\r
+ LinkedHashMap<String, Object> groupParams =\r
+ new LinkedHashMap<String, Object>();\r
+\r
+ groupParams.put("usersGroups", new Long(userId));\r
+\r
+ return search(\r
+ user.getCompanyId(), null, null, groupParams, start, end);\r
+ }\r
+ else {\r
+ return userPersistence.getGroups(userId, start, end);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Returns a name ordered range of all the user's site groups and immediate\r
+ * organization groups. System and staged groups are not included.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @return the range of the user's groups and organization groups ordered by\r
+ * name\r
+ * @throws PortalException if a user with the primary key could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getUserGroups(long userId, int start, int end)\r
+ throws PortalException, SystemException {\r
+\r
+ return getUserGroups(userId, false, start, end);\r
+ }\r
+\r
+ /**\r
+ * Returns the groups associated with the user groups.\r
+ *\r
+ * @param userGroups the user groups\r
+ * @return the groups associated with the user groups\r
+ * @throws PortalException if any one of the user group's group could not be\r
+ * found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getUserGroupsGroups(List<UserGroup> userGroups)\r
+ throws PortalException, SystemException {\r
+\r
+ List<Group> userGroupGroups = new ArrayList<Group>();\r
+\r
+ for (int i = 0; i < userGroups.size(); i++) {\r
+ UserGroup userGroup = userGroups.get(i);\r
+\r
+ Group group = userGroup.getGroup();\r
+\r
+ userGroupGroups.add(group);\r
+ }\r
+\r
+ return userGroupGroups;\r
+ }\r
+\r
+ /**\r
+ * Returns all the groups related to the user groups.\r
+ *\r
+ * @param userGroups the user groups\r
+ * @return the groups related to the user groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getUserGroupsRelatedGroups(List<UserGroup> userGroups)\r
+ throws SystemException {\r
+\r
+ List<Group> userGroupGroups = new ArrayList<Group>();\r
+\r
+ for (int i = 0; i < userGroups.size(); i++) {\r
+ UserGroup userGroup = userGroups.get(i);\r
+\r
+ List<Group> groups = userGroupPersistence.getGroups(\r
+ userGroup.getUserGroupId());\r
+\r
+ userGroupGroups.addAll(groups);\r
+ }\r
+\r
+ return userGroupGroups;\r
+ }\r
+\r
+ /**\r
+ * Returns the range of all groups associated with the user's organization\r
+ * groups, including the ancestors of the organization groups, unless portal\r
+ * property <code>organizations.membership.strict</code> is set to\r
+ * <code>true</code>.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param start the lower bound of the range of groups to consider\r
+ * @param end the upper bound of the range of groups to consider (not\r
+ * inclusive)\r
+ * @return the range of groups associated with the user's organization\r
+ * groups\r
+ * @throws PortalException if a user with the primary key could not be found\r
+ * or if another portal exception occurred\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> getUserOrganizationsGroups(\r
+ long userId, int start, int end)\r
+ throws PortalException, SystemException {\r
+\r
+ List<Group> userOrgsGroups = new UniqueList<Group>();\r
+\r
+ List<Organization> userOrgs =\r
+ organizationLocalService.getUserOrganizations(userId, start, end);\r
+\r
+ for (Organization organization : userOrgs) {\r
+ userOrgsGroups.add(0, organization.getGroup());\r
+\r
+ if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) {\r
+ for (Organization ancestorOrganization :\r
+ organization.getAncestors()) {\r
+\r
+ userOrgsGroups.add(0, ancestorOrganization.getGroup());\r
+ }\r
+ }\r
+ }\r
+\r
+ return userOrgsGroups;\r
+ }\r
+\r
+ /**\r
+ * Returns <code>true</code> if the group is associated with the role.\r
+ *\r
+ * @param roleId the primary key of the role\r
+ * @param groupId the primary key of the group\r
+ * @return <code>true</code> if the group is associated with the role;\r
+ * <code>false</code> otherwise\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public boolean hasRoleGroup(long roleId, long groupId)\r
+ throws SystemException {\r
+\r
+ return rolePersistence.containsGroup(roleId, groupId);\r
+ }\r
+\r
+ /**\r
+ * Returns <code>true</code> if the live group has a staging group.\r
+ *\r
+ * @param liveGroupId the primary key of the live group\r
+ * @return <code>true</code> if the live group has a staging group;\r
+ * <code>false</code> otherwise\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public boolean hasStagingGroup(long liveGroupId) throws SystemException {\r
+ if (groupPersistence.fetchByLiveGroupId(liveGroupId) != null) {\r
+ return true;\r
+ }\r
+ else {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Returns <code>true</code> if the user is immediately associated with the\r
+ * group, or associated with the group via the user's organizations,\r
+ * inherited organizations, or user groups.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param groupId the primary key of the group\r
+ * @return <code>true</code> if the user is associated with the group;\r
+ * <code>false</code> otherwise\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public boolean hasUserGroup(long userId, long groupId)\r
+ throws SystemException {\r
+\r
+ return hasUserGroup(userId, groupId, true);\r
+ }\r
+\r
+ /**\r
+ * Returns <code>true</code> if the user is immediately associated with the\r
+ * group, or optionally if the user is associated with the group via the\r
+ * user's organizations, inherited organizations, or user groups.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param groupId the primary key of the group\r
+ * @param inherit whether to include organization groups and user groups to\r
+ * which the user belongs in the determination\r
+ * @return <code>true</code> if the user is associated with the group;\r
+ * <code>false</code> otherwise\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public boolean hasUserGroup(long userId, long groupId, boolean inherit)\r
+ throws SystemException {\r
+\r
+ if (groupFinder.countByG_U(groupId, userId, inherit) > 0) {\r
+ return true;\r
+ }\r
+ else {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public Group loadFetchGroup(long companyId, String name)\r
+ throws SystemException {\r
+\r
+ return groupPersistence.fetchByC_N(companyId, name);\r
+ }\r
+\r
+ public Group loadGetGroup(long companyId, String name)\r
+ throws PortalException, SystemException {\r
+\r
+ return groupPersistence.findByC_N(companyId, name);\r
+ }\r
+\r
+ public List<Group> search(\r
+ long companyId, LinkedHashMap<String, Object> params, int start,\r
+ int end)\r
+ throws SystemException {\r
+\r
+ return groupFinder.findByCompanyId(\r
+ companyId, params, start, end, new GroupNameComparator(true));\r
+ }\r
+\r
+ /**\r
+ * Returns a name ordered range of all the groups that match the class name\r
+ * IDs, name, and description, optionally including the user's inherited\r
+ * organization groups and user groups. System and staged groups are not\r
+ * included.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param classNameIds the class names of entities to include in the search\r
+ * (optionally <code>null</code>)\r
+ * @param name the group's name (optionally <code>null</code>)\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param params the finder params (optionally <code>null</code>). To\r
+ * include a user's organizations, inherited organizations, and user\r
+ * groups in the search, add an entry with key\r
+ * "usersGroups" mapped to the user's ID and an entry with\r
+ * key "inherit" mapped to a non-<code>null</code> object.\r
+ * For more information see {@link\r
+ * com.liferay.portal.service.persistence.GroupFinder}\r
+ * com.liferay.portal.service.persistence.GroupFinder}\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @return the matching groups ordered by name\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> search(\r
+ long companyId, long[] classNameIds, String name,\r
+ String description, LinkedHashMap<String, Object> params, int start,\r
+ int end)\r
+ throws SystemException {\r
+\r
+ return search(\r
+ companyId, classNameIds, name, description, params, start, end,\r
+ null);\r
+ }\r
+\r
+ /**\r
+ * Returns an ordered range of all the groups that match the class name IDs,\r
+ * name, and description, optionally including the user's inherited\r
+ * organization groups and user groups. System and staged groups are not\r
+ * included.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param classNameIds the group's class name IDs (optionally\r
+ * <code>null</code>)\r
+ * @param name the group's name (optionally <code>null</code>)\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param params the finder params (optionally <code>null</code>). To\r
+ * include a user's organizations, inherited organizations, and user\r
+ * groups in the search, add an entry with key\r
+ * "usersGroups" mapped to the user's ID and an entry with\r
+ * key "inherit" mapped to a non-<code>null</code> object.\r
+ * For more information see {@link\r
+ * com.liferay.portal.service.persistence.GroupFinder}\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @param obc the comparator to order the groups (optionally\r
+ * <code>null</code>)\r
+ * @return the matching groups ordered by comparator <code>obc</code>\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> search(\r
+ long companyId, long[] classNameIds, String name,\r
+ String description, LinkedHashMap<String, Object> params, int start,\r
+ int end, OrderByComparator obc)\r
+ throws SystemException {\r
+\r
+ if (obc == null) {\r
+ obc = new GroupNameComparator(true);\r
+ }\r
+\r
+ String realName = getRealName(companyId, name);\r
+\r
+ return groupFinder.findByC_C_N_D(\r
+ companyId, classNameIds, name, realName, description, params, start,\r
+ end, obc);\r
+ }\r
+\r
+ /**\r
+ * Returns a name ordered range of all the site groups and organization\r
+ * groups that match the name and description, optionally including the\r
+ * user's inherited organization groups and user groups. System and staged\r
+ * groups are not included.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param name the group's name (optionally <code>null</code>)\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param params the finder params (optionally <code>null</code>). To\r
+ * include the user's inherited organizations and user groups in the\r
+ * search, add entries having "usersGroups" and\r
+ * "inherit" as keys mapped to the the user's ID. For more\r
+ * information see {@link\r
+ * com.liferay.portal.service.persistence.GroupFinder}\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @return the matching groups ordered by name\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> search(\r
+ long companyId, String name, String description,\r
+ LinkedHashMap<String, Object> params, int start, int end)\r
+ throws SystemException {\r
+\r
+ return search(companyId, name, description, params, start, end, null);\r
+ }\r
+\r
+ /**\r
+ * Returns an ordered range of all the site groups and organization groups\r
+ * that match the name and description, optionally including the user's\r
+ * inherited organization groups and user groups. System and staged groups\r
+ * are not included.\r
+ *\r
+ * <p>\r
+ * Useful when paginating results. Returns a maximum of <code>end -\r
+ * start</code> instances. <code>start</code> and <code>end</code> are not\r
+ * primary keys, they are indexes in the result set. Thus, <code>0</code>\r
+ * refers to the first result in the set. Setting both <code>start</code>\r
+ * and <code>end</code> to {@link\r
+ * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full\r
+ * result set.\r
+ * </p>\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param name the group's name (optionally <code>null</code>)\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param params the finder params (optionally <code>null</code>). To\r
+ * include the user's inherited organizations and user groups in the\r
+ * search, add entries having "usersGroups" and\r
+ * "inherit" as keys mapped to the the user's ID. For more\r
+ * information see {@link\r
+ * com.liferay.portal.service.persistence.GroupFinder}\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @param obc the comparator to order the groups (optionally\r
+ * <code>null</code>)\r
+ * @return the matching groups ordered by comparator <code>obc</code>\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Group> search(\r
+ long companyId, String name, String description,\r
+ LinkedHashMap<String, Object> params, int start, int end,\r
+ OrderByComparator obc)\r
+ throws SystemException {\r
+\r
+ if (obc == null) {\r
+ obc = new GroupNameComparator(true);\r
+ }\r
+\r
+ String realName = getRealName(companyId, name);\r
+\r
+ return groupFinder.findByC_N_D(\r
+ companyId, name, realName, description, params, start, end, obc);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of groups that match the class name IDs, name, and\r
+ * description, optionally including the user's inherited organization\r
+ * groups and user groups. System and staged groups are not included.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param classNameIds the class names of entities to include in the search\r
+ * (optionally <code>null</code>)\r
+ * @param name the group's name (optionally <code>null</code>)\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param params the finder params (optionally <code>null</code>). To\r
+ * include the user's inherited organization groups and user groups\r
+ * in the search, add entries having "usersGroups" and\r
+ * "inherit" as keys mapped to the the user's ID. For more\r
+ * information see {@link\r
+ * com.liferay.portal.service.persistence.GroupFinder}\r
+ * @return the number of matching groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @ThreadLocalCachable\r
+ public int searchCount(\r
+ long companyId, long[] classNameIds, String name,\r
+ String description, LinkedHashMap<String, Object> params)\r
+ throws SystemException {\r
+\r
+ String realName = getRealName(companyId, name);\r
+\r
+ return groupFinder.countByC_C_N_D(\r
+ companyId, classNameIds, name, realName, description, params);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of groups and immediate organization groups that match\r
+ * the name and description, optionally including the user's inherited\r
+ * organization groups and user groups. System and staged groups are not\r
+ * included.\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param name the group's name (optionally <code>null</code>)\r
+ * @param description the group's description (optionally\r
+ * <code>null</code>)\r
+ * @param params the finder params (optionally <code>null</code>). To\r
+ * include the user's inherited organization groups and user groups\r
+ * in the search, add entries having "usersGroups" and\r
+ * "inherit" as keys mapped to the the user's ID. For more\r
+ * information see {@link\r
+ * com.liferay.portal.service.persistence.GroupFinder}\r
+ * @return the number of matching groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @ThreadLocalCachable\r
+ public int searchCount(\r
+ long companyId, String name, String description,\r
+ LinkedHashMap<String, Object> params)\r
+ throws SystemException {\r
+\r
+ String realName = getRealName(companyId, name);\r
+\r
+ return groupFinder.countByC_N_D(\r
+ companyId, name, realName, description, params);\r
+ }\r
+\r
+ /**\r
+ * Sets the groups associated with the role, removing and adding\r
+ * associations as necessary.\r
+ *\r
+ * @param roleId the primary key of the role\r
+ * @param groupIds the primary keys of the groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void setRoleGroups(long roleId, long[] groupIds)\r
+ throws SystemException {\r
+\r
+ rolePersistence.setGroups(roleId, groupIds);\r
+\r
+ PermissionCacheUtil.clearCache();\r
+ }\r
+\r
+ /**\r
+ * Removes the groups from the role.\r
+ *\r
+ * @param roleId the primary key of the role\r
+ * @param groupIds the primary keys of the groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void unsetRoleGroups(long roleId, long[] groupIds)\r
+ throws SystemException {\r
+\r
+ rolePersistence.removeGroups(roleId, groupIds);\r
+\r
+ PermissionCacheUtil.clearCache();\r
+ }\r
+\r
+ /**\r
+ * Removes the user from the groups.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param groupIds the primary keys of the groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void unsetUserGroups(long userId, long[] groupIds)\r
+ throws SystemException {\r
+\r
+ userGroupRoleLocalService.deleteUserGroupRoles(userId, groupIds);\r
+\r
+ userPersistence.removeGroups(userId, groupIds);\r
+\r
+ PermissionCacheUtil.clearCache();\r
+ }\r
+\r
+ /**\r
+ * Updates the group's asset replacing categories and tag names.\r
+ *\r
+ * @param userId the primary key of the user\r
+ * @param group the group\r
+ * @param assetCategoryIds the primary keys of the asset categories\r
+ * (optionally <code>null</code>)\r
+ * @param assetTagNames the asset tag names (optionally <code>null</code>)\r
+ * @throws PortalException if a user with the primary key could not be found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public void updateAsset(\r
+ long userId, Group group, long[] assetCategoryIds,\r
+ String[] assetTagNames)\r
+ throws PortalException, SystemException {\r
+\r
+ User user = userPersistence.findByPrimaryKey(userId);\r
+\r
+ Company company = companyPersistence.findByPrimaryKey(\r
+ user.getCompanyId());\r
+\r
+ Group companyGroup = company.getGroup();\r
+\r
+ assetEntryLocalService.updateEntry(\r
+ userId, companyGroup.getGroupId(), Group.class.getName(),\r
+ group.getGroupId(), null, 0, assetCategoryIds, assetTagNames, false,\r
+ null, null, null, null, null, group.getDescriptiveName(),\r
+ group.getDescription(), null, null, null, 0, 0, null, false);\r
+ }\r
+\r
+ /**\r
+ * Updates the group's friendly URL.\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @param friendlyURL the group's new friendlyURL (optionally\r
+ * <code>null</code>)\r
+ * @return the group\r
+ * @throws PortalException if a group with the primary key could not be\r
+ * found or if a valid friendly URL could not be created for the\r
+ * group\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group updateFriendlyURL(long groupId, String friendlyURL)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = groupPersistence.findByPrimaryKey(groupId);\r
+\r
+ if (group.isUser()) {\r
+ User user = userPersistence.findByPrimaryKey(group.getClassPK());\r
+\r
+ friendlyURL = StringPool.SLASH + user.getScreenName();\r
+\r
+ if (group.getFriendlyURL().equals(friendlyURL)) {\r
+ return group;\r
+ }\r
+ }\r
+\r
+ friendlyURL = getFriendlyURL(\r
+ group.getCompanyId(), groupId, group.getClassNameId(),\r
+ group.getClassPK(), StringPool.BLANK, friendlyURL);\r
+\r
+ validateFriendlyURL(\r
+ group.getCompanyId(), group.getGroupId(), group.getClassNameId(),\r
+ group.getClassPK(), friendlyURL);\r
+\r
+ group.setFriendlyURL(friendlyURL);\r
+\r
+ groupPersistence.update(group, false);\r
+\r
+ return group;\r
+ }\r
+\r
+ /**\r
+ * Updates the group's type settings.\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @param typeSettings the group's new type settings (optionally\r
+ * <code>null</code>)\r
+ * @return the group\r
+ * @throws PortalException if a group with the primary key could not be\r
+ * found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group updateGroup(long groupId, String typeSettings)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = groupPersistence.findByPrimaryKey(groupId);\r
+\r
+ group.setTypeSettings(typeSettings);\r
+\r
+ groupPersistence.update(group, false);\r
+\r
+ return group;\r
+ }\r
+\r
+ /**\r
+ * Updates the group.\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @param name the group's new name\r
+ * @param description the group's new description (optionally\r
+ * <code>null</code>)\r
+ * @param type the group's new type. For more information see {@link\r
+ * com.liferay.portal.model.GroupConstants}\r
+ * @param friendlyURL the group's new friendlyURL (optionally\r
+ * <code>null</code>)\r
+ * @param active whether the group is active\r
+ * @param serviceContext the service context to be applied (optionally\r
+ * <code>null</code>). Can set asset category IDs and asset tag\r
+ * names for the group.\r
+ * @return the group\r
+ * @throws PortalException if a group with the primary key could not be\r
+ * found or if the friendly URL was invalid or could one not be\r
+ * created\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group updateGroup(\r
+ long groupId, String name, String description, int type,\r
+ String friendlyURL, boolean active, ServiceContext serviceContext)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = groupPersistence.findByPrimaryKey(groupId);\r
+\r
+ String className = group.getClassName();\r
+ long classNameId = group.getClassNameId();\r
+ long classPK = group.getClassPK();\r
+ friendlyURL = getFriendlyURL(\r
+ group.getCompanyId(), groupId, classNameId, classPK,\r
+ StringPool.BLANK, friendlyURL);\r
+\r
+ if ((classNameId <= 0) || className.equals(Group.class.getName())) {\r
+ validateName(\r
+ group.getGroupId(), group.getCompanyId(), name, group.isSite());\r
+ }\r
+ else if (className.equals(Organization.class.getName())) {\r
+ Organization organization =\r
+ organizationPersistence.findByPrimaryKey(classPK);\r
+\r
+ name = getOrgGroupName(organization.getName());\r
+ }\r
+ else if (!GroupConstants.USER_PERSONAL_SITE.equals(name)) {\r
+ name = String.valueOf(classPK);\r
+ }\r
+\r
+ if (PortalUtil.isSystemGroup(group.getName()) &&\r
+ !group.getName().equals(name)) {\r
+\r
+ throw new RequiredGroupException();\r
+ }\r
+\r
+ validateFriendlyURL(\r
+ group.getCompanyId(), group.getGroupId(), group.getClassNameId(),\r
+ group.getClassPK(), friendlyURL);\r
+\r
+ group.setName(name);\r
+ group.setDescription(description);\r
+ group.setType(type);\r
+ group.setFriendlyURL(friendlyURL);\r
+ group.setActive(active);\r
+\r
+ if ((serviceContext != null) && group.isSite()) {\r
+ group.setExpandoBridgeAttributes(serviceContext);\r
+ }\r
+\r
+ groupPersistence.update(group, false);\r
+\r
+ // Asset\r
+\r
+ if ((serviceContext != null) && group.isSite()) {\r
+ User user = null;\r
+\r
+ try {\r
+ user = userPersistence.findByPrimaryKey(\r
+ group.getCreatorUserId());\r
+\r
+ }\r
+ catch (NoSuchUserException nsue1) {\r
+ try {\r
+ user = userPersistence.findByPrimaryKey(\r
+ serviceContext.getUserId());\r
+ }\r
+ catch (NoSuchUserException nsue2) {\r
+ user = userLocalService.getDefaultUser(\r
+ group.getCompanyId());\r
+ }\r
+ }\r
+\r
+ updateAsset(\r
+ user.getUserId(), group, serviceContext.getAssetCategoryIds(),\r
+ serviceContext.getAssetTagNames());\r
+ }\r
+\r
+ return group;\r
+ }\r
+\r
+ /**\r
+ * Associates the group with a main site if the group is an organization.\r
+ *\r
+ * @param groupId the primary key of the group\r
+ * @param site whether the group is to be associated with a main site\r
+ * @return the group\r
+ * @throws PortalException if a group with the primary key could not be\r
+ * found\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public Group updateSite(long groupId, boolean site)\r
+ throws PortalException, SystemException {\r
+\r
+ Group group = groupPersistence.findByPrimaryKey(groupId);\r
+\r
+ if (!group.isOrganization()) {\r
+ return group;\r
+ }\r
+\r
+ group.setSite(site);\r
+\r
+ groupPersistence.update(group, false);\r
+\r
+ return group;\r
+ }\r
+\r
+ protected void addControlPanelLayouts(Group group)\r
+ throws PortalException, SystemException {\r
+\r
+ long defaultUserId = userLocalService.getDefaultUserId(\r
+ group.getCompanyId());\r
+\r
+ String friendlyURL = getFriendlyURL(\r
+ PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL);\r
+\r
+ ServiceContext serviceContext = new ServiceContext();\r
+\r
+ layoutLocalService.addLayout(\r
+ defaultUserId, group.getGroupId(), true,\r
+ LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,\r
+ PropsValues.CONTROL_PANEL_LAYOUT_NAME, StringPool.BLANK,\r
+ StringPool.BLANK, LayoutConstants.TYPE_CONTROL_PANEL, false,\r
+ friendlyURL, serviceContext);\r
+ }\r
+\r
+ protected void addDefaultGuestPublicLayoutByProperties(Group group)\r
+ throws PortalException, SystemException {\r
+\r
+ long defaultUserId = userLocalService.getDefaultUserId(\r
+ group.getCompanyId());\r
+ String friendlyURL = getFriendlyURL(\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_FRIENDLY_URL);\r
+\r
+ ServiceContext serviceContext = new ServiceContext();\r
+\r
+ Layout layout = layoutLocalService.addLayout(\r
+ defaultUserId, group.getGroupId(), false,\r
+ LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_NAME, StringPool.BLANK,\r
+ StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, friendlyURL,\r
+ serviceContext);\r
+\r
+ LayoutTypePortlet layoutTypePortlet =\r
+ (LayoutTypePortlet)layout.getLayoutType();\r
+\r
+ layoutTypePortlet.setLayoutTemplateId(\r
+ 0, PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_TEMPLATE_ID, false);\r
+\r
+ for (int i = 0; i < 10; i++) {\r
+ String columnId = "column-" + i;\r
+ String portletIds = PropsUtil.get(\r
+ PropsKeys.DEFAULT_GUEST_PUBLIC_LAYOUT_COLUMN + i);\r
+\r
+ layoutTypePortlet.addPortletIds(\r
+ 0, StringUtil.split(portletIds), columnId, false);\r
+ }\r
+\r
+ layoutLocalService.updateLayout(\r
+ layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),\r
+ layout.getTypeSettings());\r
+\r
+ boolean updateLayoutSet = false;\r
+\r
+ LayoutSet layoutSet = layout.getLayoutSet();\r
+\r
+ if (Validator.isNotNull(\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_THEME_ID)) {\r
+\r
+ layoutSet.setThemeId(\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_THEME_ID);\r
+\r
+ updateLayoutSet = true;\r
+ }\r
+\r
+ if (Validator.isNotNull(\r
+ PropsValues.\r
+ DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID)) {\r
+\r
+ layoutSet.setColorSchemeId(\r
+ PropsValues.\r
+ DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID);\r
+\r
+ updateLayoutSet = true;\r
+ }\r
+\r
+ if (Validator.isNotNull(\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_THEME_ID)) {\r
+\r
+ layoutSet.setWapThemeId(\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_THEME_ID);\r
+\r
+ updateLayoutSet = true;\r
+ }\r
+\r
+ if (Validator.isNotNull(\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID)) {\r
+\r
+ layoutSet.setWapColorSchemeId(\r
+ PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID);\r
+\r
+ updateLayoutSet = true;\r
+ }\r
+\r
+ if (updateLayoutSet) {\r
+ layoutSetLocalService.updateLayoutSet(layoutSet);\r
+ }\r
+ }\r
+\r
+ protected void addDefaultGuestPublicLayouts(Group group)\r
+ throws PortalException, SystemException {\r
+\r
+ if (publicLARFile != null) {\r
+ addDefaultGuestPublicLayoutsByLAR(group, publicLARFile);\r
+ }\r
+ else {\r
+ addDefaultGuestPublicLayoutByProperties(group);\r
+ }\r
+ }\r
+\r
+ protected void addDefaultGuestPublicLayoutsByLAR(Group group, File larFile)\r
+ throws PortalException, SystemException {\r
+\r
+ long defaultUserId = userLocalService.getDefaultUserId(\r
+ group.getCompanyId());\r
+\r
+ Map<String, String[]> parameterMap = new HashMap<String, String[]>();\r
+\r
+ parameterMap.put(\r
+ PortletDataHandlerKeys.CATEGORIES,\r
+ new String[] {Boolean.TRUE.toString()});\r
+ parameterMap.put(\r
+ PortletDataHandlerKeys.PERMISSIONS,\r
+ new String[] {Boolean.TRUE.toString()});\r
+ parameterMap.put(\r
+ PortletDataHandlerKeys.PORTLET_DATA,\r
+ new String[] {Boolean.TRUE.toString()});\r
+ parameterMap.put(\r
+ PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,\r
+ new String[] {Boolean.TRUE.toString()});\r
+ parameterMap.put(\r
+ PortletDataHandlerKeys.PORTLET_SETUP,\r
+ new String[] {Boolean.TRUE.toString()});\r
+ parameterMap.put(\r
+ PortletDataHandlerKeys.USER_PERMISSIONS,\r
+ new String[] {Boolean.FALSE.toString()});\r
+\r
+ layoutLocalService.importLayouts(\r
+ defaultUserId, group.getGroupId(), false, parameterMap, larFile);\r
+ }\r
+\r
+ protected String getFriendlyURL(\r
+ long companyId, long groupId, long classNameId, long classPK,\r
+ String friendlyName, String friendlyURL)\r
+ throws PortalException, SystemException {\r
+\r
+ friendlyURL = getFriendlyURL(friendlyURL);\r
+\r
+ if (Validator.isNotNull(friendlyURL)) {\r
+ return friendlyURL;\r
+ }\r
+\r
+ friendlyURL = StringPool.SLASH + getFriendlyURL(friendlyName);\r
+\r
+ String originalFriendlyURL = friendlyURL;\r
+\r
+ for (int i = 1;; i++) {\r
+ try {\r
+ validateFriendlyURL(\r
+ companyId, groupId, classNameId, classPK, friendlyURL);\r
+\r
+ break;\r
+ }\r
+ catch (GroupFriendlyURLException gfurle) {\r
+ int type = gfurle.getType();\r
+\r
+ if (type == GroupFriendlyURLException.DUPLICATE) {\r
+ friendlyURL = originalFriendlyURL + i;\r
+ }\r
+ else {\r
+ friendlyURL = StringPool.SLASH + classPK;\r
+\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return friendlyURL;\r
+ }\r
+\r
+ protected String getFriendlyURL(String friendlyURL) {\r
+ return FriendlyURLNormalizerUtil.normalize(friendlyURL);\r
+ }\r
+\r
+ protected String getOrgGroupName(String name) {\r
+ return name + ORGANIZATION_NAME_SUFFIX;\r
+ }\r
+\r
+ protected String getRealName(long companyId, String name)\r
+ throws SystemException {\r
+\r
+ if (Validator.isNull(name)) {\r
+ return name;\r
+ }\r
+\r
+ String realName = name;\r
+\r
+ try {\r
+ Company company = companyLocalService.getCompany(companyId);\r
+\r
+ Account account = company.getAccount();\r
+\r
+ String companyName = account.getName();\r
+\r
+ name = StringUtil.replace(\r
+ name, StringPool.PERCENT, StringPool.BLANK);\r
+\r
+ if (companyName.indexOf(name) != -1) {\r
+ realName =\r
+ StringPool.PERCENT + GroupConstants.GUEST +\r
+ StringPool.PERCENT;\r
+ }\r
+ }\r
+ catch (PortalException pe) {\r
+ }\r
+\r
+ return realName;\r
+ }\r
+\r
+ protected void initImportLARFile() {\r
+ String publicLARFileName = PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUTS_LAR;\r
+\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug("Reading public LAR file " + publicLARFileName);\r
+ }\r
+\r
+ if (Validator.isNotNull(publicLARFileName)) {\r
+ publicLARFile = new File(publicLARFileName);\r
+\r
+ if (!publicLARFile.exists()) {\r
+ _log.error(\r
+ "Public LAR file " + publicLARFile + " does not exist");\r
+\r
+ publicLARFile = null;\r
+ }\r
+ else {\r
+ if (_log.isDebugEnabled()) {\r
+ _log.debug("Using public LAR file " + publicLARFileName);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ protected void initUserPersonalSitePermissions(Group group)\r
+ throws PortalException, SystemException {\r
+\r
+ // User role\r
+\r
+ Role role = roleLocalService.getRole(\r
+ group.getCompanyId(), RoleConstants.USER);\r
+\r
+ setCompanyPermissions(\r
+ role, PortletKeys.PORTAL,\r
+ new String[] {ActionKeys.VIEW_CONTROL_PANEL});\r
+\r
+ List<Portlet> portlets = portletLocalService.getPortlets(\r
+ group.getCompanyId(), false, false);\r
+\r
+ for (Portlet portlet : portlets) {\r
+ setRolePermissions(\r
+ group, role, portlet.getPortletId(),\r
+ new String[] {ActionKeys.VIEW});\r
+ }\r
+\r
+ setRolePermissions(\r
+ group, role, Layout.class.getName(),\r
+ new String[] {ActionKeys.VIEW});\r
+\r
+ setRolePermissions(\r
+ group, role, "com.liferay.portlet.blogs",\r
+ new String[] {\r
+ ActionKeys.ADD_ENTRY, ActionKeys.PERMISSIONS,\r
+ ActionKeys.SUBSCRIBE});\r
+\r
+ setRolePermissions(\r
+ group, role, "com.liferay.portlet.calendar",\r
+ new String[] {\r
+ ActionKeys.ADD_EVENT, ActionKeys.EXPORT_ALL_EVENTS,\r
+ ActionKeys.PERMISSIONS});\r
+\r
+ // Power User role\r
+\r
+ role = roleLocalService.getRole(\r
+ group.getCompanyId(), RoleConstants.POWER_USER);\r
+\r
+ for (Portlet portlet : portlets) {\r
+ List<String> actions =\r
+ ResourceActionsUtil.getPortletResourceActions(\r
+ portlet.getPortletId());\r
+\r
+ String controlPanelEntryCategory = GetterUtil.getString(\r
+ portlet.getControlPanelEntryCategory());\r
+\r
+ if (actions.contains(ActionKeys.ACCESS_IN_CONTROL_PANEL) &&\r
+ controlPanelEntryCategory.equals(PortletCategoryKeys.CONTENT)) {\r
+\r
+ setRolePermissions(\r
+ group, role, portlet.getPortletId(),\r
+ new String[] {ActionKeys.ACCESS_IN_CONTROL_PANEL});\r
+ }\r
+ }\r
+\r
+ setRolePermissions(\r
+ group, role, Group.class.getName(),\r
+ new String[] {ActionKeys.MANAGE_LAYOUTS});\r
+\r
+ setRolePermissions(group, role, "com.liferay.portlet.asset");\r
+ setRolePermissions(group, role, "com.liferay.portlet.blogs");\r
+ setRolePermissions(group, role, "com.liferay.portlet.bookmarks");\r
+ setRolePermissions(group, role, "com.liferay.portlet.calendar");\r
+ setRolePermissions(group, role, "com.liferay.portlet.documentlibrary");\r
+ setRolePermissions(group, role, "com.liferay.portlet.imagegallery");\r
+ setRolePermissions(group, role, "com.liferay.portlet.messageboards");\r
+ setRolePermissions(group, role, "com.liferay.portlet.polls");\r
+ setRolePermissions(group, role, "com.liferay.portlet.wiki");\r
+ }\r
+\r
+ protected boolean isStaging(ServiceContext serviceContext) {\r
+ if (serviceContext != null) {\r
+ return ParamUtil.getBoolean(serviceContext, "staging");\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ protected void setCompanyPermissions(\r
+ Role role, String name, String[] actionIds)\r
+ throws PortalException, SystemException {\r
+\r
+ if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {\r
+ if (resourceBlockLocalService.isSupported(name)) {\r
+ resourceBlockLocalService.setCompanyScopePermissions(\r
+ role.getCompanyId(), name, role.getRoleId(),\r
+ Arrays.asList(actionIds));\r
+ }\r
+ else {\r
+ resourcePermissionLocalService.setResourcePermissions(\r
+ role.getCompanyId(), name, ResourceConstants.SCOPE_COMPANY,\r
+ String.valueOf(role.getCompanyId()), role.getRoleId(),\r
+ actionIds);\r
+ }\r
+ }\r
+ else {\r
+ permissionLocalService.setRolePermissions(\r
+ role.getRoleId(), role.getCompanyId(), name,\r
+ ResourceConstants.SCOPE_COMPANY,\r
+ String.valueOf(role.getCompanyId()), actionIds);\r
+ }\r
+ }\r
+\r
+ protected void setRolePermissions(Group group, Role role, String name)\r
+ throws PortalException, SystemException {\r
+\r
+ List<String> actions = ResourceActionsUtil.getModelResourceActions(\r
+ name);\r
+\r
+ setRolePermissions(\r
+ group, role, name, actions.toArray(new String[actions.size()]));\r
+ }\r
+\r
+ protected void setRolePermissions(\r
+ Group group, Role role, String name, String[] actionIds)\r
+ throws PortalException, SystemException {\r
+\r
+ if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {\r
+ if (resourceBlockLocalService.isSupported(name)) {\r
+ resourceBlockLocalService.setGroupScopePermissions(\r
+ role.getCompanyId(), group.getGroupId(), name,\r
+ role.getRoleId(), Arrays.asList(actionIds));\r
+ }\r
+ else {\r
+ resourcePermissionLocalService.setResourcePermissions(\r
+ group.getCompanyId(), name, ResourceConstants.SCOPE_GROUP,\r
+ String.valueOf(group.getGroupId()), role.getRoleId(),\r
+ actionIds);\r
+ }\r
+ }\r
+ else {\r
+ permissionLocalService.setRolePermissions(\r
+ role.getRoleId(), group.getCompanyId(), name,\r
+ ResourceConstants.SCOPE_GROUP,\r
+ String.valueOf(group.getGroupId()), actionIds);\r
+ }\r
+ }\r
+\r
+ protected void unscheduleStaging(Group group) {\r
+ try {\r
+\r
+ // Remote publishing\r
+\r
+ String groupName = StagingUtil.getSchedulerGroupName(\r
+ DestinationNames.LAYOUTS_REMOTE_PUBLISHER, group.getGroupId());\r
+\r
+ SchedulerEngineUtil.delete(groupName, StorageType.PERSISTED);\r
+\r
+ long liveGroupId = 0;\r
+ long stagingGroupId = 0;\r
+\r
+ if (group.isStagingGroup()) {\r
+ liveGroupId = group.getLiveGroupId();\r
+\r
+ stagingGroupId = group.getGroupId();\r
+ }\r
+ else if (group.hasStagingGroup()) {\r
+ liveGroupId = group.getGroupId();\r
+\r
+ stagingGroupId = group.getStagingGroup().getGroupId();\r
+ }\r
+\r
+ if ((liveGroupId != 0) && (stagingGroupId != 0)) {\r
+\r
+ // Publish to live\r
+\r
+ groupName = StagingUtil.getSchedulerGroupName(\r
+ DestinationNames.LAYOUTS_LOCAL_PUBLISHER, liveGroupId);\r
+\r
+ SchedulerEngineUtil.delete(groupName, StorageType.PERSISTED);\r
+\r
+ // Copy from live\r
+\r
+ groupName = StagingUtil.getSchedulerGroupName(\r
+ DestinationNames.LAYOUTS_LOCAL_PUBLISHER, stagingGroupId);\r
+\r
+ SchedulerEngineUtil.delete(groupName, StorageType.PERSISTED);\r
+ }\r
+ }\r
+ catch (Exception e) {\r
+ _log.error(\r
+ "Unable to unschedule events for group: " + group.getGroupId());\r
+ }\r
+ }\r
+\r
+ protected void validateFriendlyURL(\r
+ long companyId, long groupId, long classNameId, long classPK,\r
+ String friendlyURL)\r
+ throws PortalException, SystemException {\r
+\r
+ Company company = companyPersistence.findByPrimaryKey(companyId);\r
+\r
+ if (company.isSystem()) {\r
+ return;\r
+ }\r
+\r
+ if (Validator.isNull(friendlyURL)) {\r
+ return;\r
+ }\r
+\r
+ int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);\r
+\r
+ if (exceptionType != -1) {\r
+ throw new GroupFriendlyURLException(exceptionType);\r
+ }\r
+\r
+ Group group = groupPersistence.fetchByC_F(companyId, friendlyURL);\r
+\r
+ if ((group != null) && (group.getGroupId() != groupId)) {\r
+ throw new GroupFriendlyURLException(\r
+ GroupFriendlyURLException.DUPLICATE);\r
+ }\r
+\r
+ String groupIdFriendlyURL = friendlyURL.substring(1);\r
+\r
+ if (Validator.isNumber(groupIdFriendlyURL)) {\r
+ long groupClassNameId = PortalUtil.getClassNameId(Group.class);\r
+\r
+ if (((classNameId != groupClassNameId) &&\r
+ !groupIdFriendlyURL.equals(String.valueOf(classPK)) &&\r
+ !PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) ||\r
+ ((classNameId == groupClassNameId) &&\r
+ !groupIdFriendlyURL.equals(String.valueOf(groupId)))) {\r
+\r
+ GroupFriendlyURLException gfurle =\r
+ new GroupFriendlyURLException(\r
+ GroupFriendlyURLException.POSSIBLE_DUPLICATE);\r
+\r
+ gfurle.setKeywordConflict(groupIdFriendlyURL);\r
+\r
+ throw gfurle;\r
+ }\r
+ }\r
+\r
+ String screenName = friendlyURL.substring(1);\r
+\r
+ User user = userPersistence.fetchByC_SN(companyId, screenName);\r
+\r
+ if (user != null) {\r
+ long userClassNameId = PortalUtil.getClassNameId(User.class);\r
+\r
+ if ((classNameId == userClassNameId) &&\r
+ (classPK == user.getUserId())) {\r
+ }\r
+ else {\r
+ throw new GroupFriendlyURLException(\r
+ GroupFriendlyURLException.DUPLICATE);\r
+ }\r
+ }\r
+\r
+ if (StringUtil.count(friendlyURL, StringPool.SLASH) > 1) {\r
+ throw new GroupFriendlyURLException(\r
+ GroupFriendlyURLException.TOO_DEEP);\r
+ }\r
+ }\r
+\r
+ protected void validateName(\r
+ long groupId, long companyId, String name, boolean site)\r
+ throws PortalException, SystemException {\r
+\r
+ if (Validator.isNull(name) || Validator.isNumber(name) ||\r
+ name.contains(StringPool.STAR) ||\r
+ name.contains(ORGANIZATION_NAME_SUFFIX)) {\r
+\r
+ throw new GroupNameException();\r
+ }\r
+\r
+ try {\r
+ Group group = groupFinder.findByC_N(companyId, name);\r
+\r
+ if ((groupId <= 0) || (group.getGroupId() != groupId)) {\r
+ throw new DuplicateGroupException();\r
+ }\r
+ }\r
+ catch (NoSuchGroupException nsge) {\r
+ }\r
+\r
+ if (site) {\r
+ Company company = companyLocalService.getCompany(companyId);\r
+\r
+ if (name.equals(company.getName())) {\r
+ throw new DuplicateGroupException();\r
+ }\r
+ }\r
+ }\r
+\r
+ // AAPEESC DEBUT\r
+ /**\r
+ * Retourne les 10 premiers groupes ayant des tags communs avec un utilisateur\r
+ * La liste est triee dans l'ordre decroissant du nombre de tags en commun puis\r
+ * dans l'ordre alphabetique du nom de groupe\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param classNameIds the group's class name IDs (optionally\r
+ * <code>null</code>)\r
+ * @param liste de criteres.\r
+ * criteres userId : identifiant de l'utilisateur\r
+ * @param start the lower bound of the range of groups to return\r
+ * @param end the upper bound of the range of groups to return (not\r
+ * inclusive)\r
+ * @return the matching groups\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ \r
+ public List<Group> search(\r
+ long companyId, long[] classNameIds,\r
+ LinkedHashMap<String, Object> params, int start,\r
+ int end)\r
+ throws SystemException {\r
+\r
+ return groupFinder.findByUserTags(\r
+ companyId, classNameIds, params, start,\r
+ end);\r
+ }\r
+ \r
+ /**\r
+ * Retourne le nombre de groupes ayant des tags communs avec un utilisateur\r
+ *\r
+ * @param companyId the primary key of the company\r
+ * @param classNameIds the group's class name IDs (optionally\r
+ * <code>null</code>)\r
+ * @param liste de criteres.\r
+ * criteres userId : identifiant de l'utilisateur\r
+ * @return le nombre de groupes ayant des tags communs avec un utilisateur\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ @ThreadLocalCachable\r
+ public int searchCount(\r
+ long companyId, long[] classNameIds,LinkedHashMap<String, Object> params)\r
+ throws SystemException {\r
+ return groupFinder.countByUserTags(\r
+ companyId, classNameIds, params);\r
+ }\r
+ \r
+ /**\r
+ * Retourne les identifiants de tags attaches a un utilisateurs\r
+ *\r
+ * @param userId l'identifiant de l'utilisater\r
+ * @return les identifiants des tags attaches a l'utilisateur\r
+ * @throws SystemException if a system exception occurred\r
+ */\r
+ public List<Long> findUserTags(long userId) throws SystemException {\r
+ return groupFinder.findUserTags(userId);\r
+ }\r
+\r
+ // AAPEESC FIN\r
+ \r
+ protected File publicLARFile;\r
+\r
+ private static Log _log = LogFactoryUtil.getLog(\r
+ GroupLocalServiceImpl.class);\r
+\r
+ private Map<String, Group> _systemGroupsMap = new HashMap<String, Group>();\r
+\r
+}
\ No newline at end of file