Example usage for com.liferay.portal.kernel.service UserGroupLocalServiceUtil getUserUserGroups

List of usage examples for com.liferay.portal.kernel.service UserGroupLocalServiceUtil getUserUserGroups

Introduction

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

Prototype

public static java.util.List<com.liferay.portal.kernel.model.UserGroup> getUserUserGroups(long userId) 

Source Link

Usage

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

License:Open Source License

public long[] checkUserGroupIds(long userId, long[] userGroupIds) throws PortalException {

    long[] oldUserGroupIds = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any user groups that the administrator does not have the
        // rights to remove or that have a mandatory membership

        List<UserGroup> oldUserGroups = UserGroupLocalServiceUtil.getUserUserGroups(userId);

        oldUserGroupIds = new long[oldUserGroups.size()];

        for (int i = 0; i < oldUserGroups.size(); i++) {
            UserGroup userGroup = oldUserGroups.get(i);

            if (!ArrayUtil.contains(userGroupIds, userGroup.getUserGroupId()) && (!UserGroupPermissionUtil
                    .contains(permissionChecker, userGroup.getUserGroupId(), ActionKeys.ASSIGN_MEMBERS)
                    || UserGroupMembershipPolicyUtil.isMembershipRequired(userId,
                            userGroup.getUserGroupId()))) {

                userGroupIds = ArrayUtil.append(userGroupIds, userGroup.getUserGroupId());
            }/*from  w w  w .j a v a  2  s . c o m*/

            oldUserGroupIds[i] = userGroup.getUserGroupId();
        }
    }

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

    for (long userGroupId : userGroupIds) {
        if ((oldUserGroupIds == null) || !ArrayUtil.contains(oldUserGroupIds, userGroupId)) {

            UserGroupPermissionUtil.check(permissionChecker, userGroupId, ActionKeys.ASSIGN_MEMBERS);
        }
    }

    return userGroupIds;
}

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

License:Open Source License

@Override
public User getUser(long userId) throws PortalException {

    _log.info("getting user with id: " + String.valueOf(userId));

    _log.debug("    ... security check ...");

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.VIEW);

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    Contact userContact = ContactLocalServiceUtil.getContact(user.getContactId());

    List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
    List<Group> userGroups = GroupLocalServiceUtil.getUserGroups(user.getUserId());
    List<Organization> userOrganizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());
    List<UserGroup> userUserGroups = UserGroupLocalServiceUtil.getUserUserGroups(user.getUserId());

    return user;/* w w  w  .ja  va  2s . c o  m*/
}