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