Example usage for com.liferay.portal.kernel.model User getUserGroups

List of usage examples for com.liferay.portal.kernel.model User getUserGroups

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model User getUserGroups.

Prototype

public java.util.List<UserGroup> getUserGroups();

Source Link

Usage

From source file:com.liferay.osb.scv.connector.internal.model.SCVUserGroup.java

License:Open Source License

@Override
public List<UserGroup> getModels(User user) throws Exception {
    return user.getUserGroups();
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java

License:Open Source License

public List<UserGroupRole> checkUserGroupRoles(long userId, List<UserGroupRole> userGroupRoles)
        throws PortalException {

    List<UserGroupRole> oldUserGroupRoles = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any user group roles that the administrator does not
        // have the rights to remove or that have a mandatory membership
        User user = UserLocalServiceUtil.getUser(userId);
        List<UserGroup> userGroups = user.getUserGroups();

        for (UserGroup userGroup : userGroups) {
            List<UserGroupRole> roles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId,
                    userGroup.getUserGroupId());
            oldUserGroupRoles.addAll(roles);
        }//from www . j a v  a 2s. c o  m

        for (UserGroupRole oldUserGroupRole : oldUserGroupRoles) {
            Role role = oldUserGroupRole.getRole();
            Group group = oldUserGroupRole.getGroup();

            if (userGroupRoles.contains(oldUserGroupRole)) {
                continue;
            }

            if (role.getType() == RoleConstants.TYPE_ORGANIZATION) {
                Organization organization = OrganizationLocalServiceUtil
                        .getOrganization(group.getOrganizationId());

                if (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role)
                        || OrganizationMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId,
                                organization.getOrganizationId(), role.getRoleId())
                        || OrganizationMembershipPolicyUtil.isRoleRequired(userId,
                                organization.getOrganizationId(), role.getRoleId())) {

                    userGroupRoles.add(oldUserGroupRole);
                }
            } else if (role.getType() == RoleConstants.TYPE_SITE) {
                if (!userGroupRoles.contains(oldUserGroupRole)
                        && (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role)
                                || SiteMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId,
                                        group.getGroupId(), role.getRoleId())
                                || SiteMembershipPolicyUtil.isRoleRequired(userId, group.getGroupId(),
                                        role.getRoleId()))) {

                    userGroupRoles.add(oldUserGroupRole);
                }
            }
        }
    }

    // Check that the administrator has the permission to add a new user
    // group role and that the user group role membership is allowed

    for (UserGroupRole userGroupRole : userGroupRoles) {
        if ((oldUserGroupRoles == null) || !oldUserGroupRoles.contains(userGroupRole)) {

            UserGroupRolePermissionUtil.check(permissionChecker, userGroupRole.getGroupId(),
                    userGroupRole.getRoleId());
        }
    }

    return userGroupRoles;
}