use of com.liferay.portal.model.Account in project liferay-ide by liferay.
the class UserLocalServiceImpl method addDefaultGroups.
/**
* Adds the user to the default groups, unless the user is already in these
* groups. The default groups can be specified in
* <code>portal.properties</code> with the key
* <code>admin.default.group.names</code>.
*
* @param userId the primary key of the user
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public void addDefaultGroups(long userId) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
Set<Long> groupIdsSet = new HashSet<Long>();
String[] defaultGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_GROUP_NAMES);
for (String defaultGroupName : defaultGroupNames) {
Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
Account account = company.getAccount();
if (StringUtil.equalsIgnoreCase(defaultGroupName, account.getName())) {
defaultGroupName = GroupConstants.GUEST;
}
Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultGroupName);
if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
groupIdsSet.add(group.getGroupId());
}
}
String[] defaultOrganizationGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES);
for (String defaultOrganizationGroupName : defaultOrganizationGroupNames) {
defaultOrganizationGroupName += GroupLocalServiceImpl.ORGANIZATION_NAME_SUFFIX;
Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultOrganizationGroupName);
if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
groupIdsSet.add(group.getGroupId());
}
}
long[] groupIds = ArrayUtil.toArray(groupIdsSet.toArray(new Long[groupIdsSet.size()]));
groupLocalService.addUserGroups(userId, groupIds);
}