001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.DuplicateUserGroupException;
018    import com.liferay.portal.NoSuchUserGroupException;
019    import com.liferay.portal.RequiredUserGroupException;
020    import com.liferay.portal.UserGroupNameException;
021    import com.liferay.portal.kernel.exception.PortalException;
022    import com.liferay.portal.kernel.exception.SystemException;
023    import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
024    import com.liferay.portal.kernel.lar.UserIdStrategy;
025    import com.liferay.portal.kernel.search.Indexer;
026    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
027    import com.liferay.portal.kernel.util.CharPool;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.Validator;
030    import com.liferay.portal.kernel.workflow.WorkflowConstants;
031    import com.liferay.portal.model.Group;
032    import com.liferay.portal.model.GroupConstants;
033    import com.liferay.portal.model.ResourceConstants;
034    import com.liferay.portal.model.Team;
035    import com.liferay.portal.model.User;
036    import com.liferay.portal.model.UserGroup;
037    import com.liferay.portal.model.UserGroupConstants;
038    import com.liferay.portal.security.ldap.LDAPUserGroupTransactionThreadLocal;
039    import com.liferay.portal.security.permission.PermissionCacheUtil;
040    import com.liferay.portal.service.base.UserGroupLocalServiceBaseImpl;
041    import com.liferay.portal.util.PropsValues;
042    
043    import java.io.File;
044    
045    import java.util.ArrayList;
046    import java.util.LinkedHashMap;
047    import java.util.List;
048    import java.util.Map;
049    
050    /**
051     * The implementation of the user group local service.
052     *
053     * @author Charles May
054     */
055    public class UserGroupLocalServiceImpl extends UserGroupLocalServiceBaseImpl {
056    
057            /**
058             * Adds the user groups to the group.
059             *
060             * @param  groupId the primary key of the group
061             * @param  userGroupIds the primary keys of the user groups
062             * @throws SystemException if a system exception occurred
063             */
064            public void addGroupUserGroups(long groupId, long[] userGroupIds)
065                    throws SystemException {
066    
067                    groupPersistence.addUserGroups(groupId, userGroupIds);
068    
069                    PermissionCacheUtil.clearCache();
070            }
071    
072            /**
073             * Adds the user groups to the team.
074             *
075             * @param  teamId the primary key of the team
076             * @param  userGroupIds the primary keys of the user groups
077             * @throws SystemException if a system exception occurred
078             */
079            public void addTeamUserGroups(long teamId, long[] userGroupIds)
080                    throws SystemException {
081    
082                    teamPersistence.addUserGroups(teamId, userGroupIds);
083    
084                    PermissionCacheUtil.clearCache();
085            }
086    
087            /**
088             * Adds a user group.
089             *
090             * <p>
091             * This method handles the creation and bookkeeping of the user group,
092             * including its resources, metadata, and internal data structures. It is
093             * not necessary to make subsequent calls to setup default groups and
094             * resources for the user group.
095             * </p>
096             *
097             * @param  userId the primary key of the user
098             * @param  companyId the primary key of the user group's company
099             * @param  name the user group's name
100             * @param  description the user group's description
101             * @return the user group
102             * @throws PortalException if the user group's information was invalid
103             * @throws SystemException if a system exception occurred
104             */
105            public UserGroup addUserGroup(
106                            long userId, long companyId, String name, String description)
107                    throws PortalException, SystemException {
108    
109                    // User Group
110    
111                    validate(0, companyId, name);
112    
113                    long userGroupId = counterLocalService.increment();
114    
115                    UserGroup userGroup = userGroupPersistence.create(userGroupId);
116    
117                    userGroup.setCompanyId(companyId);
118                    userGroup.setParentUserGroupId(
119                            UserGroupConstants.DEFAULT_PARENT_USER_GROUP_ID);
120                    userGroup.setName(name);
121                    userGroup.setDescription(description);
122                    userGroup.setAddedByLDAPImport(
123                            LDAPUserGroupTransactionThreadLocal.isOriginatesFromLDAP());
124    
125                    userGroupPersistence.update(userGroup);
126    
127                    // Group
128    
129                    groupLocalService.addGroup(
130                            userId, GroupConstants.DEFAULT_PARENT_GROUP_ID,
131                            UserGroup.class.getName(), userGroup.getUserGroupId(),
132                            GroupConstants.DEFAULT_LIVE_GROUP_ID, String.valueOf(userGroupId),
133                            null, 0, null, false, true, null);
134    
135                    // Resources
136    
137                    resourceLocalService.addResources(
138                            companyId, 0, userId, UserGroup.class.getName(),
139                            userGroup.getUserGroupId(), false, false, false);
140    
141                    return userGroup;
142            }
143    
144            /**
145             * Clears all associations between the user and its user groups and clears
146             * the permissions cache.
147             *
148             * <p>
149             * This method is called from {@link #deleteUserGroup(UserGroup)}.
150             * </p>
151             *
152             * @param  userId the primary key of the user
153             * @throws SystemException if a system exception occurred
154             */
155            public void clearUserUserGroups(long userId) throws SystemException {
156                    userPersistence.clearUserGroups(userId);
157    
158                    PermissionCacheUtil.clearCache();
159            }
160    
161            /**
162             * Copies the user group's layouts to the users who are not already members
163             * of the user group.
164             *
165             * @param      userGroupId the primary key of the user group
166             * @param      userIds the primary keys of the users
167             * @throws     PortalException if any one of the users could not be found or
168             *             if a portal exception occurred
169             * @throws     SystemException if a system exception occurred
170             * @deprecated
171             */
172            public void copyUserGroupLayouts(long userGroupId, long userIds[])
173                    throws PortalException, SystemException {
174    
175                    Map<String, String[]> parameterMap = getLayoutTemplatesParameters();
176    
177                    File[] files = exportLayouts(userGroupId, parameterMap);
178    
179                    try {
180                            for (long userId : userIds) {
181                                    if (!userGroupPersistence.containsUser(userGroupId, userId)) {
182                                            importLayouts(userId, parameterMap, files[0], files[1]);
183                                    }
184                            }
185                    }
186                    finally {
187                            if (files[0] != null) {
188                                    files[0].delete();
189                            }
190    
191                            if (files[1] != null) {
192                                    files[1].delete();
193                            }
194                    }
195            }
196    
197            /**
198             * Copies the user groups' layouts to the user.
199             *
200             * @param      userGroupIds the primary keys of the user groups
201             * @param      userId the primary key of the user
202             * @throws     PortalException if a user with the primary key could not be
203             *             found or if a portal exception occurred
204             * @throws     SystemException if a system exception occurred
205             * @deprecated
206             */
207            public void copyUserGroupLayouts(long userGroupIds[], long userId)
208                    throws PortalException, SystemException {
209    
210                    for (long userGroupId : userGroupIds) {
211                            if (!userGroupPersistence.containsUser(userGroupId, userId)) {
212                                    copyUserGroupLayouts(userGroupId, userId);
213                            }
214                    }
215            }
216    
217            /**
218             * Copies the user group's layout to the user.
219             *
220             * @param      userGroupId the primary key of the user group
221             * @param      userId the primary key of the user
222             * @throws     PortalException if a user with the primary key could not be
223             *             found or if a portal exception occurred
224             * @throws     SystemException if a system exception occurred
225             * @deprecated
226             */
227            public void copyUserGroupLayouts(long userGroupId, long userId)
228                    throws PortalException, SystemException {
229    
230                    Map<String, String[]> parameterMap = getLayoutTemplatesParameters();
231    
232                    File[] files = exportLayouts(userGroupId, parameterMap);
233    
234                    try {
235                            importLayouts(userId, parameterMap, files[0], files[1]);
236                    }
237                    finally {
238                            if (files[0] != null) {
239                                    files[0].delete();
240                            }
241    
242                            if (files[1] != null) {
243                                    files[1].delete();
244                            }
245                    }
246            }
247    
248            /**
249             * Deletes the user group.
250             *
251             * @param  userGroupId the primary key of the user group
252             * @return the deleted user group
253             * @throws PortalException if a user group with the primary key could not be
254             *         found or if the user group had a workflow in approved status
255             * @throws SystemException if a system exception occurred
256             */
257            @Override
258            public UserGroup deleteUserGroup(long userGroupId)
259                    throws PortalException, SystemException {
260    
261                    UserGroup userGroup = userGroupPersistence.findByPrimaryKey(
262                            userGroupId);
263    
264                    return deleteUserGroup(userGroup);
265            }
266    
267            /**
268             * Deletes the user group.
269             *
270             * @param  userGroup the user group
271             * @return the deleted user group
272             * @throws PortalException if the organization had a workflow in approved
273             *         status
274             * @throws SystemException if a system exception occurred
275             */
276            @Override
277            public UserGroup deleteUserGroup(UserGroup userGroup)
278                    throws PortalException, SystemException {
279    
280                    int count = userLocalService.getUserGroupUsersCount(
281                            userGroup.getUserGroupId(), WorkflowConstants.STATUS_APPROVED);
282    
283                    if (count > 0) {
284                            throw new RequiredUserGroupException();
285                    }
286    
287                    // Users
288    
289                    clearUserUserGroups(userGroup.getUserGroupId());
290    
291                    // Group
292    
293                    Group group = userGroup.getGroup();
294    
295                    groupLocalService.deleteGroup(group);
296    
297                    // User group roles
298    
299                    userGroupGroupRoleLocalService.deleteUserGroupGroupRolesByUserGroupId(
300                            userGroup.getUserGroupId());
301    
302                    // Resources
303    
304                    resourceLocalService.deleteResource(
305                            userGroup.getCompanyId(), UserGroup.class.getName(),
306                            ResourceConstants.SCOPE_INDIVIDUAL, userGroup.getUserGroupId());
307    
308                    // User group
309    
310                    userGroupPersistence.remove(userGroup);
311    
312                    // Permission cache
313    
314                    PermissionCacheUtil.clearCache();
315    
316                    return userGroup;
317            }
318    
319            /**
320             * Returns the user group with the name.
321             *
322             * @param  companyId the primary key of the user group's company
323             * @param  name the user group's name
324             * @return Returns the user group with the name
325             * @throws PortalException if a user group with the name could not be found
326             * @throws SystemException if a system exception occurred
327             */
328            public UserGroup getUserGroup(long companyId, String name)
329                    throws PortalException, SystemException {
330    
331                    return userGroupPersistence.findByC_N(companyId, name);
332            }
333    
334            /**
335             * Returns all the user groups belonging to the company.
336             *
337             * @param  companyId the primary key of the user groups' company
338             * @return the user groups belonging to the company
339             * @throws SystemException if a system exception occurred
340             */
341            public List<UserGroup> getUserGroups(long companyId)
342                    throws SystemException {
343    
344                    return userGroupPersistence.findByCompanyId(companyId);
345            }
346    
347            /**
348             * Returns all the user groups with the primary keys.
349             *
350             * @param  userGroupIds the primary keys of the user groups
351             * @return the user groups with the primary keys
352             * @throws PortalException if any one of the user groups could not be found
353             * @throws SystemException if a system exception occurred
354             */
355            public List<UserGroup> getUserGroups(long[] userGroupIds)
356                    throws PortalException, SystemException {
357    
358                    List<UserGroup> userGroups = new ArrayList<UserGroup>(
359                            userGroupIds.length);
360    
361                    for (long userGroupId : userGroupIds) {
362                            UserGroup userGroup = getUserGroup(userGroupId);
363    
364                            userGroups.add(userGroup);
365                    }
366    
367                    return userGroups;
368            }
369    
370            /**
371             * Returns all the user groups to which the user belongs.
372             *
373             * @param  userId the primary key of the user
374             * @return the user groups to which the user belongs
375             * @throws SystemException if a system exception occurred
376             */
377            public List<UserGroup> getUserUserGroups(long userId)
378                    throws SystemException {
379    
380                    return userPersistence.getUserGroups(userId);
381            }
382    
383            /**
384             * Returns <code>true</code> if the user group is associated with the group.
385             *
386             * @param  groupId the primary key of the group
387             * @param  userGroupId the primary key of the user group
388             * @return <code>true</code> if the user group belongs to the group;
389             *         <code>false</code> otherwise
390             * @throws SystemException if a system exception occurred
391             */
392            public boolean hasGroupUserGroup(long groupId, long userGroupId)
393                    throws SystemException {
394    
395                    return groupPersistence.containsUserGroup(groupId, userGroupId);
396            }
397    
398            /**
399             * Returns <code>true</code> if the user group belongs to the team.
400             *
401             * @param  teamId the primary key of the team
402             * @param  userGroupId the primary key of the user group
403             * @return <code>true</code> if the user group belongs to the team;
404             *         <code>false</code> otherwise
405             * @throws SystemException if a system exception occurred
406             */
407            public boolean hasTeamUserGroup(long teamId, long userGroupId)
408                    throws SystemException {
409    
410                    return teamPersistence.containsUserGroup(teamId, userGroupId);
411            }
412    
413            /**
414             * Returns an ordered range of all the user groups that match the keywords.
415             *
416             * <p>
417             * Useful when paginating results. Returns a maximum of <code>end -
418             * start</code> instances. <code>start</code> and <code>end</code> are not
419             * primary keys, they are indexes in the result set. Thus, <code>0</code>
420             * refers to the first result in the set. Setting both <code>start</code>
421             * and <code>end</code> to {@link
422             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
423             * result set.
424             * </p>
425             *
426             * @param  companyId the primary key of the user group's company
427             * @param  keywords the keywords (space separated), which may occur in the
428             *         user group's name or description (optionally <code>null</code>)
429             * @param  params the finder params (optionally <code>null</code>). For more
430             *         information see {@link
431             *         com.liferay.portal.service.persistence.UserGroupFinder}
432             * @param  start the lower bound of the range of user groups to return
433             * @param  end the upper bound of the range of user groups to return (not
434             *         inclusive)
435             * @param  obc the comparator to order the user groups (optionally
436             *         <code>null</code>)
437             * @return the matching user groups ordered by comparator <code>obc</code>
438             * @throws SystemException if a system exception occurred
439             * @see    com.liferay.portal.service.persistence.UserGroupFinder
440             */
441            public List<UserGroup> search(
442                            long companyId, String keywords,
443                            LinkedHashMap<String, Object> params, int start, int end,
444                            OrderByComparator obc)
445                    throws SystemException {
446    
447                    return userGroupFinder.findByKeywords(
448                            companyId, keywords, params, start, end, obc);
449            }
450    
451            /**
452             * Returns an ordered range of all the user groups that match the name and
453             * description.
454             *
455             * <p>
456             * Useful when paginating results. Returns a maximum of <code>end -
457             * start</code> instances. <code>start</code> and <code>end</code> are not
458             * primary keys, they are indexes in the result set. Thus, <code>0</code>
459             * refers to the first result in the set. Setting both <code>start</code>
460             * and <code>end</code> to {@link
461             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
462             * result set.
463             * </p>
464             *
465             * @param  companyId the primary key of the user group's company
466             * @param  name the user group's name (optionally <code>null</code>)
467             * @param  description the user group's description (optionally
468             *         <code>null</code>)
469             * @param  params the finder params (optionally <code>null</code>). For more
470             *         information see {@link
471             *         com.liferay.portal.service.persistence.UserGroupFinder}
472             * @param  start the lower bound of the range of user groups to return
473             * @param  end the upper bound of the range of user groups to return (not
474             *         inclusive)
475             * @param  obc the comparator to order the user groups (optionally
476             *         <code>null</code>)
477             * @return the matching user groups ordered by comparator <code>obc</code>
478             * @throws SystemException if a system exception occurred
479             * @see    com.liferay.portal.service.persistence.UserGroupFinder
480             */
481            public List<UserGroup> search(
482                            long companyId, String name, String description,
483                            LinkedHashMap<String, Object> params, int start, int end,
484                            OrderByComparator obc)
485                    throws SystemException {
486    
487                    return userGroupFinder.findByC_N_D(
488                            companyId, name, description, params, false, start, end, obc);
489            }
490    
491            /**
492             * Returns the number of user groups that match the keywords
493             *
494             * @param  companyId the primary key of the user group's company
495             * @param  keywords the keywords (space separated), which may occur in the
496             *         user group's name or description (optionally <code>null</code>)
497             * @param  params the finder params (optionally <code>null</code>). For more
498             *         information see {@link
499             *         com.liferay.portal.service.persistence.UserGroupFinder}
500             * @return the number of matching user groups
501             * @throws SystemException if a system exception occurred
502             * @see    com.liferay.portal.service.persistence.UserGroupFinder
503             */
504            public int searchCount(
505                            long companyId, String keywords,
506                            LinkedHashMap<String, Object> params)
507                    throws SystemException {
508    
509                    return userGroupFinder.countByKeywords(companyId, keywords, params);
510            }
511    
512            /**
513             * Returns the number of user groups that match the name and description.
514             *
515             * @param  companyId the primary key of the user group's company
516             * @param  name the user group's name (optionally <code>null</code>)
517             * @param  description the user group's description (optionally
518             *         <code>null</code>)
519             * @param  params the finder params (optionally <code>null</code>). For more
520             *         information see {@link
521             *         com.liferay.portal.service.persistence.UserGroupFinder}
522             * @return the number of matching user groups
523             * @throws SystemException if a system exception occurred
524             * @see    com.liferay.portal.service.persistence.UserGroupFinder
525             */
526            public int searchCount(
527                            long companyId, String name, String description,
528                            LinkedHashMap<String, Object> params)
529                    throws SystemException {
530    
531                    return userGroupFinder.countByC_N_D(
532                            companyId, name, description, params, false);
533            }
534    
535            /**
536             * Sets the user groups associated with the user copying the user group
537             * layouts and removing and adding user group associations for the user as
538             * necessary.
539             *
540             * @param  userId the primary key of the user
541             * @param  userGroupIds the primary keys of the user groups
542             * @throws PortalException if a portal exception occurred
543             * @throws SystemException if a system exception occurred
544             */
545            public void setUserUserGroups(long userId, long[] userGroupIds)
546                    throws PortalException, SystemException {
547    
548                    copyUserGroupLayouts(userGroupIds, userId);
549    
550                    userPersistence.setUserGroups(userId, userGroupIds);
551    
552                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
553    
554                    indexer.reindex(userId);
555    
556                    PermissionCacheUtil.clearCache();
557            }
558    
559            /**
560             * Removes the user groups from the group.
561             *
562             * @param  groupId the primary key of the group
563             * @param  userGroupIds the primary keys of the user groups
564             * @throws SystemException if a system exception occurred
565             */
566            public void unsetGroupUserGroups(long groupId, long[] userGroupIds)
567                    throws SystemException {
568    
569                    List<Team> teams = teamPersistence.findByGroupId(groupId);
570    
571                    for (Team team : teams) {
572                            teamPersistence.removeUserGroups(team.getTeamId(), userGroupIds);
573                    }
574    
575                    userGroupGroupRoleLocalService.deleteUserGroupGroupRoles(
576                            userGroupIds, groupId);
577    
578                    groupPersistence.removeUserGroups(groupId, userGroupIds);
579    
580                    PermissionCacheUtil.clearCache();
581            }
582    
583            /**
584             * Removes the user groups from the team.
585             *
586             * @param  teamId the primary key of the team
587             * @param  userGroupIds the primary keys of the user groups
588             * @throws SystemException if a system exception occurred
589             */
590            public void unsetTeamUserGroups(long teamId, long[] userGroupIds)
591                    throws SystemException {
592    
593                    teamPersistence.removeUserGroups(teamId, userGroupIds);
594    
595                    PermissionCacheUtil.clearCache();
596            }
597    
598            /**
599             * Updates the user group.
600             *
601             * @param  companyId the primary key of the user group's company
602             * @param  userGroupId the primary key of the user group
603             * @param  name the user group's name
604             * @param  description the user group's description
605             * @return the user group
606             * @throws PortalException if a user group with the primary key could not be
607             *         found or if the new information was invalid
608             * @throws SystemException if a system exception occurred
609             */
610            public UserGroup updateUserGroup(
611                            long companyId, long userGroupId, String name, String description)
612                    throws PortalException, SystemException {
613    
614                    validate(userGroupId, companyId, name);
615    
616                    UserGroup userGroup = userGroupPersistence.findByPrimaryKey(
617                            userGroupId);
618    
619                    userGroup.setName(name);
620                    userGroup.setDescription(description);
621    
622                    userGroupPersistence.update(userGroup);
623    
624                    return userGroup;
625            }
626    
627            protected File[] exportLayouts(
628                            long userGroupId, Map<String, String[]> parameterMap)
629                    throws PortalException, SystemException {
630    
631                    File[] files = new File[2];
632    
633                    UserGroup userGroup = userGroupPersistence.findByPrimaryKey(
634                            userGroupId);
635    
636                    Group group = userGroup.getGroup();
637    
638                    if (userGroup.hasPrivateLayouts()) {
639                            files[0] = layoutLocalService.exportLayoutsAsFile(
640                                    group.getGroupId(), true, null, parameterMap, null, null);
641                    }
642    
643                    if (userGroup.hasPublicLayouts()) {
644                            files[1] = layoutLocalService.exportLayoutsAsFile(
645                                    group.getGroupId(), false, null, parameterMap, null, null);
646                    }
647    
648                    return files;
649            }
650    
651            protected Map<String, String[]> getLayoutTemplatesParameters() {
652                    Map<String, String[]> parameterMap =
653                            new LinkedHashMap<String, String[]>();
654    
655                    parameterMap.put(
656                            PortletDataHandlerKeys.CATEGORIES,
657                            new String[] {Boolean.TRUE.toString()});
658                    parameterMap.put(
659                            PortletDataHandlerKeys.DATA_STRATEGY,
660                            new String[] {PortletDataHandlerKeys.DATA_STRATEGY_MIRROR});
661                    parameterMap.put(
662                            PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,
663                            new String[] {Boolean.FALSE.toString()});
664                    parameterMap.put(
665                            PortletDataHandlerKeys.DELETE_PORTLET_DATA,
666                            new String[] {Boolean.FALSE.toString()});
667                    parameterMap.put(
668                            PortletDataHandlerKeys.LAYOUT_SET_SETTINGS,
669                            new String[] {Boolean.FALSE.toString()});
670                    parameterMap.put(
671                            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE,
672                            new String[] {PortletDataHandlerKeys.
673                                    LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE});
674                    parameterMap.put(
675                            PortletDataHandlerKeys.LOGO,
676                            new String[] {Boolean.FALSE.toString()});
677                    parameterMap.put(
678                            PortletDataHandlerKeys.PERMISSIONS,
679                            new String[] {Boolean.TRUE.toString()});
680                    parameterMap.put(
681                            PortletDataHandlerKeys.PORTLET_DATA,
682                            new String[] {Boolean.TRUE.toString()});
683                    parameterMap.put(
684                            PortletDataHandlerKeys.PORTLET_DATA_ALL,
685                            new String[] {Boolean.TRUE.toString()});
686                    parameterMap.put(
687                            PortletDataHandlerKeys.PORTLET_SETUP,
688                            new String[] {Boolean.TRUE.toString()});
689                    parameterMap.put(
690                            PortletDataHandlerKeys.PORTLET_USER_PREFERENCES,
691                            new String[] {Boolean.TRUE.toString()});
692                    parameterMap.put(
693                            PortletDataHandlerKeys.PORTLETS_MERGE_MODE,
694                            new String[] {PortletDataHandlerKeys.
695                                    PORTLETS_MERGE_MODE_ADD_TO_BOTTOM});
696                    parameterMap.put(
697                            PortletDataHandlerKeys.THEME,
698                            new String[] {Boolean.FALSE.toString()});
699                    parameterMap.put(
700                            PortletDataHandlerKeys.THEME_REFERENCE,
701                            new String[] {Boolean.TRUE.toString()});
702                    parameterMap.put(
703                            PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE,
704                            new String[] {Boolean.FALSE.toString()});
705                    parameterMap.put(
706                            PortletDataHandlerKeys.USER_ID_STRATEGY,
707                            new String[] {UserIdStrategy.CURRENT_USER_ID});
708    
709                    return parameterMap;
710            }
711    
712            protected void importLayouts(
713                            long userId, Map<String, String[]> parameterMap,
714                            File privateLayoutsFile, File publicLayoutsFile)
715                    throws PortalException, SystemException {
716    
717                    User user = userPersistence.findByPrimaryKey(userId);
718    
719                    long groupId = user.getGroup().getGroupId();
720    
721                    if (privateLayoutsFile != null) {
722                            layoutLocalService.importLayouts(
723                                    userId, groupId, true, parameterMap, privateLayoutsFile);
724                    }
725    
726                    if (publicLayoutsFile != null) {
727                            layoutLocalService.importLayouts(
728                                    userId, groupId, false, parameterMap, publicLayoutsFile);
729                    }
730            }
731    
732            protected void validate(long userGroupId, long companyId, String name)
733                    throws PortalException, SystemException {
734    
735                    if (Validator.isNull(name) ||
736                            (name.indexOf(CharPool.COMMA) != -1) ||
737                            (name.indexOf(CharPool.STAR) != -1)) {
738    
739                            throw new UserGroupNameException();
740                    }
741    
742                    if (Validator.isNumber(name) &&
743                            !PropsValues.USER_GROUPS_NAME_ALLOW_NUMERIC) {
744    
745                            throw new UserGroupNameException();
746                    }
747    
748                    try {
749                            UserGroup userGroup = userGroupFinder.findByC_N(companyId, name);
750    
751                            if (userGroup.getUserGroupId() != userGroupId) {
752                                    throw new DuplicateUserGroupException();
753                            }
754                    }
755                    catch (NoSuchUserGroupException nsuge) {
756                    }
757            }
758    
759    }