2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portal.service.impl;
\r
17 import com.liferay.portal.DuplicateGroupException;
\r
18 import com.liferay.portal.GroupFriendlyURLException;
\r
19 import com.liferay.portal.GroupNameException;
\r
20 import com.liferay.portal.NoSuchGroupException;
\r
21 import com.liferay.portal.NoSuchLayoutSetException;
\r
22 import com.liferay.portal.NoSuchUserException;
\r
23 import com.liferay.portal.RequiredGroupException;
\r
24 import com.liferay.portal.kernel.cache.ThreadLocalCachable;
\r
25 import com.liferay.portal.kernel.dao.orm.QueryUtil;
\r
26 import com.liferay.portal.kernel.exception.PortalException;
\r
27 import com.liferay.portal.kernel.exception.SystemException;
\r
28 import com.liferay.portal.kernel.language.LanguageUtil;
\r
29 import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
\r
30 import com.liferay.portal.kernel.log.Log;
\r
31 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
32 import com.liferay.portal.kernel.messaging.DestinationNames;
\r
33 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
\r
34 import com.liferay.portal.kernel.scheduler.StorageType;
\r
35 import com.liferay.portal.kernel.spring.aop.Skip;
\r
36 import com.liferay.portal.kernel.staging.StagingUtil;
\r
37 import com.liferay.portal.kernel.transaction.Propagation;
\r
38 import com.liferay.portal.kernel.transaction.Transactional;
\r
39 import com.liferay.portal.kernel.util.FileUtil;
\r
40 import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
\r
41 import com.liferay.portal.kernel.util.GetterUtil;
\r
42 import com.liferay.portal.kernel.util.OrderByComparator;
\r
43 import com.liferay.portal.kernel.util.ParamUtil;
\r
44 import com.liferay.portal.kernel.util.PropsKeys;
\r
45 import com.liferay.portal.kernel.util.StringPool;
\r
46 import com.liferay.portal.kernel.util.StringUtil;
\r
47 import com.liferay.portal.kernel.util.UniqueList;
\r
48 import com.liferay.portal.kernel.util.Validator;
\r
49 import com.liferay.portal.model.Account;
\r
50 import com.liferay.portal.model.Company;
\r
51 import com.liferay.portal.model.Group;
\r
52 import com.liferay.portal.model.GroupConstants;
\r
53 import com.liferay.portal.model.Layout;
\r
54 import com.liferay.portal.model.LayoutConstants;
\r
55 import com.liferay.portal.model.LayoutPrototype;
\r
56 import com.liferay.portal.model.LayoutSet;
\r
57 import com.liferay.portal.model.LayoutSetPrototype;
\r
58 import com.liferay.portal.model.LayoutTypePortlet;
\r
59 import com.liferay.portal.model.Organization;
\r
60 import com.liferay.portal.model.Portlet;
\r
61 import com.liferay.portal.model.Resource;
\r
62 import com.liferay.portal.model.ResourceConstants;
\r
63 import com.liferay.portal.model.ResourcePermission;
\r
64 import com.liferay.portal.model.Role;
\r
65 import com.liferay.portal.model.RoleConstants;
\r
66 import com.liferay.portal.model.User;
\r
67 import com.liferay.portal.model.UserGroup;
\r
68 import com.liferay.portal.model.UserPersonalSite;
\r
69 import com.liferay.portal.model.impl.LayoutImpl;
\r
70 import com.liferay.portal.security.permission.ActionKeys;
\r
71 import com.liferay.portal.security.permission.PermissionCacheUtil;
\r
72 import com.liferay.portal.security.permission.ResourceActionsUtil;
\r
73 import com.liferay.portal.service.ServiceContext;
\r
74 import com.liferay.portal.service.base.GroupLocalServiceBaseImpl;
\r
75 import com.liferay.portal.theme.ThemeLoader;
\r
76 import com.liferay.portal.theme.ThemeLoaderFactory;
\r
77 import com.liferay.portal.util.PortalUtil;
\r
78 import com.liferay.portal.util.PortletCategoryKeys;
\r
79 import com.liferay.portal.util.PortletKeys;
\r
80 import com.liferay.portal.util.PropsUtil;
\r
81 import com.liferay.portal.util.PropsValues;
\r
82 import com.liferay.portal.util.comparator.GroupNameComparator;
\r
83 import com.liferay.portlet.blogs.model.BlogsEntry;
\r
84 import com.liferay.portlet.journal.model.JournalArticle;
\r
85 import com.liferay.portlet.messageboards.model.MBCategoryConstants;
\r
87 import java.io.File;
\r
89 import java.util.ArrayList;
\r
90 import java.util.Arrays;
\r
91 import java.util.HashMap;
\r
92 import java.util.LinkedHashMap;
\r
93 import java.util.List;
\r
94 import java.util.Locale;
\r
95 import java.util.Map;
\r
98 * The group local service is responsible for accessing, creating, modifying and
\r
102 * Groups are mostly used in Liferay as a resource container for permissioning
\r
103 * and content scoping purposes as described in {@link
\r
104 * com.liferay.portal.model.impl.GroupImpl}.
\r
108 * Groups are also the entity to which LayoutSets are generally associated.
\r
109 * Since LayoutSets are the parent entities of Layouts (i.e. pages), no entity
\r
110 * can have associated pages without also having an associated Group. This
\r
111 * relationship can be depicted as ... Layout -> LayoutSet -> Group[type] [->
\r
112 * Entity]. Note, the Entity part is optional.
\r
116 * Group has a "type" definition that is typically identified by two fields of
\r
117 * the entity - <code>String className</code>, and <code>int type </code>.
\r
121 * The <code>className</code> field helps create the group's association with
\r
122 * other entities (e.g. Organization, User, Company, UserGroup, ... etc.). The
\r
123 * value of <code>className</code> is the full name of the entity's class and
\r
124 * the primary key of the associated entity instance. A site has
\r
125 * <code>className="Group"</code> and has no associated entity.
\r
129 * The <code>type</code> field helps distinguish between a group used strictly
\r
130 * for scoping and a group that also has pages (in which case the type is
\r
131 * <code>SITE</code>). For a list of types, see {@link
\r
132 * com.liferay.portal.model.GroupConstants}.
\r
136 * Here is a listing of how Group is related to some portal entities ...
\r
141 * Site is a Group with <code>className="Group"</code>
\r
144 * Company has 1 Group (this is the global scope, but never has pages)
\r
147 * User has 1 Group (pages are optional based on the behavior configuration for
\r
151 * Layout Template (<code>LayoutPrototype</code>) has 1 Group which uses only 1
\r
152 * of it's 2 LayoutSets to store a single page which can later be used to
\r
153 * derive a single page in any Site
\r
156 * Site Template (<code>LayoutSetPrototype</code>) has 1 Group which uses only
\r
157 * 1 of it's 2 LayoutSets to store many pages which can later be used to derive
\r
158 * entire Sites or pulled into an existing Site
\r
161 * Organization has 1 Group, but can also be associated to a Site at any point
\r
162 * in it's life cycle in order to support having pages
\r
165 * UserGroup has 1 Group that can have pages in both of the group's LayoutSets
\r
166 * which are later inherited by users assigned to the UserGroup
\r
170 * @author Brian Wing Shun Chan
\r
171 * @author Alexander Chow
\r
172 * @author Bruno Farache
\r
173 * @author Wesley Gong
\r
174 * ---------------------------------------------------------------------------------
\r
175 19/12/2013 Putchhat SRUN M - AAPEESC - Ajout du critere tag dans la recherche
\r
178 public class GroupLocalServiceImpl extends GroupLocalServiceBaseImpl {
\r
180 public static final String ORGANIZATION_NAME_SUFFIX = " LFR_ORGANIZATION";
\r
183 * Constructs a group local service.
\r
185 public GroupLocalServiceImpl() {
\r
186 initImportLARFile();
\r
192 * @param userId the primary key of the group's creator/owner
\r
193 * @param className the entity's class name
\r
194 * @param classPK the primary key of the entity's instance
\r
195 * @param liveGroupId the primary key of the live group
\r
196 * @param name the entity's name
\r
197 * @param description the group's description (optionally
\r
198 * <code>null</code>)
\r
199 * @param type the group's type. For more information see {@link
\r
200 * com.liferay.portal.model.GroupConstants}
\r
201 * @param friendlyURL the group's friendlyURL (optionally
\r
202 * <code>null</code>)
\r
203 * @param site whether the group is to be associated with a main site
\r
204 * @param active whether the group is active
\r
205 * @param serviceContext the service context to be applied (optionally
\r
206 * <code>null</code>). Can set asset category IDs and asset tag
\r
207 * names for the group, and whether the group is for staging.
\r
208 * @return the group
\r
209 * @throws PortalException if a creator could not be found, if the group's
\r
210 * information was invalid, if a layout could not be found, or if a
\r
211 * valid friendly URL could not be created for the group
\r
212 * @throws SystemException if a system exception occurred
\r
214 public Group addGroup(
\r
215 long userId, String className, long classPK, long liveGroupId,
\r
216 String name, String description, int type, String friendlyURL,
\r
217 boolean site, boolean active, ServiceContext serviceContext)
\r
218 throws PortalException, SystemException {
\r
222 User user = userPersistence.findByPrimaryKey(userId);
\r
223 className = GetterUtil.getString(className);
\r
224 long classNameId = PortalUtil.getClassNameId(className);
\r
225 String friendlyName = name;
\r
230 groupId = counterLocalService.increment();
\r
232 User screenNameUser = userPersistence.fetchByC_SN(
\r
233 user.getCompanyId(), String.valueOf(groupId));
\r
235 if (screenNameUser == null) {
\r
240 boolean staging = isStaging(serviceContext);
\r
242 long groupClassNameId = PortalUtil.getClassNameId(Group.class);
\r
244 if ((classNameId <= 0) || className.equals(Group.class.getName())) {
\r
245 className = Group.class.getName();
\r
246 classNameId = groupClassNameId;
\r
249 else if (className.equals(Organization.class.getName())) {
\r
250 name = getOrgGroupName(name);
\r
252 else if (!GroupConstants.USER_PERSONAL_SITE.equals(name)) {
\r
253 name = String.valueOf(classPK);
\r
256 if (className.equals(Organization.class.getName()) && staging) {
\r
257 classPK = liveGroupId;
\r
260 long parentGroupId = GroupConstants.DEFAULT_PARENT_GROUP_ID;
\r
262 if (className.equals(Layout.class.getName())) {
\r
263 Layout layout = layoutLocalService.getLayout(classPK);
\r
265 parentGroupId = layout.getGroupId();
\r
268 // On enleve les "/"
\r
270 friendlyName = friendlyName.replaceAll("/", "-");
\r
272 catch(Exception exc) {
\r
273 // surement une creation de user!!!
\r
274 // on ne fait rien ;)
\r
277 friendlyURL = getFriendlyURL(
\r
278 user.getCompanyId(), groupId, classNameId, classPK, friendlyName,
\r
282 name = name.concat(" (Staging)");
\r
283 friendlyURL = friendlyURL.concat("-staging");
\r
286 if (className.equals(Group.class.getName())) {
\r
287 if (!site && (liveGroupId == 0)) {
\r
288 throw new IllegalArgumentException();
\r
291 else if (!className.equals(Organization.class.getName()) &&
\r
292 className.startsWith("com.liferay.portal.model.")) {
\r
295 throw new IllegalArgumentException();
\r
299 if ((classNameId <= 0) || className.equals(Group.class.getName())) {
\r
300 validateName(groupId, user.getCompanyId(), name, site);
\r
303 validateFriendlyURL(
\r
304 user.getCompanyId(), groupId, classNameId, classPK, friendlyURL);
\r
306 Group group = groupPersistence.create(groupId);
\r
308 group.setCompanyId(user.getCompanyId());
\r
309 group.setCreatorUserId(userId);
\r
310 group.setClassNameId(classNameId);
\r
311 group.setClassPK(classPK);
\r
312 group.setParentGroupId(parentGroupId);
\r
313 group.setLiveGroupId(liveGroupId);
\r
314 group.setName(name);
\r
315 group.setDescription(description);
\r
316 group.setType(type);
\r
317 group.setFriendlyURL(friendlyURL);
\r
318 group.setSite(site);
\r
319 group.setActive(active);
\r
321 if ((serviceContext != null) && (classNameId == groupClassNameId) &&
\r
322 !user.isDefaultUser()) {
\r
324 group.setExpandoBridgeAttributes(serviceContext);
\r
327 groupPersistence.update(group, false);
\r
332 layoutSetLocalService.getLayoutSet(groupId, true);
\r
333 } catch (NoSuchLayoutSetException e) {
\r
334 layoutSetLocalService.addLayoutSet(groupId, true);
\r
338 layoutSetLocalService.getLayoutSet(groupId, false);
\r
339 } catch (NoSuchLayoutSetException e) {
\r
340 layoutSetLocalService.addLayoutSet(groupId, false);
\r
343 //Retire pour raisons de compatibilites.
\r
344 //layoutSetLocalService.addLayoutSet(groupId, true);
\r
345 //layoutSetLocalService.addLayoutSet(groupId, false);
\r
347 if ((classNameId == groupClassNameId) && !user.isDefaultUser()) {
\r
351 resourceLocalService.addResources(
\r
352 group.getCompanyId(), 0, 0, Group.class.getName(),
\r
353 group.getGroupId(), false, false, false);
\r
357 Role role = roleLocalService.getRole(
\r
358 group.getCompanyId(), RoleConstants.SITE_OWNER);
\r
360 userGroupRoleLocalService.addUserGroupRoles(
\r
361 userId, groupId, new long[] {role.getRoleId()});
\r
365 userLocalService.addGroupUsers(
\r
366 group.getGroupId(), new long[] {userId});
\r
370 if (serviceContext != null) {
\r
372 userId, group, serviceContext.getAssetCategoryIds(),
\r
373 serviceContext.getAssetTagNames());
\r
376 else if (className.equals(Organization.class.getName()) &&
\r
377 !user.isDefaultUser()) {
\r
381 resourceLocalService.addResources(
\r
382 group.getCompanyId(), 0, 0, Group.class.getName(),
\r
383 group.getGroupId(), false, false, false);
\r
390 * Adds the group using the default live group.
\r
392 * @param userId the primary key of the group's creator/owner
\r
393 * @param className the entity's class name
\r
394 * @param classPK the primary key of the entity's instance
\r
395 * @param name the entity's name
\r
396 * @param description the group's description (optionally
\r
397 * <code>null</code>)
\r
398 * @param type the group's type. For more information see {@link
\r
399 * com.liferay.portal.model.GroupConstants}
\r
400 * @param friendlyURL the group's friendlyURL
\r
401 * @param site whether the group is to be associated with a main site
\r
402 * @param active whether the group is active
\r
403 * @param serviceContext the service context to be applied (optionally
\r
404 * <code>null</code>). Can set asset category IDs and asset tag
\r
405 * names for the group, and whether the group is for staging.
\r
406 * @return the group
\r
407 * @throws PortalException if a creator could not be found, if the group's
\r
408 * information was invalid, if a layout could not be found, or if a
\r
409 * valid friendly URL could not be created for the group
\r
410 * @throws SystemException if a system exception occurred
\r
412 public Group addGroup(
\r
413 long userId, String className, long classPK, String name,
\r
414 String description, int type, String friendlyURL, boolean site,
\r
415 boolean active, ServiceContext serviceContext)
\r
416 throws PortalException, SystemException {
\r
419 userId, className, classPK, GroupConstants.DEFAULT_LIVE_GROUP_ID,
\r
420 name, description, type, friendlyURL, site, active, serviceContext);
\r
424 * Adds the groups to the role.
\r
426 * @param roleId the primary key of the role
\r
427 * @param groupIds the primary keys of the groups
\r
428 * @throws SystemException if a system exception occurred
\r
430 public void addRoleGroups(long roleId, long[] groupIds)
\r
431 throws SystemException {
\r
433 rolePersistence.addGroups(roleId, groupIds);
\r
435 PermissionCacheUtil.clearCache();
\r
439 * Adds the user to the groups.
\r
441 * @param userId the primary key of the user
\r
442 * @param groupIds the primary keys of the groups
\r
443 * @throws SystemException if a system exception occurred
\r
445 public void addUserGroups(long userId, long[] groupIds)
\r
446 throws SystemException {
\r
448 userPersistence.addGroups(userId, groupIds);
\r
450 PermissionCacheUtil.clearCache();
\r
454 * Adds a company group if it does not exist. This method is typically used
\r
455 * when a virtual host is added.
\r
457 * @param companyId the primary key of the company
\r
458 * @throws PortalException if a default user for the company could not be
\r
459 * found, if the group's information was invalid, if a layout could
\r
460 * not be found, or if a valid friendly URL could not be created for
\r
462 * @throws SystemException if a system exception occurred
\r
464 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
\r
465 public void checkCompanyGroup(long companyId)
\r
466 throws PortalException, SystemException {
\r
468 long classNameId = PortalUtil.getClassNameId(Company.class);
\r
470 int count = groupPersistence.countByC_C_C(
\r
471 companyId, classNameId, companyId);
\r
474 long defaultUserId = userLocalService.getDefaultUserId(companyId);
\r
476 groupLocalService.addGroup(
\r
477 defaultUserId, Company.class.getName(), companyId, null, null,
\r
478 0, null, false, true, null);
\r
483 * Creates systems groups and other related data needed by the system on the
\r
484 * very first startup. Also takes care of creating the control panel groups
\r
487 * @param companyId the primary key of the company
\r
488 * @throws PortalException if a new system group could not be created
\r
489 * @throws SystemException if a system exception occurred
\r
491 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
\r
492 public void checkSystemGroups(long companyId)
\r
493 throws PortalException, SystemException {
\r
495 String companyIdHexString = StringUtil.toHexString(companyId);
\r
497 for (Group group : groupFinder.findBySystem(companyId)) {
\r
498 _systemGroupsMap.put(
\r
499 companyIdHexString.concat(group.getName()), group);
\r
502 long defaultUserId = userLocalService.getDefaultUserId(companyId);
\r
504 String[] systemGroups = PortalUtil.getSystemGroups();
\r
506 for (String name : systemGroups) {
\r
507 String groupCacheKey = companyIdHexString.concat(name);
\r
509 Group group = _systemGroupsMap.get(groupCacheKey);
\r
511 if (group == null) {
\r
512 group = groupPersistence.fetchByC_N(companyId, name);
\r
515 if (group == null) {
\r
516 String className = null;
\r
518 int type = GroupConstants.TYPE_SITE_OPEN;
\r
519 String friendlyURL = null;
\r
520 boolean site = true;
\r
522 if (name.equals(GroupConstants.CONTROL_PANEL)) {
\r
523 type = GroupConstants.TYPE_SITE_PRIVATE;
\r
524 friendlyURL = GroupConstants.CONTROL_PANEL_FRIENDLY_URL;
\r
526 else if (name.equals(GroupConstants.GUEST)) {
\r
527 friendlyURL = "/guest";
\r
529 else if (name.equals(GroupConstants.USER_PERSONAL_SITE)) {
\r
530 className = UserPersonalSite.class.getName();
\r
531 classPK = defaultUserId;
\r
532 type = GroupConstants.TYPE_SITE_PRIVATE;
\r
534 GroupConstants.USER_PERSONAL_SITE_FRIENDLY_URL;
\r
538 group = groupLocalService.addGroup(
\r
539 defaultUserId, className, classPK, name, null, type,
\r
540 friendlyURL, site, true, null);
\r
542 if (name.equals(GroupConstants.USER_PERSONAL_SITE)) {
\r
543 initUserPersonalSitePermissions(group);
\r
547 if (group.isControlPanel()) {
\r
548 LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(
\r
549 group.getGroupId(), true);
\r
551 if (layoutSet.getPageCount() == 0) {
\r
552 addControlPanelLayouts(group);
\r
556 if (group.getName().equals(GroupConstants.GUEST)) {
\r
557 LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(
\r
558 group.getGroupId(), false);
\r
560 if (layoutSet.getPageCount() == 0) {
\r
561 addDefaultGuestPublicLayouts(group);
\r
565 _systemGroupsMap.put(groupCacheKey, group);
\r
570 * Deletes the group and its associated data.
\r
573 * The group is unstaged and its assets and resources including layouts,
\r
574 * membership requests, subscriptions, teams, blogs, bookmarks, calendar
\r
575 * events, image gallery, journals, message boards, polls, shopping related
\r
576 * entities, software catalog, and wikis are also deleted.
\r
579 * @param group the group
\r
580 * @throws PortalException if the group was a system group, or if the user
\r
581 * did not have permission to delete the group or its assets or its
\r
583 * @throws SystemException if a system exception occurred
\r
586 public Group deleteGroup(Group group)
\r
587 throws PortalException, SystemException {
\r
589 if (PortalUtil.isSystemGroup(group.getName())) {
\r
590 throw new RequiredGroupException(
\r
591 String.valueOf(group.getGroupId()));
\r
594 // Layout set branches
\r
596 layoutSetBranchLocalService.deleteLayoutSetBranches(
\r
597 group.getGroupId(), true, true);
\r
599 layoutSetBranchLocalService.deleteLayoutSetBranches(
\r
600 group.getGroupId(), false, true);
\r
604 ServiceContext serviceContext = new ServiceContext();
\r
607 layoutSetLocalService.deleteLayoutSet(
\r
608 group.getGroupId(), true, serviceContext);
\r
610 catch (NoSuchLayoutSetException nslse) {
\r
614 layoutSetLocalService.deleteLayoutSet(
\r
615 group.getGroupId(), false, serviceContext);
\r
617 catch (NoSuchLayoutSetException nslse) {
\r
622 userGroupRoleLocalService.deleteUserGroupRolesByGroupId(
\r
623 group.getGroupId());
\r
625 // User group roles
\r
627 userGroupGroupRoleLocalService.deleteUserGroupGroupRolesByGroupId(
\r
628 group.getGroupId());
\r
630 // Membership requests
\r
632 membershipRequestLocalService.deleteMembershipRequests(
\r
633 group.getGroupId());
\r
637 subscriptionLocalService.deleteSubscriptions(
\r
638 group.getCompanyId(), BlogsEntry.class.getName(),
\r
639 group.getGroupId());
\r
640 subscriptionLocalService.deleteSubscriptions(
\r
641 group.getCompanyId(), JournalArticle.class.getName(),
\r
642 group.getGroupId());
\r
646 teamLocalService.deleteTeams(group.getGroupId());
\r
650 unscheduleStaging(group);
\r
652 if (group.hasStagingGroup()) {
\r
653 deleteGroup(group.getStagingGroup().getGroupId());
\r
658 ThemeLoader themeLoader = ThemeLoaderFactory.getDefaultThemeLoader();
\r
660 if (themeLoader != null) {
\r
662 themeLoader.getFileStorage() + StringPool.SLASH +
\r
663 group.getGroupId();
\r
665 FileUtil.deltree(themePath + "-private");
\r
666 FileUtil.deltree(themePath + "-public");
\r
671 if (group.isRegularSite()) {
\r
672 assetEntryLocalService.deleteEntry(
\r
673 Group.class.getName(), group.getGroupId());
\r
676 assetVocabularyLocalService.deleteVocabularies(group.getGroupId());
\r
680 blogsEntryLocalService.deleteEntries(group.getGroupId());
\r
681 blogsStatsUserLocalService.deleteStatsUserByGroupId(group.getGroupId());
\r
685 bookmarksFolderLocalService.deleteFolders(group.getGroupId());
\r
689 calEventLocalService.deleteEvents(group.getGroupId());
\r
691 // Document library
\r
693 // Comment this because used in user's purge, we want to control the deleted folders and associated files
\r
694 //repositoryLocalService.deleteRepositories(group.getGroupId());
\r
695 dlFileEntryTypeLocalService.deleteFileEntryTypes(group.getGroupId());
\r
699 journalArticleLocalService.deleteArticles(group.getGroupId());
\r
700 journalTemplateLocalService.deleteTemplates(group.getGroupId());
\r
701 journalStructureLocalService.deleteStructures(group.getGroupId());
\r
705 mbBanLocalService.deleteBansByGroupId(group.getGroupId());
\r
706 mbCategoryLocalService.deleteCategories(group.getGroupId());
\r
707 mbStatsUserLocalService.deleteStatsUsersByGroupId(group.getGroupId());
\r
708 mbThreadLocalService.deleteThreads(
\r
709 group.getGroupId(), MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
\r
713 pollsQuestionLocalService.deleteQuestions(group.getGroupId());
\r
717 shoppingCartLocalService.deleteGroupCarts(group.getGroupId());
\r
718 shoppingCategoryLocalService.deleteCategories(group.getGroupId());
\r
719 shoppingCouponLocalService.deleteCoupons(group.getGroupId());
\r
720 shoppingOrderLocalService.deleteOrders(group.getGroupId());
\r
722 // Software catalog
\r
724 scFrameworkVersionLocalService.deleteFrameworkVersions(
\r
725 group.getGroupId());
\r
726 scProductEntryLocalService.deleteProductEntries(group.getGroupId());
\r
730 wikiNodeLocalService.deleteNodes(group.getGroupId());
\r
734 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
\r
735 List<ResourcePermission> resourcePermissions =
\r
736 resourcePermissionPersistence.findByC_P(
\r
737 group.getCompanyId(), String.valueOf(group.getGroupId()));
\r
739 for (ResourcePermission resourcePermission : resourcePermissions) {
\r
740 resourcePermissionLocalService.deleteResourcePermission(
\r
741 resourcePermission);
\r
745 List<Resource> resources = resourceFinder.findByC_P(
\r
746 group.getCompanyId(), String.valueOf(group.getGroupId()));
\r
748 for (Resource resource : resources) {
\r
749 resourceLocalService.deleteResource(resource);
\r
753 if (!group.isStagingGroup() &&
\r
754 (group.isOrganization() || group.isRegularSite())) {
\r
756 resourceLocalService.deleteResource(
\r
757 group.getCompanyId(), Group.class.getName(),
\r
758 ResourceConstants.SCOPE_INDIVIDUAL, group.getGroupId());
\r
763 if (group.isOrganization() && group.isSite()) {
\r
764 group.setSite(false);
\r
766 groupPersistence.update(group, false);
\r
769 groupPersistence.remove(group);
\r
772 // Permission cache
\r
774 PermissionCacheUtil.clearCache();
\r
780 * Deletes the group and its associated data.
\r
783 * The group is unstaged and its assets and resources including layouts,
\r
784 * membership requests, subscriptions, teams, blogs, bookmarks, calendar
\r
785 * events, image gallery, journals, message boards, polls, shopping related
\r
786 * entities, software catalog, and wikis are also deleted.
\r
789 * @param groupId the primary key of the group
\r
790 * @throws PortalException if a group with the primary key could not be
\r
791 * found, if the group was a system group, or if the user did not
\r
792 * have permission to delete the group, its assets, or its resources
\r
793 * @throws SystemException if a system exception occurred
\r
796 public Group deleteGroup(long groupId)
\r
797 throws PortalException, SystemException {
\r
799 Group group = groupPersistence.findByPrimaryKey(groupId);
\r
801 return deleteGroup(group);
\r
805 * Returns the group with the matching friendly URL.
\r
807 * @param companyId the primary key of the company
\r
808 * @param friendlyURL the friendly URL
\r
809 * @return the group with the friendly URL, or <code>null</code> if a
\r
810 * matching group could not be found
\r
811 * @throws SystemException if a system exception occurred
\r
813 public Group fetchFriendlyURLGroup(long companyId, String friendlyURL)
\r
814 throws SystemException {
\r
816 if (Validator.isNull(friendlyURL)) {
\r
820 friendlyURL = getFriendlyURL(friendlyURL);
\r
822 return groupPersistence.fetchByC_F(companyId, friendlyURL);
\r
826 * Returns the group with the matching group name.
\r
828 * @param companyId the primary key of the company
\r
829 * @param name the group's name
\r
830 * @return the group with the name and associated company, or
\r
831 * <code>null</code> if a matching group could not be found
\r
832 * @throws SystemException if a system exception occurred
\r
835 public Group fetchGroup(long companyId, String name)
\r
836 throws SystemException {
\r
838 Group group = _systemGroupsMap.get(
\r
839 StringUtil.toHexString(companyId).concat(name));
\r
841 if (group != null) {
\r
845 return groupLocalService.loadFetchGroup(companyId, name);
\r
849 * Returns the company group.
\r
851 * @param companyId the primary key of the company
\r
852 * @return the group associated with the company
\r
853 * @throws PortalException if a matching group could not be found
\r
854 * @throws SystemException if a system exception occurred
\r
856 public Group getCompanyGroup(long companyId)
\r
857 throws PortalException, SystemException {
\r
859 long classNameId = PortalUtil.getClassNameId(Company.class);
\r
861 return groupPersistence.findByC_C_C(companyId, classNameId, companyId);
\r
865 * Returns a range of all the groups associated with the company.
\r
868 * Useful when paginating results. Returns a maximum of <code>end -
\r
869 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
870 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
871 * refers to the first result in the set. Setting both <code>start</code>
\r
872 * and <code>end</code> to {@link
\r
873 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
877 * @param companyId the primary key of the company
\r
878 * @param start the lower bound of the range of groups to return
\r
879 * @param end the upper bound of the range of groups to return (not
\r
881 * @return the range of groups associated with the company
\r
882 * @throws SystemException if a system exception occurred
\r
884 public List<Group> getCompanyGroups(long companyId, int start, int end)
\r
885 throws SystemException {
\r
887 return groupPersistence.findByCompanyId(companyId, start, end);
\r
891 * Returns the number of groups associated with the company.
\r
893 * @param companyId the primary key of the company
\r
894 * @return the number of groups associated with the company
\r
895 * @throws SystemException if a system exception occurred
\r
897 public int getCompanyGroupsCount(long companyId) throws SystemException {
\r
898 return groupPersistence.countByCompanyId(companyId);
\r
902 * Returns the group with the matching friendly URL.
\r
904 * @param companyId the primary key of the company
\r
905 * @param friendlyURL the group's friendlyURL
\r
906 * @return the group with the friendly URL
\r
907 * @throws PortalException if a matching group could not be found, or if the
\r
908 * friendly URL was invalid
\r
909 * @throws SystemException if a system exception occurred
\r
911 public Group getFriendlyURLGroup(long companyId, String friendlyURL)
\r
912 throws PortalException, SystemException {
\r
914 if (Validator.isNull(friendlyURL)) {
\r
915 throw new NoSuchGroupException();
\r
918 friendlyURL = getFriendlyURL(friendlyURL);
\r
920 return groupPersistence.findByC_F(companyId, friendlyURL);
\r
924 * Returns the group with the matching primary key.
\r
926 * @param groupId the primary key of the group
\r
927 * @return the group with the primary key
\r
928 * @throws PortalException if a group with the primary key could not be
\r
930 * @throws SystemException if a system exception occurred
\r
933 @ThreadLocalCachable
\r
934 public Group getGroup(long groupId)
\r
935 throws PortalException, SystemException {
\r
937 return groupPersistence.findByPrimaryKey(groupId);
\r
941 * Returns the group with the matching group name.
\r
943 * @param companyId the primary key of the company
\r
944 * @param name the group's name
\r
945 * @return the group with the name
\r
946 * @throws PortalException if a matching group could not be found
\r
947 * @throws SystemException if a system exception occurred
\r
950 public Group getGroup(long companyId, String name)
\r
951 throws PortalException, SystemException {
\r
953 Group group = _systemGroupsMap.get(
\r
954 StringUtil.toHexString(companyId).concat(name));
\r
956 if (group != null) {
\r
960 return groupLocalService.loadGetGroup(companyId, name);
\r
963 public String getGroupDescriptiveName(Group group, Locale locale)
\r
964 throws PortalException, SystemException {
\r
966 String name = group.getName();
\r
968 if (group.isCompany()) {
\r
969 name = LanguageUtil.get(locale, "global");
\r
971 else if (group.isControlPanel()) {
\r
972 name = LanguageUtil.get(locale, "control-panel");
\r
974 else if (group.isLayout()) {
\r
975 Layout layout = layoutLocalService.getLayout(group.getClassPK());
\r
977 name = layout.getName(locale);
\r
979 else if (group.isLayoutPrototype()) {
\r
980 LayoutPrototype layoutPrototype =
\r
981 layoutPrototypeLocalService.getLayoutPrototype(
\r
982 group.getClassPK());
\r
984 name = layoutPrototype.getName(locale);
\r
986 else if (group.isLayoutSetPrototype()) {
\r
987 LayoutSetPrototype layoutSetPrototype =
\r
988 layoutSetPrototypePersistence.findByPrimaryKey(
\r
989 group.getClassPK());
\r
991 name = layoutSetPrototype.getName(locale);
\r
993 else if (group.isOrganization()) {
\r
994 long organizationId = group.getOrganizationId();
\r
996 Organization organization =
\r
997 organizationPersistence.findByPrimaryKey(organizationId);
\r
999 name = organization.getName();
\r
1001 else if (group.isUser()) {
\r
1002 long userId = group.getClassPK();
\r
1004 User user = userPersistence.findByPrimaryKey(userId);
\r
1006 name = user.getFullName();
\r
1008 else if (group.isUserGroup()) {
\r
1009 long userGroupId = group.getClassPK();
\r
1011 UserGroup userGroup = userGroupPersistence.findByPrimaryKey(
\r
1014 name = userGroup.getName();
\r
1016 else if (group.isUserPersonalSite()) {
\r
1017 name = LanguageUtil.get(locale, "user-personal-site");
\r
1019 else if (name.equals(GroupConstants.GUEST)) {
\r
1020 Company company = companyPersistence.findByPrimaryKey(
\r
1021 group.getCompanyId());
\r
1023 Account account = company.getAccount();
\r
1025 name = account.getName();
\r
1031 public String getGroupDescriptiveName(long groupId, Locale locale)
\r
1032 throws PortalException, SystemException {
\r
1034 Group group = groupPersistence.findByPrimaryKey(groupId);
\r
1036 return getGroupDescriptiveName(group, locale);
\r
1040 * Returns the groups with the matching primary keys.
\r
1042 * @param groupIds the primary keys of the groups
\r
1043 * @return the groups with the primary keys
\r
1044 * @throws PortalException if any one of the groups could not be found
\r
1045 * @throws SystemException if a system exception occurred
\r
1047 public List<Group> getGroups(long[] groupIds)
\r
1048 throws PortalException, SystemException {
\r
1050 List<Group> groups = new ArrayList<Group>(groupIds.length);
\r
1052 for (long groupId : groupIds) {
\r
1053 Group group = getGroup(groupId);
\r
1055 groups.add(group);
\r
1062 * Returns the group associated with the layout.
\r
1064 * @param companyId the primary key of the company
\r
1065 * @param plid the primary key of the layout
\r
1066 * @return the group associated with the layout
\r
1067 * @throws PortalException if a matching group could not be found
\r
1068 * @throws SystemException if a system exception occurred
\r
1070 public Group getLayoutGroup(long companyId, long plid)
\r
1071 throws PortalException, SystemException {
\r
1073 long classNameId = PortalUtil.getClassNameId(Layout.class);
\r
1075 return groupPersistence.findByC_C_C(companyId, classNameId, plid);
\r
1079 * Returns the group associated with the layout prototype.
\r
1081 * @param companyId the primary key of the company
\r
1082 * @param layoutPrototypeId the primary key of the layout prototype
\r
1083 * @return the group associated with the layout prototype
\r
1084 * @throws PortalException if a matching group could not be found
\r
1085 * @throws SystemException if a system exception occurred
\r
1087 public Group getLayoutPrototypeGroup(long companyId, long layoutPrototypeId)
\r
1088 throws PortalException, SystemException {
\r
1090 long classNameId = PortalUtil.getClassNameId(LayoutPrototype.class);
\r
1092 return groupPersistence.findByC_C_C(
\r
1093 companyId, classNameId, layoutPrototypeId);
\r
1097 * Returns the group associated with the layout set prototype.
\r
1099 * @param companyId the primary key of the company
\r
1100 * @param layoutSetPrototypeId the primary key of the layout set prototype
\r
1101 * @return the group associated with the layout set prototype
\r
1102 * @throws PortalException if a matching group could not be found
\r
1103 * @throws SystemException if a system exception occurred
\r
1105 public Group getLayoutSetPrototypeGroup(
\r
1106 long companyId, long layoutSetPrototypeId)
\r
1107 throws PortalException, SystemException {
\r
1109 long classNameId = PortalUtil.getClassNameId(LayoutSetPrototype.class);
\r
1111 return groupPersistence.findByC_C_C(
\r
1112 companyId, classNameId, layoutSetPrototypeId);
\r
1116 * Returns all live groups.
\r
1118 * @return all live groups
\r
1119 * @throws SystemException if a system exception occurred
\r
1121 public List<Group> getLiveGroups() throws SystemException {
\r
1122 return groupFinder.findByLiveGroups();
\r
1126 * Returns a range of all non-system groups of a specified type (className)
\r
1127 * that have no layouts.
\r
1130 * Useful when paginating results. Returns a maximum of <code>end -
\r
1131 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1132 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1133 * refers to the first result in the set. Setting both <code>start</code>
\r
1134 * and <code>end</code> to {@link
\r
1135 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1139 * @param className the entity's class name
\r
1140 * @param privateLayout whether to include groups with private layout sets
\r
1141 * or non-private layout sets
\r
1142 * @param start the lower bound of the range of groups to return
\r
1143 * @param end the upper bound of the range of groups to return (not
\r
1145 * @return the range of matching groups
\r
1146 * @throws SystemException if a system exception occurred
\r
1148 public List<Group> getNoLayoutsGroups(
\r
1149 String className, boolean privateLayout, int start, int end)
\r
1150 throws SystemException {
\r
1152 long classNameId = PortalUtil.getClassNameId(className);
\r
1154 return groupFinder.findByNoLayouts(
\r
1155 classNameId, privateLayout, start, end);
\r
1159 * Returns all non-system groups having <code>null</code> or empty friendly
\r
1162 * @return the non-system groups having <code>null</code> or empty friendly
\r
1164 * @throws SystemException if a system exception occurred
\r
1166 public List<Group> getNullFriendlyURLGroups() throws SystemException {
\r
1167 return groupFinder.findByNullFriendlyURL();
\r
1171 * Returns the specified organization group.
\r
1173 * @param companyId the primary key of the company
\r
1174 * @param organizationId the primary key of the organization
\r
1175 * @return the group associated with the organization
\r
1176 * @throws PortalException if a matching group could not be found
\r
1177 * @throws SystemException if a system exception occurred
\r
1179 public Group getOrganizationGroup(long companyId, long organizationId)
\r
1180 throws PortalException, SystemException {
\r
1182 long classNameId = PortalUtil.getClassNameId(Organization.class);
\r
1184 return groupPersistence.findByC_C_C(
\r
1185 companyId, classNameId, organizationId);
\r
1189 * Returns the specified organization groups.
\r
1191 * @param organizations the organizations
\r
1192 * @return the groups associated with the organizations
\r
1194 public List<Group> getOrganizationsGroups(
\r
1195 List<Organization> organizations) {
\r
1197 List<Group> organizationGroups = new ArrayList<Group>();
\r
1199 for (int i = 0; i < organizations.size(); i++) {
\r
1200 Organization organization = organizations.get(i);
\r
1202 Group group = organization.getGroup();
\r
1204 organizationGroups.add(group);
\r
1207 return organizationGroups;
\r
1211 * Returns all the groups related to the organizations.
\r
1213 * @param organizations the organizations
\r
1214 * @return the groups related to the organizations
\r
1215 * @throws SystemException if a system exception occurred
\r
1217 public List<Group> getOrganizationsRelatedGroups(
\r
1218 List<Organization> organizations)
\r
1219 throws SystemException {
\r
1221 List<Group> organizationGroups = new ArrayList<Group>();
\r
1223 for (int i = 0; i < organizations.size(); i++) {
\r
1224 Organization organization = organizations.get(i);
\r
1226 List<Group> groups = organizationPersistence.getGroups(
\r
1227 organization.getOrganizationId());
\r
1229 organizationGroups.addAll(groups);
\r
1232 return organizationGroups;
\r
1236 * Returns all the groups associated with the role.
\r
1238 * @param roleId the primary key of the role
\r
1239 * @return the groups associated with the role
\r
1240 * @throws SystemException if a system exception occurred
\r
1242 public List<Group> getRoleGroups(long roleId) throws SystemException {
\r
1243 return rolePersistence.getGroups(roleId);
\r
1247 * Returns the staging group.
\r
1249 * @param liveGroupId the primary key of the live group
\r
1250 * @return the staging group
\r
1251 * @throws PortalException if a matching staging group could not be found
\r
1252 * @throws SystemException if a system exception occurred
\r
1254 public Group getStagingGroup(long liveGroupId)
\r
1255 throws PortalException, SystemException {
\r
1257 return groupPersistence.findByLiveGroupId(liveGroupId);
\r
1261 * Returns the group associated with the user.
\r
1263 * @param companyId the primary key of the company
\r
1264 * @param userId the primary key of the user
\r
1265 * @return the group associated with the user
\r
1266 * @throws PortalException if a matching group could not be found
\r
1267 * @throws SystemException if a system exception occurred
\r
1269 public Group getUserGroup(long companyId, long userId)
\r
1270 throws PortalException, SystemException {
\r
1272 long classNameId = PortalUtil.getClassNameId(User.class);
\r
1274 return groupPersistence.findByC_C_C(companyId, classNameId, userId);
\r
1278 * Returns the specified "user group" group. That is, the group that
\r
1279 * represents the {@link com.liferay.portal.model.UserGroup} entity.
\r
1281 * @param companyId the primary key of the company
\r
1282 * @param userGroupId the primary key of the user group
\r
1283 * @return the group associated with the user group
\r
1284 * @throws PortalException if a matching group could not be found
\r
1285 * @throws SystemException if a system exception occurred
\r
1287 public Group getUserGroupGroup(long companyId, long userGroupId)
\r
1288 throws PortalException, SystemException {
\r
1290 long classNameId = PortalUtil.getClassNameId(UserGroup.class);
\r
1292 return groupPersistence.findByC_C_C(
\r
1293 companyId, classNameId, userGroupId);
\r
1297 * Returns all the user's site groups and immediate organization groups.
\r
1298 * System and staged groups are not included.
\r
1300 * @param userId the primary key of the user
\r
1301 * @return the user's groups and organization groups
\r
1302 * @throws PortalException if a user with the primary key could not be found
\r
1303 * @throws SystemException if a system exception occurred
\r
1305 public List<Group> getUserGroups(long userId)
\r
1306 throws PortalException, SystemException {
\r
1308 return getUserGroups(userId, false);
\r
1312 * Returns all the user's site groups and immediate organization groups,
\r
1313 * optionally including the user's inherited organization groups and user
\r
1314 * groups. System and staged groups are not included.
\r
1316 * @param userId the primary key of the user
\r
1317 * @param inherit whether to include the user's inherited organization
\r
1318 * groups and user groups
\r
1319 * @return the user's groups and immediate organization groups
\r
1320 * @throws PortalException if a user with the primary key could not be found
\r
1321 * @throws SystemException if a system exception occurred
\r
1323 public List<Group> getUserGroups(long userId, boolean inherit)
\r
1324 throws PortalException, SystemException {
\r
1326 return getUserGroups(
\r
1327 userId, inherit, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
\r
1331 * Returns a name ordered range of all the user's site groups and immediate
\r
1332 * organization groups, optionally including the user's inherited
\r
1333 * organization groups and user groups. System and staged groups are not
\r
1337 * Useful when paginating results. Returns a maximum of <code>end -
\r
1338 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1339 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1340 * refers to the first result in the set. Setting both <code>start</code>
\r
1341 * and <code>end</code> to {@link
\r
1342 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1346 * @param userId the primary key of the user
\r
1347 * @param inherit whether to include the user's inherited organization
\r
1348 * groups and user groups
\r
1349 * @param start the lower bound of the range of groups to return
\r
1350 * @param end the upper bound of the range of groups to return (not
\r
1352 * @return the range of the user's groups and immediate organization groups
\r
1354 * @throws PortalException if a user with the primary key could not be found
\r
1355 * @throws SystemException if a system exception occurred
\r
1357 public List<Group> getUserGroups(
\r
1358 long userId, boolean inherit, int start, int end)
\r
1359 throws PortalException, SystemException {
\r
1362 User user = userPersistence.findByPrimaryKey(userId);
\r
1364 LinkedHashMap<String, Object> groupParams =
\r
1365 new LinkedHashMap<String, Object>();
\r
1367 groupParams.put("usersGroups", new Long(userId));
\r
1370 user.getCompanyId(), null, null, groupParams, start, end);
\r
1373 return userPersistence.getGroups(userId, start, end);
\r
1378 * Returns a name ordered range of all the user's site groups and immediate
\r
1379 * organization groups. System and staged groups are not included.
\r
1382 * Useful when paginating results. Returns a maximum of <code>end -
\r
1383 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1384 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1385 * refers to the first result in the set. Setting both <code>start</code>
\r
1386 * and <code>end</code> to {@link
\r
1387 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1391 * @param userId the primary key of the user
\r
1392 * @param start the lower bound of the range of groups to return
\r
1393 * @param end the upper bound of the range of groups to return (not
\r
1395 * @return the range of the user's groups and organization groups ordered by
\r
1397 * @throws PortalException if a user with the primary key could not be found
\r
1398 * @throws SystemException if a system exception occurred
\r
1400 public List<Group> getUserGroups(long userId, int start, int end)
\r
1401 throws PortalException, SystemException {
\r
1403 return getUserGroups(userId, false, start, end);
\r
1407 * Returns the groups associated with the user groups.
\r
1409 * @param userGroups the user groups
\r
1410 * @return the groups associated with the user groups
\r
1411 * @throws PortalException if any one of the user group's group could not be
\r
1413 * @throws SystemException if a system exception occurred
\r
1415 public List<Group> getUserGroupsGroups(List<UserGroup> userGroups)
\r
1416 throws PortalException, SystemException {
\r
1418 List<Group> userGroupGroups = new ArrayList<Group>();
\r
1420 for (int i = 0; i < userGroups.size(); i++) {
\r
1421 UserGroup userGroup = userGroups.get(i);
\r
1423 Group group = userGroup.getGroup();
\r
1425 userGroupGroups.add(group);
\r
1428 return userGroupGroups;
\r
1432 * Returns all the groups related to the user groups.
\r
1434 * @param userGroups the user groups
\r
1435 * @return the groups related to the user groups
\r
1436 * @throws SystemException if a system exception occurred
\r
1438 public List<Group> getUserGroupsRelatedGroups(List<UserGroup> userGroups)
\r
1439 throws SystemException {
\r
1441 List<Group> userGroupGroups = new ArrayList<Group>();
\r
1443 for (int i = 0; i < userGroups.size(); i++) {
\r
1444 UserGroup userGroup = userGroups.get(i);
\r
1446 List<Group> groups = userGroupPersistence.getGroups(
\r
1447 userGroup.getUserGroupId());
\r
1449 userGroupGroups.addAll(groups);
\r
1452 return userGroupGroups;
\r
1456 * Returns the range of all groups associated with the user's organization
\r
1457 * groups, including the ancestors of the organization groups, unless portal
\r
1458 * property <code>organizations.membership.strict</code> is set to
\r
1459 * <code>true</code>.
\r
1462 * Useful when paginating results. Returns a maximum of <code>end -
\r
1463 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1464 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1465 * refers to the first result in the set. Setting both <code>start</code>
\r
1466 * and <code>end</code> to {@link
\r
1467 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1471 * @param userId the primary key of the user
\r
1472 * @param start the lower bound of the range of groups to consider
\r
1473 * @param end the upper bound of the range of groups to consider (not
\r
1475 * @return the range of groups associated with the user's organization
\r
1477 * @throws PortalException if a user with the primary key could not be found
\r
1478 * or if another portal exception occurred
\r
1479 * @throws SystemException if a system exception occurred
\r
1481 public List<Group> getUserOrganizationsGroups(
\r
1482 long userId, int start, int end)
\r
1483 throws PortalException, SystemException {
\r
1485 List<Group> userOrgsGroups = new UniqueList<Group>();
\r
1487 List<Organization> userOrgs =
\r
1488 organizationLocalService.getUserOrganizations(userId, start, end);
\r
1490 for (Organization organization : userOrgs) {
\r
1491 userOrgsGroups.add(0, organization.getGroup());
\r
1493 if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) {
\r
1494 for (Organization ancestorOrganization :
\r
1495 organization.getAncestors()) {
\r
1497 userOrgsGroups.add(0, ancestorOrganization.getGroup());
\r
1502 return userOrgsGroups;
\r
1506 * Returns <code>true</code> if the group is associated with the role.
\r
1508 * @param roleId the primary key of the role
\r
1509 * @param groupId the primary key of the group
\r
1510 * @return <code>true</code> if the group is associated with the role;
\r
1511 * <code>false</code> otherwise
\r
1512 * @throws SystemException if a system exception occurred
\r
1514 public boolean hasRoleGroup(long roleId, long groupId)
\r
1515 throws SystemException {
\r
1517 return rolePersistence.containsGroup(roleId, groupId);
\r
1521 * Returns <code>true</code> if the live group has a staging group.
\r
1523 * @param liveGroupId the primary key of the live group
\r
1524 * @return <code>true</code> if the live group has a staging group;
\r
1525 * <code>false</code> otherwise
\r
1526 * @throws SystemException if a system exception occurred
\r
1528 public boolean hasStagingGroup(long liveGroupId) throws SystemException {
\r
1529 if (groupPersistence.fetchByLiveGroupId(liveGroupId) != null) {
\r
1538 * Returns <code>true</code> if the user is immediately associated with the
\r
1539 * group, or associated with the group via the user's organizations,
\r
1540 * inherited organizations, or user groups.
\r
1542 * @param userId the primary key of the user
\r
1543 * @param groupId the primary key of the group
\r
1544 * @return <code>true</code> if the user is associated with the group;
\r
1545 * <code>false</code> otherwise
\r
1546 * @throws SystemException if a system exception occurred
\r
1548 public boolean hasUserGroup(long userId, long groupId)
\r
1549 throws SystemException {
\r
1551 return hasUserGroup(userId, groupId, true);
\r
1555 * Returns <code>true</code> if the user is immediately associated with the
\r
1556 * group, or optionally if the user is associated with the group via the
\r
1557 * user's organizations, inherited organizations, or user groups.
\r
1559 * @param userId the primary key of the user
\r
1560 * @param groupId the primary key of the group
\r
1561 * @param inherit whether to include organization groups and user groups to
\r
1562 * which the user belongs in the determination
\r
1563 * @return <code>true</code> if the user is associated with the group;
\r
1564 * <code>false</code> otherwise
\r
1565 * @throws SystemException if a system exception occurred
\r
1567 public boolean hasUserGroup(long userId, long groupId, boolean inherit)
\r
1568 throws SystemException {
\r
1570 if (groupFinder.countByG_U(groupId, userId, inherit) > 0) {
\r
1578 public Group loadFetchGroup(long companyId, String name)
\r
1579 throws SystemException {
\r
1581 return groupPersistence.fetchByC_N(companyId, name);
\r
1584 public Group loadGetGroup(long companyId, String name)
\r
1585 throws PortalException, SystemException {
\r
1587 return groupPersistence.findByC_N(companyId, name);
\r
1590 public List<Group> search(
\r
1591 long companyId, LinkedHashMap<String, Object> params, int start,
\r
1593 throws SystemException {
\r
1595 return groupFinder.findByCompanyId(
\r
1596 companyId, params, start, end, new GroupNameComparator(true));
\r
1600 * Returns a name ordered range of all the groups that match the class name
\r
1601 * IDs, name, and description, optionally including the user's inherited
\r
1602 * organization groups and user groups. System and staged groups are not
\r
1606 * Useful when paginating results. Returns a maximum of <code>end -
\r
1607 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1608 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1609 * refers to the first result in the set. Setting both <code>start</code>
\r
1610 * and <code>end</code> to {@link
\r
1611 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1615 * @param companyId the primary key of the company
\r
1616 * @param classNameIds the class names of entities to include in the search
\r
1617 * (optionally <code>null</code>)
\r
1618 * @param name the group's name (optionally <code>null</code>)
\r
1619 * @param description the group's description (optionally
\r
1620 * <code>null</code>)
\r
1621 * @param params the finder params (optionally <code>null</code>). To
\r
1622 * include a user's organizations, inherited organizations, and user
\r
1623 * groups in the search, add an entry with key
\r
1624 * "usersGroups" mapped to the user's ID and an entry with
\r
1625 * key "inherit" mapped to a non-<code>null</code> object.
\r
1626 * For more information see {@link
\r
1627 * com.liferay.portal.service.persistence.GroupFinder}
\r
1628 * com.liferay.portal.service.persistence.GroupFinder}
\r
1629 * @param start the lower bound of the range of groups to return
\r
1630 * @param end the upper bound of the range of groups to return (not
\r
1632 * @return the matching groups ordered by name
\r
1633 * @throws SystemException if a system exception occurred
\r
1635 public List<Group> search(
\r
1636 long companyId, long[] classNameIds, String name,
\r
1637 String description, LinkedHashMap<String, Object> params, int start,
\r
1639 throws SystemException {
\r
1642 companyId, classNameIds, name, description, params, start, end,
\r
1647 * Returns an ordered range of all the groups that match the class name IDs,
\r
1648 * name, and description, optionally including the user's inherited
\r
1649 * organization groups and user groups. System and staged groups are not
\r
1653 * Useful when paginating results. Returns a maximum of <code>end -
\r
1654 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1655 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1656 * refers to the first result in the set. Setting both <code>start</code>
\r
1657 * and <code>end</code> to {@link
\r
1658 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1662 * @param companyId the primary key of the company
\r
1663 * @param classNameIds the group's class name IDs (optionally
\r
1664 * <code>null</code>)
\r
1665 * @param name the group's name (optionally <code>null</code>)
\r
1666 * @param description the group's description (optionally
\r
1667 * <code>null</code>)
\r
1668 * @param params the finder params (optionally <code>null</code>). To
\r
1669 * include a user's organizations, inherited organizations, and user
\r
1670 * groups in the search, add an entry with key
\r
1671 * "usersGroups" mapped to the user's ID and an entry with
\r
1672 * key "inherit" mapped to a non-<code>null</code> object.
\r
1673 * For more information see {@link
\r
1674 * com.liferay.portal.service.persistence.GroupFinder}
\r
1675 * @param start the lower bound of the range of groups to return
\r
1676 * @param end the upper bound of the range of groups to return (not
\r
1678 * @param obc the comparator to order the groups (optionally
\r
1679 * <code>null</code>)
\r
1680 * @return the matching groups ordered by comparator <code>obc</code>
\r
1681 * @throws SystemException if a system exception occurred
\r
1683 public List<Group> search(
\r
1684 long companyId, long[] classNameIds, String name,
\r
1685 String description, LinkedHashMap<String, Object> params, int start,
\r
1686 int end, OrderByComparator obc)
\r
1687 throws SystemException {
\r
1689 if (obc == null) {
\r
1690 obc = new GroupNameComparator(true);
\r
1693 String realName = getRealName(companyId, name);
\r
1695 return groupFinder.findByC_C_N_D(
\r
1696 companyId, classNameIds, name, realName, description, params, start,
\r
1701 * Returns a name ordered range of all the site groups and organization
\r
1702 * groups that match the name and description, optionally including the
\r
1703 * user's inherited organization groups and user groups. System and staged
\r
1704 * groups are not included.
\r
1707 * Useful when paginating results. Returns a maximum of <code>end -
\r
1708 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1709 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1710 * refers to the first result in the set. Setting both <code>start</code>
\r
1711 * and <code>end</code> to {@link
\r
1712 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1716 * @param companyId the primary key of the company
\r
1717 * @param name the group's name (optionally <code>null</code>)
\r
1718 * @param description the group's description (optionally
\r
1719 * <code>null</code>)
\r
1720 * @param params the finder params (optionally <code>null</code>). To
\r
1721 * include the user's inherited organizations and user groups in the
\r
1722 * search, add entries having "usersGroups" and
\r
1723 * "inherit" as keys mapped to the the user's ID. For more
\r
1724 * information see {@link
\r
1725 * com.liferay.portal.service.persistence.GroupFinder}
\r
1726 * @param start the lower bound of the range of groups to return
\r
1727 * @param end the upper bound of the range of groups to return (not
\r
1729 * @return the matching groups ordered by name
\r
1730 * @throws SystemException if a system exception occurred
\r
1732 public List<Group> search(
\r
1733 long companyId, String name, String description,
\r
1734 LinkedHashMap<String, Object> params, int start, int end)
\r
1735 throws SystemException {
\r
1737 return search(companyId, name, description, params, start, end, null);
\r
1741 * Returns an ordered range of all the site groups and organization groups
\r
1742 * that match the name and description, optionally including the user's
\r
1743 * inherited organization groups and user groups. System and staged groups
\r
1744 * are not included.
\r
1747 * Useful when paginating results. Returns a maximum of <code>end -
\r
1748 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1749 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1750 * refers to the first result in the set. Setting both <code>start</code>
\r
1751 * and <code>end</code> to {@link
\r
1752 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1756 * @param companyId the primary key of the company
\r
1757 * @param name the group's name (optionally <code>null</code>)
\r
1758 * @param description the group's description (optionally
\r
1759 * <code>null</code>)
\r
1760 * @param params the finder params (optionally <code>null</code>). To
\r
1761 * include the user's inherited organizations and user groups in the
\r
1762 * search, add entries having "usersGroups" and
\r
1763 * "inherit" as keys mapped to the the user's ID. For more
\r
1764 * information see {@link
\r
1765 * com.liferay.portal.service.persistence.GroupFinder}
\r
1766 * @param start the lower bound of the range of groups to return
\r
1767 * @param end the upper bound of the range of groups to return (not
\r
1769 * @param obc the comparator to order the groups (optionally
\r
1770 * <code>null</code>)
\r
1771 * @return the matching groups ordered by comparator <code>obc</code>
\r
1772 * @throws SystemException if a system exception occurred
\r
1774 public List<Group> search(
\r
1775 long companyId, String name, String description,
\r
1776 LinkedHashMap<String, Object> params, int start, int end,
\r
1777 OrderByComparator obc)
\r
1778 throws SystemException {
\r
1780 if (obc == null) {
\r
1781 obc = new GroupNameComparator(true);
\r
1784 String realName = getRealName(companyId, name);
\r
1786 return groupFinder.findByC_N_D(
\r
1787 companyId, name, realName, description, params, start, end, obc);
\r
1791 * Returns the number of groups that match the class name IDs, name, and
\r
1792 * description, optionally including the user's inherited organization
\r
1793 * groups and user groups. System and staged groups are not included.
\r
1795 * @param companyId the primary key of the company
\r
1796 * @param classNameIds the class names of entities to include in the search
\r
1797 * (optionally <code>null</code>)
\r
1798 * @param name the group's name (optionally <code>null</code>)
\r
1799 * @param description the group's description (optionally
\r
1800 * <code>null</code>)
\r
1801 * @param params the finder params (optionally <code>null</code>). To
\r
1802 * include the user's inherited organization groups and user groups
\r
1803 * in the search, add entries having "usersGroups" and
\r
1804 * "inherit" as keys mapped to the the user's ID. For more
\r
1805 * information see {@link
\r
1806 * com.liferay.portal.service.persistence.GroupFinder}
\r
1807 * @return the number of matching groups
\r
1808 * @throws SystemException if a system exception occurred
\r
1810 @ThreadLocalCachable
\r
1811 public int searchCount(
\r
1812 long companyId, long[] classNameIds, String name,
\r
1813 String description, LinkedHashMap<String, Object> params)
\r
1814 throws SystemException {
\r
1816 String realName = getRealName(companyId, name);
\r
1818 return groupFinder.countByC_C_N_D(
\r
1819 companyId, classNameIds, name, realName, description, params);
\r
1823 * Returns the number of groups and immediate organization groups that match
\r
1824 * the name and description, optionally including the user's inherited
\r
1825 * organization groups and user groups. System and staged groups are not
\r
1828 * @param companyId the primary key of the company
\r
1829 * @param name the group's name (optionally <code>null</code>)
\r
1830 * @param description the group's description (optionally
\r
1831 * <code>null</code>)
\r
1832 * @param params the finder params (optionally <code>null</code>). To
\r
1833 * include the user's inherited organization groups and user groups
\r
1834 * in the search, add entries having "usersGroups" and
\r
1835 * "inherit" as keys mapped to the the user's ID. For more
\r
1836 * information see {@link
\r
1837 * com.liferay.portal.service.persistence.GroupFinder}
\r
1838 * @return the number of matching groups
\r
1839 * @throws SystemException if a system exception occurred
\r
1841 @ThreadLocalCachable
\r
1842 public int searchCount(
\r
1843 long companyId, String name, String description,
\r
1844 LinkedHashMap<String, Object> params)
\r
1845 throws SystemException {
\r
1847 String realName = getRealName(companyId, name);
\r
1849 return groupFinder.countByC_N_D(
\r
1850 companyId, name, realName, description, params);
\r
1854 * Sets the groups associated with the role, removing and adding
\r
1855 * associations as necessary.
\r
1857 * @param roleId the primary key of the role
\r
1858 * @param groupIds the primary keys of the groups
\r
1859 * @throws SystemException if a system exception occurred
\r
1861 public void setRoleGroups(long roleId, long[] groupIds)
\r
1862 throws SystemException {
\r
1864 rolePersistence.setGroups(roleId, groupIds);
\r
1866 PermissionCacheUtil.clearCache();
\r
1870 * Removes the groups from the role.
\r
1872 * @param roleId the primary key of the role
\r
1873 * @param groupIds the primary keys of the groups
\r
1874 * @throws SystemException if a system exception occurred
\r
1876 public void unsetRoleGroups(long roleId, long[] groupIds)
\r
1877 throws SystemException {
\r
1879 rolePersistence.removeGroups(roleId, groupIds);
\r
1881 PermissionCacheUtil.clearCache();
\r
1885 * Removes the user from the groups.
\r
1887 * @param userId the primary key of the user
\r
1888 * @param groupIds the primary keys of the groups
\r
1889 * @throws SystemException if a system exception occurred
\r
1891 public void unsetUserGroups(long userId, long[] groupIds)
\r
1892 throws SystemException {
\r
1894 userGroupRoleLocalService.deleteUserGroupRoles(userId, groupIds);
\r
1896 userPersistence.removeGroups(userId, groupIds);
\r
1898 PermissionCacheUtil.clearCache();
\r
1902 * Updates the group's asset replacing categories and tag names.
\r
1904 * @param userId the primary key of the user
\r
1905 * @param group the group
\r
1906 * @param assetCategoryIds the primary keys of the asset categories
\r
1907 * (optionally <code>null</code>)
\r
1908 * @param assetTagNames the asset tag names (optionally <code>null</code>)
\r
1909 * @throws PortalException if a user with the primary key could not be found
\r
1910 * @throws SystemException if a system exception occurred
\r
1912 public void updateAsset(
\r
1913 long userId, Group group, long[] assetCategoryIds,
\r
1914 String[] assetTagNames)
\r
1915 throws PortalException, SystemException {
\r
1917 User user = userPersistence.findByPrimaryKey(userId);
\r
1919 Company company = companyPersistence.findByPrimaryKey(
\r
1920 user.getCompanyId());
\r
1922 Group companyGroup = company.getGroup();
\r
1924 assetEntryLocalService.updateEntry(
\r
1925 userId, companyGroup.getGroupId(), Group.class.getName(),
\r
1926 group.getGroupId(), null, 0, assetCategoryIds, assetTagNames, false,
\r
1927 null, null, null, null, null, group.getDescriptiveName(),
\r
1928 group.getDescription(), null, null, null, 0, 0, null, false);
\r
1932 * Updates the group's friendly URL.
\r
1934 * @param groupId the primary key of the group
\r
1935 * @param friendlyURL the group's new friendlyURL (optionally
\r
1936 * <code>null</code>)
\r
1937 * @return the group
\r
1938 * @throws PortalException if a group with the primary key could not be
\r
1939 * found or if a valid friendly URL could not be created for the
\r
1941 * @throws SystemException if a system exception occurred
\r
1943 public Group updateFriendlyURL(long groupId, String friendlyURL)
\r
1944 throws PortalException, SystemException {
\r
1946 Group group = groupPersistence.findByPrimaryKey(groupId);
\r
1948 if (group.isUser()) {
\r
1949 User user = userPersistence.findByPrimaryKey(group.getClassPK());
\r
1951 friendlyURL = StringPool.SLASH + user.getScreenName();
\r
1953 if (group.getFriendlyURL().equals(friendlyURL)) {
\r
1958 friendlyURL = getFriendlyURL(
\r
1959 group.getCompanyId(), groupId, group.getClassNameId(),
\r
1960 group.getClassPK(), StringPool.BLANK, friendlyURL);
\r
1962 validateFriendlyURL(
\r
1963 group.getCompanyId(), group.getGroupId(), group.getClassNameId(),
\r
1964 group.getClassPK(), friendlyURL);
\r
1966 group.setFriendlyURL(friendlyURL);
\r
1968 groupPersistence.update(group, false);
\r
1974 * Updates the group's type settings.
\r
1976 * @param groupId the primary key of the group
\r
1977 * @param typeSettings the group's new type settings (optionally
\r
1978 * <code>null</code>)
\r
1979 * @return the group
\r
1980 * @throws PortalException if a group with the primary key could not be
\r
1982 * @throws SystemException if a system exception occurred
\r
1984 public Group updateGroup(long groupId, String typeSettings)
\r
1985 throws PortalException, SystemException {
\r
1987 Group group = groupPersistence.findByPrimaryKey(groupId);
\r
1989 group.setTypeSettings(typeSettings);
\r
1991 groupPersistence.update(group, false);
\r
1997 * Updates the group.
\r
1999 * @param groupId the primary key of the group
\r
2000 * @param name the group's new name
\r
2001 * @param description the group's new description (optionally
\r
2002 * <code>null</code>)
\r
2003 * @param type the group's new type. For more information see {@link
\r
2004 * com.liferay.portal.model.GroupConstants}
\r
2005 * @param friendlyURL the group's new friendlyURL (optionally
\r
2006 * <code>null</code>)
\r
2007 * @param active whether the group is active
\r
2008 * @param serviceContext the service context to be applied (optionally
\r
2009 * <code>null</code>). Can set asset category IDs and asset tag
\r
2010 * names for the group.
\r
2011 * @return the group
\r
2012 * @throws PortalException if a group with the primary key could not be
\r
2013 * found or if the friendly URL was invalid or could one not be
\r
2015 * @throws SystemException if a system exception occurred
\r
2017 public Group updateGroup(
\r
2018 long groupId, String name, String description, int type,
\r
2019 String friendlyURL, boolean active, ServiceContext serviceContext)
\r
2020 throws PortalException, SystemException {
\r
2022 Group group = groupPersistence.findByPrimaryKey(groupId);
\r
2024 String className = group.getClassName();
\r
2025 long classNameId = group.getClassNameId();
\r
2026 long classPK = group.getClassPK();
\r
2027 friendlyURL = getFriendlyURL(
\r
2028 group.getCompanyId(), groupId, classNameId, classPK,
\r
2029 StringPool.BLANK, friendlyURL);
\r
2031 if ((classNameId <= 0) || className.equals(Group.class.getName())) {
\r
2033 group.getGroupId(), group.getCompanyId(), name, group.isSite());
\r
2035 else if (className.equals(Organization.class.getName())) {
\r
2036 Organization organization =
\r
2037 organizationPersistence.findByPrimaryKey(classPK);
\r
2039 name = getOrgGroupName(organization.getName());
\r
2041 else if (!GroupConstants.USER_PERSONAL_SITE.equals(name)) {
\r
2042 name = String.valueOf(classPK);
\r
2045 if (PortalUtil.isSystemGroup(group.getName()) &&
\r
2046 !group.getName().equals(name)) {
\r
2048 throw new RequiredGroupException();
\r
2051 validateFriendlyURL(
\r
2052 group.getCompanyId(), group.getGroupId(), group.getClassNameId(),
\r
2053 group.getClassPK(), friendlyURL);
\r
2055 group.setName(name);
\r
2056 group.setDescription(description);
\r
2057 group.setType(type);
\r
2058 group.setFriendlyURL(friendlyURL);
\r
2059 group.setActive(active);
\r
2061 if ((serviceContext != null) && group.isSite()) {
\r
2062 group.setExpandoBridgeAttributes(serviceContext);
\r
2065 groupPersistence.update(group, false);
\r
2069 if ((serviceContext != null) && group.isSite()) {
\r
2073 user = userPersistence.findByPrimaryKey(
\r
2074 group.getCreatorUserId());
\r
2077 catch (NoSuchUserException nsue1) {
\r
2079 user = userPersistence.findByPrimaryKey(
\r
2080 serviceContext.getUserId());
\r
2082 catch (NoSuchUserException nsue2) {
\r
2083 user = userLocalService.getDefaultUser(
\r
2084 group.getCompanyId());
\r
2089 user.getUserId(), group, serviceContext.getAssetCategoryIds(),
\r
2090 serviceContext.getAssetTagNames());
\r
2097 * Associates the group with a main site if the group is an organization.
\r
2099 * @param groupId the primary key of the group
\r
2100 * @param site whether the group is to be associated with a main site
\r
2101 * @return the group
\r
2102 * @throws PortalException if a group with the primary key could not be
\r
2104 * @throws SystemException if a system exception occurred
\r
2106 public Group updateSite(long groupId, boolean site)
\r
2107 throws PortalException, SystemException {
\r
2109 Group group = groupPersistence.findByPrimaryKey(groupId);
\r
2111 if (!group.isOrganization()) {
\r
2115 group.setSite(site);
\r
2117 groupPersistence.update(group, false);
\r
2122 protected void addControlPanelLayouts(Group group)
\r
2123 throws PortalException, SystemException {
\r
2125 long defaultUserId = userLocalService.getDefaultUserId(
\r
2126 group.getCompanyId());
\r
2128 String friendlyURL = getFriendlyURL(
\r
2129 PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL);
\r
2131 ServiceContext serviceContext = new ServiceContext();
\r
2133 layoutLocalService.addLayout(
\r
2134 defaultUserId, group.getGroupId(), true,
\r
2135 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
\r
2136 PropsValues.CONTROL_PANEL_LAYOUT_NAME, StringPool.BLANK,
\r
2137 StringPool.BLANK, LayoutConstants.TYPE_CONTROL_PANEL, false,
\r
2138 friendlyURL, serviceContext);
\r
2141 protected void addDefaultGuestPublicLayoutByProperties(Group group)
\r
2142 throws PortalException, SystemException {
\r
2144 long defaultUserId = userLocalService.getDefaultUserId(
\r
2145 group.getCompanyId());
\r
2146 String friendlyURL = getFriendlyURL(
\r
2147 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_FRIENDLY_URL);
\r
2149 ServiceContext serviceContext = new ServiceContext();
\r
2151 Layout layout = layoutLocalService.addLayout(
\r
2152 defaultUserId, group.getGroupId(), false,
\r
2153 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
\r
2154 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_NAME, StringPool.BLANK,
\r
2155 StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, friendlyURL,
\r
2158 LayoutTypePortlet layoutTypePortlet =
\r
2159 (LayoutTypePortlet)layout.getLayoutType();
\r
2161 layoutTypePortlet.setLayoutTemplateId(
\r
2162 0, PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_TEMPLATE_ID, false);
\r
2164 for (int i = 0; i < 10; i++) {
\r
2165 String columnId = "column-" + i;
\r
2166 String portletIds = PropsUtil.get(
\r
2167 PropsKeys.DEFAULT_GUEST_PUBLIC_LAYOUT_COLUMN + i);
\r
2169 layoutTypePortlet.addPortletIds(
\r
2170 0, StringUtil.split(portletIds), columnId, false);
\r
2173 layoutLocalService.updateLayout(
\r
2174 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
\r
2175 layout.getTypeSettings());
\r
2177 boolean updateLayoutSet = false;
\r
2179 LayoutSet layoutSet = layout.getLayoutSet();
\r
2181 if (Validator.isNotNull(
\r
2182 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_THEME_ID)) {
\r
2184 layoutSet.setThemeId(
\r
2185 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_THEME_ID);
\r
2187 updateLayoutSet = true;
\r
2190 if (Validator.isNotNull(
\r
2192 DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID)) {
\r
2194 layoutSet.setColorSchemeId(
\r
2196 DEFAULT_GUEST_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID);
\r
2198 updateLayoutSet = true;
\r
2201 if (Validator.isNotNull(
\r
2202 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_THEME_ID)) {
\r
2204 layoutSet.setWapThemeId(
\r
2205 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_THEME_ID);
\r
2207 updateLayoutSet = true;
\r
2210 if (Validator.isNotNull(
\r
2211 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID)) {
\r
2213 layoutSet.setWapColorSchemeId(
\r
2214 PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID);
\r
2216 updateLayoutSet = true;
\r
2219 if (updateLayoutSet) {
\r
2220 layoutSetLocalService.updateLayoutSet(layoutSet);
\r
2224 protected void addDefaultGuestPublicLayouts(Group group)
\r
2225 throws PortalException, SystemException {
\r
2227 if (publicLARFile != null) {
\r
2228 addDefaultGuestPublicLayoutsByLAR(group, publicLARFile);
\r
2231 addDefaultGuestPublicLayoutByProperties(group);
\r
2235 protected void addDefaultGuestPublicLayoutsByLAR(Group group, File larFile)
\r
2236 throws PortalException, SystemException {
\r
2238 long defaultUserId = userLocalService.getDefaultUserId(
\r
2239 group.getCompanyId());
\r
2241 Map<String, String[]> parameterMap = new HashMap<String, String[]>();
\r
2244 PortletDataHandlerKeys.CATEGORIES,
\r
2245 new String[] {Boolean.TRUE.toString()});
\r
2247 PortletDataHandlerKeys.PERMISSIONS,
\r
2248 new String[] {Boolean.TRUE.toString()});
\r
2250 PortletDataHandlerKeys.PORTLET_DATA,
\r
2251 new String[] {Boolean.TRUE.toString()});
\r
2253 PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,
\r
2254 new String[] {Boolean.TRUE.toString()});
\r
2256 PortletDataHandlerKeys.PORTLET_SETUP,
\r
2257 new String[] {Boolean.TRUE.toString()});
\r
2259 PortletDataHandlerKeys.USER_PERMISSIONS,
\r
2260 new String[] {Boolean.FALSE.toString()});
\r
2262 layoutLocalService.importLayouts(
\r
2263 defaultUserId, group.getGroupId(), false, parameterMap, larFile);
\r
2266 protected String getFriendlyURL(
\r
2267 long companyId, long groupId, long classNameId, long classPK,
\r
2268 String friendlyName, String friendlyURL)
\r
2269 throws PortalException, SystemException {
\r
2271 friendlyURL = getFriendlyURL(friendlyURL);
\r
2273 if (Validator.isNotNull(friendlyURL)) {
\r
2274 return friendlyURL;
\r
2277 friendlyURL = StringPool.SLASH + getFriendlyURL(friendlyName);
\r
2279 String originalFriendlyURL = friendlyURL;
\r
2281 for (int i = 1;; i++) {
\r
2283 validateFriendlyURL(
\r
2284 companyId, groupId, classNameId, classPK, friendlyURL);
\r
2288 catch (GroupFriendlyURLException gfurle) {
\r
2289 int type = gfurle.getType();
\r
2291 if (type == GroupFriendlyURLException.DUPLICATE) {
\r
2292 friendlyURL = originalFriendlyURL + i;
\r
2295 friendlyURL = StringPool.SLASH + classPK;
\r
2302 return friendlyURL;
\r
2305 protected String getFriendlyURL(String friendlyURL) {
\r
2306 return FriendlyURLNormalizerUtil.normalize(friendlyURL);
\r
2309 protected String getOrgGroupName(String name) {
\r
2310 return name + ORGANIZATION_NAME_SUFFIX;
\r
2313 protected String getRealName(long companyId, String name)
\r
2314 throws SystemException {
\r
2316 if (Validator.isNull(name)) {
\r
2320 String realName = name;
\r
2323 Company company = companyLocalService.getCompany(companyId);
\r
2325 Account account = company.getAccount();
\r
2327 String companyName = account.getName();
\r
2329 name = StringUtil.replace(
\r
2330 name, StringPool.PERCENT, StringPool.BLANK);
\r
2332 if (companyName.indexOf(name) != -1) {
\r
2334 StringPool.PERCENT + GroupConstants.GUEST +
\r
2335 StringPool.PERCENT;
\r
2338 catch (PortalException pe) {
\r
2344 protected void initImportLARFile() {
\r
2345 String publicLARFileName = PropsValues.DEFAULT_GUEST_PUBLIC_LAYOUTS_LAR;
\r
2347 if (_log.isDebugEnabled()) {
\r
2348 _log.debug("Reading public LAR file " + publicLARFileName);
\r
2351 if (Validator.isNotNull(publicLARFileName)) {
\r
2352 publicLARFile = new File(publicLARFileName);
\r
2354 if (!publicLARFile.exists()) {
\r
2356 "Public LAR file " + publicLARFile + " does not exist");
\r
2358 publicLARFile = null;
\r
2361 if (_log.isDebugEnabled()) {
\r
2362 _log.debug("Using public LAR file " + publicLARFileName);
\r
2368 protected void initUserPersonalSitePermissions(Group group)
\r
2369 throws PortalException, SystemException {
\r
2373 Role role = roleLocalService.getRole(
\r
2374 group.getCompanyId(), RoleConstants.USER);
\r
2376 setCompanyPermissions(
\r
2377 role, PortletKeys.PORTAL,
\r
2378 new String[] {ActionKeys.VIEW_CONTROL_PANEL});
\r
2380 List<Portlet> portlets = portletLocalService.getPortlets(
\r
2381 group.getCompanyId(), false, false);
\r
2383 for (Portlet portlet : portlets) {
\r
2384 setRolePermissions(
\r
2385 group, role, portlet.getPortletId(),
\r
2386 new String[] {ActionKeys.VIEW});
\r
2389 setRolePermissions(
\r
2390 group, role, Layout.class.getName(),
\r
2391 new String[] {ActionKeys.VIEW});
\r
2393 setRolePermissions(
\r
2394 group, role, "com.liferay.portlet.blogs",
\r
2396 ActionKeys.ADD_ENTRY, ActionKeys.PERMISSIONS,
\r
2397 ActionKeys.SUBSCRIBE});
\r
2399 setRolePermissions(
\r
2400 group, role, "com.liferay.portlet.calendar",
\r
2402 ActionKeys.ADD_EVENT, ActionKeys.EXPORT_ALL_EVENTS,
\r
2403 ActionKeys.PERMISSIONS});
\r
2405 // Power User role
\r
2407 role = roleLocalService.getRole(
\r
2408 group.getCompanyId(), RoleConstants.POWER_USER);
\r
2410 for (Portlet portlet : portlets) {
\r
2411 List<String> actions =
\r
2412 ResourceActionsUtil.getPortletResourceActions(
\r
2413 portlet.getPortletId());
\r
2415 String controlPanelEntryCategory = GetterUtil.getString(
\r
2416 portlet.getControlPanelEntryCategory());
\r
2418 if (actions.contains(ActionKeys.ACCESS_IN_CONTROL_PANEL) &&
\r
2419 controlPanelEntryCategory.equals(PortletCategoryKeys.CONTENT)) {
\r
2421 setRolePermissions(
\r
2422 group, role, portlet.getPortletId(),
\r
2423 new String[] {ActionKeys.ACCESS_IN_CONTROL_PANEL});
\r
2427 setRolePermissions(
\r
2428 group, role, Group.class.getName(),
\r
2429 new String[] {ActionKeys.MANAGE_LAYOUTS});
\r
2431 setRolePermissions(group, role, "com.liferay.portlet.asset");
\r
2432 setRolePermissions(group, role, "com.liferay.portlet.blogs");
\r
2433 setRolePermissions(group, role, "com.liferay.portlet.bookmarks");
\r
2434 setRolePermissions(group, role, "com.liferay.portlet.calendar");
\r
2435 setRolePermissions(group, role, "com.liferay.portlet.documentlibrary");
\r
2436 setRolePermissions(group, role, "com.liferay.portlet.imagegallery");
\r
2437 setRolePermissions(group, role, "com.liferay.portlet.messageboards");
\r
2438 setRolePermissions(group, role, "com.liferay.portlet.polls");
\r
2439 setRolePermissions(group, role, "com.liferay.portlet.wiki");
\r
2442 protected boolean isStaging(ServiceContext serviceContext) {
\r
2443 if (serviceContext != null) {
\r
2444 return ParamUtil.getBoolean(serviceContext, "staging");
\r
2450 protected void setCompanyPermissions(
\r
2451 Role role, String name, String[] actionIds)
\r
2452 throws PortalException, SystemException {
\r
2454 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
\r
2455 if (resourceBlockLocalService.isSupported(name)) {
\r
2456 resourceBlockLocalService.setCompanyScopePermissions(
\r
2457 role.getCompanyId(), name, role.getRoleId(),
\r
2458 Arrays.asList(actionIds));
\r
2461 resourcePermissionLocalService.setResourcePermissions(
\r
2462 role.getCompanyId(), name, ResourceConstants.SCOPE_COMPANY,
\r
2463 String.valueOf(role.getCompanyId()), role.getRoleId(),
\r
2468 permissionLocalService.setRolePermissions(
\r
2469 role.getRoleId(), role.getCompanyId(), name,
\r
2470 ResourceConstants.SCOPE_COMPANY,
\r
2471 String.valueOf(role.getCompanyId()), actionIds);
\r
2475 protected void setRolePermissions(Group group, Role role, String name)
\r
2476 throws PortalException, SystemException {
\r
2478 List<String> actions = ResourceActionsUtil.getModelResourceActions(
\r
2481 setRolePermissions(
\r
2482 group, role, name, actions.toArray(new String[actions.size()]));
\r
2485 protected void setRolePermissions(
\r
2486 Group group, Role role, String name, String[] actionIds)
\r
2487 throws PortalException, SystemException {
\r
2489 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
\r
2490 if (resourceBlockLocalService.isSupported(name)) {
\r
2491 resourceBlockLocalService.setGroupScopePermissions(
\r
2492 role.getCompanyId(), group.getGroupId(), name,
\r
2493 role.getRoleId(), Arrays.asList(actionIds));
\r
2496 resourcePermissionLocalService.setResourcePermissions(
\r
2497 group.getCompanyId(), name, ResourceConstants.SCOPE_GROUP,
\r
2498 String.valueOf(group.getGroupId()), role.getRoleId(),
\r
2503 permissionLocalService.setRolePermissions(
\r
2504 role.getRoleId(), group.getCompanyId(), name,
\r
2505 ResourceConstants.SCOPE_GROUP,
\r
2506 String.valueOf(group.getGroupId()), actionIds);
\r
2510 protected void unscheduleStaging(Group group) {
\r
2513 // Remote publishing
\r
2515 String groupName = StagingUtil.getSchedulerGroupName(
\r
2516 DestinationNames.LAYOUTS_REMOTE_PUBLISHER, group.getGroupId());
\r
2518 SchedulerEngineUtil.delete(groupName, StorageType.PERSISTED);
\r
2520 long liveGroupId = 0;
\r
2521 long stagingGroupId = 0;
\r
2523 if (group.isStagingGroup()) {
\r
2524 liveGroupId = group.getLiveGroupId();
\r
2526 stagingGroupId = group.getGroupId();
\r
2528 else if (group.hasStagingGroup()) {
\r
2529 liveGroupId = group.getGroupId();
\r
2531 stagingGroupId = group.getStagingGroup().getGroupId();
\r
2534 if ((liveGroupId != 0) && (stagingGroupId != 0)) {
\r
2536 // Publish to live
\r
2538 groupName = StagingUtil.getSchedulerGroupName(
\r
2539 DestinationNames.LAYOUTS_LOCAL_PUBLISHER, liveGroupId);
\r
2541 SchedulerEngineUtil.delete(groupName, StorageType.PERSISTED);
\r
2545 groupName = StagingUtil.getSchedulerGroupName(
\r
2546 DestinationNames.LAYOUTS_LOCAL_PUBLISHER, stagingGroupId);
\r
2548 SchedulerEngineUtil.delete(groupName, StorageType.PERSISTED);
\r
2551 catch (Exception e) {
\r
2553 "Unable to unschedule events for group: " + group.getGroupId());
\r
2557 protected void validateFriendlyURL(
\r
2558 long companyId, long groupId, long classNameId, long classPK,
\r
2559 String friendlyURL)
\r
2560 throws PortalException, SystemException {
\r
2562 Company company = companyPersistence.findByPrimaryKey(companyId);
\r
2564 if (company.isSystem()) {
\r
2568 if (Validator.isNull(friendlyURL)) {
\r
2572 int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);
\r
2574 if (exceptionType != -1) {
\r
2575 throw new GroupFriendlyURLException(exceptionType);
\r
2578 Group group = groupPersistence.fetchByC_F(companyId, friendlyURL);
\r
2580 if ((group != null) && (group.getGroupId() != groupId)) {
\r
2581 throw new GroupFriendlyURLException(
\r
2582 GroupFriendlyURLException.DUPLICATE);
\r
2585 String groupIdFriendlyURL = friendlyURL.substring(1);
\r
2587 if (Validator.isNumber(groupIdFriendlyURL)) {
\r
2588 long groupClassNameId = PortalUtil.getClassNameId(Group.class);
\r
2590 if (((classNameId != groupClassNameId) &&
\r
2591 !groupIdFriendlyURL.equals(String.valueOf(classPK)) &&
\r
2592 !PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) ||
\r
2593 ((classNameId == groupClassNameId) &&
\r
2594 !groupIdFriendlyURL.equals(String.valueOf(groupId)))) {
\r
2596 GroupFriendlyURLException gfurle =
\r
2597 new GroupFriendlyURLException(
\r
2598 GroupFriendlyURLException.POSSIBLE_DUPLICATE);
\r
2600 gfurle.setKeywordConflict(groupIdFriendlyURL);
\r
2606 String screenName = friendlyURL.substring(1);
\r
2608 User user = userPersistence.fetchByC_SN(companyId, screenName);
\r
2610 if (user != null) {
\r
2611 long userClassNameId = PortalUtil.getClassNameId(User.class);
\r
2613 if ((classNameId == userClassNameId) &&
\r
2614 (classPK == user.getUserId())) {
\r
2617 throw new GroupFriendlyURLException(
\r
2618 GroupFriendlyURLException.DUPLICATE);
\r
2622 if (StringUtil.count(friendlyURL, StringPool.SLASH) > 1) {
\r
2623 throw new GroupFriendlyURLException(
\r
2624 GroupFriendlyURLException.TOO_DEEP);
\r
2628 protected void validateName(
\r
2629 long groupId, long companyId, String name, boolean site)
\r
2630 throws PortalException, SystemException {
\r
2632 if (Validator.isNull(name) || Validator.isNumber(name) ||
\r
2633 name.contains(StringPool.STAR) ||
\r
2634 name.contains(ORGANIZATION_NAME_SUFFIX)) {
\r
2636 throw new GroupNameException();
\r
2640 Group group = groupFinder.findByC_N(companyId, name);
\r
2642 if ((groupId <= 0) || (group.getGroupId() != groupId)) {
\r
2643 throw new DuplicateGroupException();
\r
2646 catch (NoSuchGroupException nsge) {
\r
2650 Company company = companyLocalService.getCompany(companyId);
\r
2652 if (name.equals(company.getName())) {
\r
2653 throw new DuplicateGroupException();
\r
2660 * Retourne les 10 premiers groupes ayant des tags communs avec un utilisateur
\r
2661 * La liste est triee dans l'ordre decroissant du nombre de tags en commun puis
\r
2662 * dans l'ordre alphabetique du nom de groupe
\r
2664 * @param companyId the primary key of the company
\r
2665 * @param classNameIds the group's class name IDs (optionally
\r
2666 * <code>null</code>)
\r
2667 * @param liste de criteres.
\r
2668 * criteres userId : identifiant de l'utilisateur
\r
2669 * @param start the lower bound of the range of groups to return
\r
2670 * @param end the upper bound of the range of groups to return (not
\r
2672 * @return the matching groups
\r
2673 * @throws SystemException if a system exception occurred
\r
2676 public List<Group> search(
\r
2677 long companyId, long[] classNameIds,
\r
2678 LinkedHashMap<String, Object> params, int start,
\r
2680 throws SystemException {
\r
2682 return groupFinder.findByUserTags(
\r
2683 companyId, classNameIds, params, start,
\r
2688 * Retourne le nombre de groupes ayant des tags communs avec un utilisateur
\r
2690 * @param companyId the primary key of the company
\r
2691 * @param classNameIds the group's class name IDs (optionally
\r
2692 * <code>null</code>)
\r
2693 * @param liste de criteres.
\r
2694 * criteres userId : identifiant de l'utilisateur
\r
2695 * @return le nombre de groupes ayant des tags communs avec un utilisateur
\r
2696 * @throws SystemException if a system exception occurred
\r
2698 @ThreadLocalCachable
\r
2699 public int searchCount(
\r
2700 long companyId, long[] classNameIds,LinkedHashMap<String, Object> params)
\r
2701 throws SystemException {
\r
2702 return groupFinder.countByUserTags(
\r
2703 companyId, classNameIds, params);
\r
2707 * Retourne les identifiants de tags attaches a un utilisateurs
\r
2709 * @param userId l'identifiant de l'utilisater
\r
2710 * @return les identifiants des tags attaches a l'utilisateur
\r
2711 * @throws SystemException if a system exception occurred
\r
2713 public List<Long> findUserTags(long userId) throws SystemException {
\r
2714 return groupFinder.findUserTags(userId);
\r
2719 protected File publicLARFile;
\r
2721 private static Log _log = LogFactoryUtil.getLog(
\r
2722 GroupLocalServiceImpl.class);
\r
2724 private Map<String, Group> _systemGroupsMap = new HashMap<String, Group>();
\r