List of usage examples for com.liferay.portal.kernel.service UserGroupLocalServiceUtil getUserGroup
public static com.liferay.portal.kernel.model.UserGroup getUserGroup(long companyId, String name) throws com.liferay.portal.kernel.exception.PortalException
From source file:com.liferay.message.boards.web.internal.util.MBUserRankUtil.java
License:Open Source License
private static boolean _isEntityRank(long companyId, MBStatsUser statsUser, String entityType, String entityValue) throws Exception { long groupId = statsUser.getGroupId(); long userId = statsUser.getUserId(); if (entityType.equals("organization-role") || entityType.equals("site-role")) { Role role = RoleLocalServiceUtil.getRole(companyId, entityValue); if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(userId, groupId, role.getRoleId(), true)) { return true; }/* w w w .ja v a 2 s . co m*/ } else if (entityType.equals("organization")) { Organization organization = OrganizationLocalServiceUtil.getOrganization(companyId, entityValue); if (OrganizationLocalServiceUtil.hasUserOrganization(userId, organization.getOrganizationId(), false, false)) { return true; } } else if (entityType.equals("regular-role")) { if (RoleLocalServiceUtil.hasUserRole(userId, companyId, entityValue, true)) { return true; } } else if (entityType.equals("user-group")) { UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, entityValue); if (UserLocalServiceUtil.hasUserGroupUser(userGroup.getUserGroupId(), userId)) { return true; } } return false; }
From source file:it.sysdata.base.service.impl.UserHelperLocalServiceImpl.java
License:Open Source License
public User addUserEmail(String emailAddress, String password, String firstName, String lastName, ServiceContext serviceContext) throws PortalException, SystemException { HttpServletRequest httpServletRequest = serviceContext.getRequest(); Locale locale = PortalUtil.getLocale(httpServletRequest); String userAgent = httpServletRequest.getHeader("User-Agent"); _validateUser(emailAddress, password, serviceContext); long companyId = serviceContext.getCompanyId(); long[] groupIds = new long[1]; long[] roleIds = null; long[] userGroupIds = null; long[] organizationIds = null; if (Validator.isNotNull(PortletPropsValues.API_NEWUSER_USERGROUP_MEMBER)) { UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, PortletPropsValues.API_NEWUSER_USERGROUP_MEMBER); userGroupIds = new long[] { userGroup.getUserGroupId() }; }//from ww w .j ava2 s . c o m if (Validator.isNotNull(PortletPropsValues.API_NEWUSER_GROUPNAME_MEMBER)) { Group group = GroupLocalServiceUtil.getGroup(companyId, PortletPropsValues.API_NEWUSER_GROUPNAME_MEMBER); if (group.getGroupId() > 0) { groupIds[0] = group.getGroupId(); } else { groupIds = null; } } // Role role = RoleLocalServiceUtil.getRole(companyId, "roleName"); // if (role.getRoleId() > 0) { // roleIds[0] = role.getRoleId(); // } // else { // roleIds = null; // } User user = UserLocalServiceUtil.addUser(0, companyId, false, password, password, true, null, emailAddress, 0, null, locale, firstName, null, lastName, 0, 0, true, 1, 1, 1970, null, groupIds, organizationIds, roleIds, userGroupIds, PortletPropsValues.API_NEWUSER_SENDEMAIL, serviceContext); _log.info( String.format("addUserEmail %s, %s, %s > %s", emailAddress, password, userAgent, user.getUserId())); return user; }