Example usage for com.liferay.portal.kernel.service UserGroupRoleLocalServiceUtil hasUserGroupRole

List of usage examples for com.liferay.portal.kernel.service UserGroupRoleLocalServiceUtil hasUserGroupRole

Introduction

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

Prototype

public static boolean hasUserGroupRole(long userId, long groupId, String roleName, boolean inherit)
            throws com.liferay.portal.kernel.exception.PortalException 

Source Link

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. jav  a  2s .  c  o  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;
}