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