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