Example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getUserGroups

List of usage examples for com.liferay.portal.kernel.service GroupLocalServiceUtil getUserGroups

Introduction

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

Prototype

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

Source Link

Usage

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

License:Open Source License

public long[] checkGroups(long userId, long[] groupIds) throws PortalException {

    long[] oldGroupIds = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    User user = null;/*from ww  w .  j  a  v  a 2 s.co  m*/

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any mandatory groups or groups that the administrator
        // does not have the rights to remove and check that he has the
        // permission to add a new group

        user = userPersistence.findByPrimaryKey(userId);

        List<Group> oldGroups = GroupLocalServiceUtil.getUserGroups(userId);

        oldGroupIds = new long[oldGroups.size()];

        for (int i = 0; i < oldGroups.size(); i++) {
            Group group = oldGroups.get(i);

            if (!ArrayUtil.contains(groupIds, group.getGroupId())
                    && (!GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.ASSIGN_MEMBERS)
                            || SiteMembershipPolicyUtil.isMembershipProtected(permissionChecker,
                                    user.getUserId(), group.getGroupId())
                            || SiteMembershipPolicyUtil.isMembershipRequired(userId, group.getGroupId()))) {

                groupIds = ArrayUtil.append(groupIds, group.getGroupId());
            }

            oldGroupIds[i] = group.getGroupId();
        }
    }

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

    for (long groupId : groupIds) {
        if ((oldGroupIds != null) && ArrayUtil.contains(oldGroupIds, groupId)) {

            continue;
        }

        Group group = GroupLocalServiceUtil.getGroup(groupId);

        GroupPermissionUtil.check(permissionChecker, group, ActionKeys.ASSIGN_MEMBERS);
    }

    return groupIds;
}

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;//from  ww w  .  j a  v a 2  s .c  o m
}