Example usage for com.liferay.portal.kernel.service RoleLocalServiceUtil hasUserRole

List of usage examples for com.liferay.portal.kernel.service RoleLocalServiceUtil hasUserRole

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service RoleLocalServiceUtil hasUserRole.

Prototype

public static boolean hasUserRole(long userId, long companyId, String name, boolean inherited)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns true if the user is associated with the named regular role.

Usage

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;
        }/*from   w w  w .ja  v a  2  s.c om*/
    } 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;
}