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

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

Introduction

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

Prototype

public long[] getGroupIds();

Source Link

Usage

From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java

License:Open Source License

protected void updateProfile(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    User user = themeDisplay.getUser();

    boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo");

    byte[] portraitBytes = null;

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

    if (!deleteLogo && (fileEntryId > 0)) {
        FileEntry fileEntry = dlAppLocalService.getFileEntry(fileEntryId);

        try (InputStream inputStream = fileEntry.getContentStream()) {
            portraitBytes = FileUtil.getBytes(inputStream);
        }/* w w  w . j  av  a2s  .c o  m*/
    }

    String comments = BeanParamUtil.getString(user, actionRequest, "comments");
    String emailAddress = BeanParamUtil.getString(user, actionRequest, "emailAddress");
    String firstName = BeanParamUtil.getString(user, actionRequest, "firstName");
    String jobTitle = BeanParamUtil.getString(user, actionRequest, "jobTitle");
    String lastName = BeanParamUtil.getString(user, actionRequest, "lastName");
    String middleName = BeanParamUtil.getString(user, actionRequest, "middleName");
    String screenName = BeanParamUtil.getString(user, actionRequest, "screenName");

    Contact contact = user.getContact();

    String facebookSn = BeanParamUtil.getString(contact, actionRequest, "facebookSn");
    String jabberSn = BeanParamUtil.getString(contact, actionRequest, "jabberSn");
    String skypeSn = BeanParamUtil.getString(contact, actionRequest, "skypeSn");
    String smsSn = BeanParamUtil.getString(contact, actionRequest, "smsSn");
    String twitterSn = BeanParamUtil.getString(contact, actionRequest, "twitterSn");

    Calendar cal = CalendarFactoryUtil.getCalendar();

    cal.setTime(user.getBirthday());

    int birthdayDay = cal.get(Calendar.DATE);
    int birthdayMonth = cal.get(Calendar.MONTH);
    int birthdayYear = cal.get(Calendar.YEAR);

    List<AnnouncementsDelivery> announcementsDeliveries = announcementsDeliveryLocalService
            .getUserDeliveries(user.getUserId());

    userService.updateUser(user.getUserId(), user.getPasswordUnencrypted(), user.getPasswordUnencrypted(),
            user.getPasswordUnencrypted(), user.getPasswordReset(), user.getReminderQueryQuestion(),
            user.getReminderQueryAnswer(), screenName, emailAddress, user.getFacebookId(), user.getOpenId(),
            !deleteLogo, portraitBytes, user.getLanguageId(), user.getTimeZoneId(), user.getGreeting(),
            comments, firstName, middleName, lastName, contact.getPrefixId(), contact.getSuffixId(),
            user.isMale(), birthdayMonth, birthdayDay, birthdayYear, smsSn, facebookSn, jabberSn, skypeSn,
            twitterSn, jobTitle, user.getGroupIds(), user.getOrganizationIds(), user.getRoleIds(), null,
            user.getUserGroupIds(), user.getAddresses(), null, user.getPhones(), user.getWebsites(),
            announcementsDeliveries, new ServiceContext());
}

From source file:com.liferay.mentions.internal.util.DefaultMentionsUserFinder.java

License:Open Source License

@Override
public List<User> getUsers(long companyId, long userId, String query,
        SocialInteractionsConfiguration socialInteractionsConfiguration) throws PortalException {

    if (socialInteractionsConfiguration.isSocialInteractionsAnyUserEnabled()) {

        LinkedHashMap<String, Object> params = new LinkedHashMap<>();

        params.put("wildcardMode", WildcardMode.TRAILING);

        return _userLocalService.search(companyId, query, WorkflowConstants.STATUS_APPROVED, params, 0,
                _MAX_USERS, new UserScreenNameComparator());
    }//www  .j a  va  2  s . com

    User user = _userLocalService.getUser(userId);

    int[] types = { SocialRelationConstants.TYPE_BI_FRIEND };

    if (socialInteractionsConfiguration.isSocialInteractionsFriendsEnabled()
            && socialInteractionsConfiguration.isSocialInteractionsSitesEnabled()) {

        return _userLocalService.searchSocial(user.getGroupIds(), userId, types, query, 0, _MAX_USERS);
    }

    if (socialInteractionsConfiguration.isSocialInteractionsSitesEnabled()) {

        return _userLocalService.searchSocial(companyId, user.getGroupIds(), query, 0, _MAX_USERS);
    }

    if (socialInteractionsConfiguration.isSocialInteractionsFriendsEnabled()) {

        return _userLocalService.searchSocial(userId, types, query, 0, _MAX_USERS);
    }

    return Collections.emptyList();
}

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

License:Open Source License

@Override
public List<Long> getPrimaryKeys(User user) throws Exception {
    return getList(user.getGroupIds());
}

From source file:com.liferay.social.activity.service.test.SocialRelationLocalServiceTest.java

License:Open Source License

@Test
public void testGetMultipleGroups() throws Exception {
    User dlc3User = UserLocalServiceUtil.getUserByScreenName(TestPropsValues.getCompanyId(), "dlc3");

    List<User> groupUsers = UserLocalServiceUtil.getGroupUsers(TestPropsValues.getGroupId());

    GroupLocalServiceUtil.addUserGroup(dlc3User.getUserId(), TestPropsValues.getGroupId());

    User dlc4User = UserLocalServiceUtil.getUserByScreenName(TestPropsValues.getCompanyId(), "dlc4");

    GroupLocalServiceUtil.addUserGroup(dlc4User.getUserId(), TestPropsValues.getGroupId());

    Set<Long> groupIds = SetUtil.intersect(dlc3User.getGroupIds(), dlc4User.getGroupIds());

    List<User> users = UserLocalServiceUtil.searchSocial(TestPropsValues.getCompanyId(),
            ArrayUtil.toArray(groupIds.toArray(new Long[groupIds.size()])), "dlc", QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);//from  ww  w .  ja v  a  2s .  c o m

    users = ListUtil.remove(users, groupUsers);

    Assert.assertEquals(users.toString(), 2, users.size());

    GroupLocalServiceUtil.deleteUserGroup(dlc3User.getUserId(), TestPropsValues.getGroupId());
    GroupLocalServiceUtil.deleteUserGroup(dlc4User.getUserId(), TestPropsValues.getGroupId());
}

From source file:com.liferay.users.admin.internal.search.UserIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(User user) throws Exception {
    Document document = getBaseModelDocument(CLASS_NAME, user);

    long[] organizationIds = user.getOrganizationIds();

    document.addKeyword(Field.COMPANY_ID, user.getCompanyId());
    document.addKeyword(Field.GROUP_ID, getActiveGroupIds(user.getUserId()));
    document.addDate(Field.MODIFIED_DATE, user.getModifiedDate());
    document.addKeyword(Field.SCOPE_GROUP_ID, user.getGroupIds());
    document.addKeyword(Field.STATUS, user.getStatus());
    document.addKeyword(Field.USER_ID, user.getUserId());
    document.addKeyword(Field.USER_NAME, user.getFullName(), true);
    document.addKeyword("ancestorOrganizationIds", getAncestorOrganizationIds(user.getOrganizationIds()));
    document.addText("emailAddress", user.getEmailAddress());
    document.addText("firstName", user.getFirstName());
    document.addText("fullName", user.getFullName());
    document.addKeyword("groupIds", user.getGroupIds());
    document.addText("jobTitle", user.getJobTitle());
    document.addText("lastName", user.getLastName());
    document.addText("middleName", user.getMiddleName());
    document.addKeyword("organizationIds", organizationIds);
    document.addKeyword("organizationCount", String.valueOf(organizationIds.length));
    document.addKeyword("roleIds", user.getRoleIds());
    document.addText("screenName", user.getScreenName());
    document.addKeyword("teamIds", user.getTeamIds());
    document.addKeyword("userGroupIds", user.getUserGroupIds());

    populateAddresses(document, user.getAddresses(), 0, 0);

    return document;
}

From source file:com.liferay.users.admin.web.internal.portlet.action.EditUserOrganizationsMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    try {/*  ww  w.  ja  v  a 2s  .  c  om*/
        User user = _portal.getSelectedUser(actionRequest);

        Contact contact = user.getContact();

        Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

        birthdayCal.setTime(user.getBirthday());

        long[] organizationIds = UsersAdminUtil.getOrganizationIds(actionRequest);

        ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

        _userService.updateUser(user.getUserId(), user.getPassword(), null, null, user.getPasswordReset(), null,
                null, user.getScreenName(), user.getEmailAddress(), user.getFacebookId(), user.getOpenId(),
                user.getLanguageId(), user.getTimeZoneId(), user.getGreeting(), user.getComments(),
                user.getFirstName(), user.getMiddleName(), user.getLastName(), contact.getPrefixId(),
                contact.getSuffixId(), user.isMale(), birthdayCal.get(Calendar.MONTH),
                birthdayCal.get(Calendar.DATE), birthdayCal.get(Calendar.YEAR), contact.getSmsSn(),
                contact.getFacebookSn(), contact.getJabberSn(), contact.getSkypeSn(), contact.getTwitterSn(),
                user.getJobTitle(), user.getGroupIds(), organizationIds, user.getRoleIds(),
                _usersAdmin.getUserGroupRoles(actionRequest), user.getUserGroupIds(), serviceContext);
    } catch (Exception e) {
        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass());

            actionResponse.setRenderParameter("mvcPath", "/error.jsp");
        } else if (e instanceof MembershipPolicyException) {
            SessionErrors.add(actionRequest, e.getClass(), e);

            actionResponse.setRenderParameter("mvcPath", "/edit_user.jsp");
            actionResponse.setRenderParameter("screenNavigationCategoryKey",
                    UserFormConstants.CATEGORY_KEY_GENERAL);
            actionResponse.setRenderParameter("screenNavigationEntryKey",
                    UserFormConstants.ENTRY_KEY_ORGANIZATIONS);
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.users.admin.web.internal.portlet.action.UpdateUserRolesMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    try {/*  ww w. j  a  va  2  s.  c  o m*/
        User user = _portal.getSelectedUser(actionRequest);

        Contact contact = user.getContact();

        Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

        birthdayCal.setTime(user.getBirthday());

        long[] roleIds = _usersAdmin.getRoleIds(actionRequest);

        List<UserGroupRole> userGroupRoles = null;

        String addGroupRolesGroupIds = actionRequest.getParameter("addGroupRolesGroupIds");
        String addGroupRolesRoleIds = actionRequest.getParameter("addGroupRolesRoleIds");
        String deleteGroupRolesGroupIds = actionRequest.getParameter("deleteGroupRolesGroupIds");
        String deleteGroupRolesRoleIds = actionRequest.getParameter("deleteGroupRolesRoleIds");

        if ((addGroupRolesGroupIds != null) || (addGroupRolesRoleIds != null)
                || (deleteGroupRolesGroupIds != null) || (deleteGroupRolesRoleIds != null)) {

            userGroupRoles = _usersAdmin.getUserGroupRoles(actionRequest);
        }

        ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

        _userService.updateUser(user.getUserId(), user.getPassword(), null, null, user.getPasswordReset(), null,
                null, user.getScreenName(), user.getEmailAddress(), user.getFacebookId(), user.getOpenId(),
                user.getLanguageId(), user.getTimeZoneId(), user.getGreeting(), user.getComments(),
                user.getFirstName(), user.getMiddleName(), user.getLastName(), contact.getPrefixId(),
                contact.getSuffixId(), user.isMale(), birthdayCal.get(Calendar.MONTH),
                birthdayCal.get(Calendar.DATE), birthdayCal.get(Calendar.YEAR), contact.getSmsSn(),
                contact.getFacebookSn(), contact.getJabberSn(), contact.getSkypeSn(), contact.getTwitterSn(),
                user.getJobTitle(), user.getGroupIds(), user.getOrganizationIds(), roleIds, userGroupRoles,
                user.getUserGroupIds(), serviceContext);
    } catch (Exception e) {
        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass());

            actionResponse.setRenderParameter("mvcPath", "/error.jsp");
        } else if (e instanceof MembershipPolicyException) {
            SessionErrors.add(actionRequest, e.getClass(), e);

            actionResponse.setRenderParameter("mvcPath", "/edit_user.jsp");
            actionResponse.setRenderParameter("screenNavigationCategoryKey",
                    UserFormConstants.CATEGORY_KEY_GENERAL);
            actionResponse.setRenderParameter("screenNavigationEntryKey", UserFormConstants.ENTRY_KEY_ROLES);
        } else {
            throw e;
        }
    }
}

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

License:Open Source License

@Override
public User updateUser(long userId, String oldPassword, String newPassword1, String newPassword2,
        boolean passwordReset, String reminderQueryQuestion, String reminderQueryAnswer, String screenName,
        String emailAddress, long facebookId, String openId, boolean portrait, byte[] portraitBytes,
        String languageId, String timeZoneId, String greeting, String comments, String firstName,
        String middleName, String lastName, long prefixId, long suffixId, boolean male, int birthdayMonth,
        int birthdayDay, int birthdayYear, String smsSn, String facebookSn, String jabberSn, String skypeSn,
        String twitterSn, String jobTitle, long[] groupIds, long[] organizationIds, long[] roleIds,
        List<UserGroupRole> userGroupRoles, long[] userGroupIds, List<Address> addresses,
        List<EmailAddress> emailAddresses, List<Phone> phones, List<Website> websites,
        List<AnnouncementsDelivery> announcementsDelivers, ServiceContext serviceContext)
        throws PortalException {

    _log.info("Updating user ... ");

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

    PortalPermissionUtil.check(getPermissionChecker(), AngularActionKeys.UPDATE_USER);

    _log.debug("    ... processing ... ");

    long creatorId = 0;

    try {// w  w w .  j  a v a 2  s .  com
        creatorId = this.getUserId();
    } catch (PrincipalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to get current user ID", pe);
        }
    }

    if (StringUtils.isEmpty(emailAddress)) {
        throw new PortalException("A email address is needed for new users!");
    }

    // Null safe actions
    if (groupIds == null) {
        groupIds = new long[0];
    }

    if (organizationIds == null) {
        organizationIds = new long[0];
    }

    if (roleIds == null) {
        roleIds = new long[0];
    }

    if (userGroupRoles == null) {
        userGroupRoles = new ArrayList<UserGroupRole>();
    }

    if (userGroupIds == null) {
        userGroupIds = new long[0];
    }

    if (addresses == null) {
        addresses = new ArrayList<Address>();
    }

    if (emailAddresses == null) {
        emailAddresses = new ArrayList<EmailAddress>();
    }

    if (phones == null) {
        phones = new ArrayList<Phone>();
    }

    if (websites == null) {
        websites = new ArrayList<Website>();
    }

    if (announcementsDelivers == null) {
        announcementsDelivers = new ArrayList<AnnouncementsDelivery>();
    }

    User userToUpdate = UserLocalServiceUtil.getUserById(userId);

    if (StringUtils.isEmpty(screenName)) {
        screenName = userToUpdate.getScreenName();
    }

    this.checkUpdateUserPermission(creatorId, userId, userToUpdate.getCompanyId(), groupIds, organizationIds,
            roleIds, userGroupIds, serviceContext);

    // Update contact parts
    this.updateUserAddresses(userToUpdate.getContactId(), addresses);
    this.updateUserEmailAddress(userToUpdate.getContactId(), emailAddresses);
    this.updateUserPhones(userToUpdate.getContactId(), phones);
    this.updateUsrWebsites(userToUpdate.getContactId(), websites);
    this.updateAnnouncementsDeliveries(userToUpdate.getContactId(), announcementsDelivers);

    if (creatorId == userId) {
        emailAddress = StringUtil.toLowerCase(emailAddress.trim());

        if (!StringUtil.equalsIgnoreCase(emailAddress, userToUpdate.getEmailAddress())) {

            validateEmail(emailAddress, userToUpdate);
        }
    }

    validateUpdatePermission(userToUpdate, screenName, emailAddress, firstName, middleName, lastName, prefixId,
            suffixId, birthdayMonth, birthdayDay, birthdayYear, male, jobTitle);

    // Group membership policy

    long[] oldGroupIds = userToUpdate.getGroupIds();

    List<Long> addGroupIds = new ArrayList<>();
    List<Long> removeGroupIds = Collections.emptyList();

    if (groupIds != null) {
        removeGroupIds = ListUtil.toList(oldGroupIds);

        groupIds = angularGroupService.checkGroups(userId, groupIds);

        for (long groupId : groupIds) {
            if (ArrayUtil.contains(oldGroupIds, groupId)) {
                removeGroupIds.remove(groupId);
            } else {
                addGroupIds.add(groupId);
            }
        }

        if (!addGroupIds.isEmpty() || !removeGroupIds.isEmpty()) {
            SiteMembershipPolicyUtil.checkMembership(new long[] { userId }, ArrayUtil.toLongArray(addGroupIds),
                    ArrayUtil.toLongArray(removeGroupIds));
        }
    }

    // Organization membership policy

    long[] oldOrganizationIds = userToUpdate.getOrganizationIds();

    List<Long> addOrganizationIds = new ArrayList<>();
    List<Long> removeOrganizationIds = Collections.emptyList();

    if (organizationIds != null) {
        removeOrganizationIds = ListUtil.toList(oldOrganizationIds);

        organizationIds = angularOrganizationService.checkOrganizations(userId, organizationIds);

        for (long organizationId : organizationIds) {
            if (ArrayUtil.contains(oldOrganizationIds, organizationId)) {
                removeOrganizationIds.remove(organizationId);
            } else {
                addOrganizationIds.add(organizationId);
            }
        }

        if (!addOrganizationIds.isEmpty() || !removeOrganizationIds.isEmpty()) {

            OrganizationMembershipPolicyUtil.checkMembership(new long[] { userId },
                    ArrayUtil.toLongArray(addOrganizationIds), ArrayUtil.toLongArray(removeOrganizationIds));
        }
    }

    // Role membership policy

    long[] oldRoleIds = userToUpdate.getRoleIds();

    List<Long> addRoleIds = new ArrayList<>();
    List<Long> removeRoleIds = Collections.emptyList();

    if (roleIds != null) {
        removeRoleIds = ListUtil.toList(oldRoleIds);

        roleIds = angularRoleService.checkRoles(userId, roleIds);

        for (long roleId : roleIds) {
            if (ArrayUtil.contains(oldRoleIds, roleId)) {
                removeRoleIds.remove(roleId);
            } else {
                addRoleIds.add(roleId);
            }
        }

        if (!addRoleIds.isEmpty() || !removeRoleIds.isEmpty()) {
            RoleMembershipPolicyUtil.checkRoles(new long[] { userId }, ArrayUtil.toLongArray(addRoleIds),
                    ArrayUtil.toLongArray(removeRoleIds));
        }
    }

    List<UserGroupRole> oldOrganizationUserGroupRoles = new ArrayList<>();
    List<UserGroupRole> oldSiteUserGroupRoles = new ArrayList<>();

    List<UserGroupRole> oldUserGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId);

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

        if (role.getType() == RoleConstants.TYPE_ORGANIZATION) {
            oldOrganizationUserGroupRoles.add(oldUserGroupRole);
        } else if (role.getType() == RoleConstants.TYPE_SITE) {
            oldSiteUserGroupRoles.add(oldUserGroupRole);
        }
    }

    List<UserGroupRole> addOrganizationUserGroupRoles = new ArrayList<>();
    List<UserGroupRole> removeOrganizationUserGroupRoles = Collections.emptyList();
    List<UserGroupRole> addSiteUserGroupRoles = new ArrayList<>();
    List<UserGroupRole> removeSiteUserGroupRoles = Collections.emptyList();

    if (userGroupRoles != null) {
        userGroupRoles = angularRoleService.checkUserGroupRoles(userId, userGroupRoles);

        removeOrganizationUserGroupRoles = ListUtil.copy(oldOrganizationUserGroupRoles);
        removeSiteUserGroupRoles = ListUtil.copy(oldSiteUserGroupRoles);

        for (UserGroupRole userGroupRole : userGroupRoles) {
            Role role = userGroupRole.getRole();

            if (role.getType() == RoleConstants.TYPE_ORGANIZATION) {
                if (oldOrganizationUserGroupRoles.contains(userGroupRole)) {
                    removeOrganizationUserGroupRoles.remove(userGroupRole);
                } else {
                    addOrganizationUserGroupRoles.add(userGroupRole);
                }
            } else if (role.getType() == RoleConstants.TYPE_SITE) {
                if (oldSiteUserGroupRoles.contains(userGroupRole)) {
                    removeSiteUserGroupRoles.remove(userGroupRole);
                } else {
                    addSiteUserGroupRoles.add(userGroupRole);
                }
            }
        }

        if (!addOrganizationUserGroupRoles.isEmpty() || !removeOrganizationUserGroupRoles.isEmpty()) {

            OrganizationMembershipPolicyUtil.checkRoles(addOrganizationUserGroupRoles,
                    removeOrganizationUserGroupRoles);
        }

        if (!addSiteUserGroupRoles.isEmpty() || !removeSiteUserGroupRoles.isEmpty()) {

            SiteMembershipPolicyUtil.checkRoles(addSiteUserGroupRoles, removeSiteUserGroupRoles);
        }
    }

    // User group membership policy

    long[] oldUserGroupIds = userToUpdate.getUserGroupIds();

    List<Long> addUserGroupIds = new ArrayList<>();
    List<Long> removeUserGroupIds = Collections.emptyList();

    if (userGroupIds != null) {
        removeUserGroupIds = ListUtil.toList(oldUserGroupIds);

        userGroupIds = angularUserGroupService.checkUserGroupIds(userId, userGroupIds);

        for (long userGroupId : userGroupIds) {
            if (ArrayUtil.contains(oldUserGroupIds, userGroupId)) {
                removeUserGroupIds.remove(userGroupId);
            } else {
                addUserGroupIds.add(userGroupId);
            }
        }

        if (!addUserGroupIds.isEmpty() || !removeUserGroupIds.isEmpty()) {
            UserGroupMembershipPolicyUtil.checkMembership(new long[] { userId },
                    ArrayUtil.toLongArray(addUserGroupIds), ArrayUtil.toLongArray(removeUserGroupIds));
        }
    }

    userToUpdate = userLocalService.updateUser(userId, oldPassword, newPassword1, newPassword2, passwordReset,
            reminderQueryQuestion, reminderQueryAnswer, screenName, emailAddress, facebookId, openId, portrait,
            portraitBytes, languageId, timeZoneId, greeting, comments, firstName, middleName, lastName,
            prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, smsSn, facebookSn, jabberSn,
            skypeSn, twitterSn, jobTitle, groupIds, organizationIds, roleIds, userGroupRoles, userGroupIds,
            serviceContext);

    if (!addGroupIds.isEmpty() || !removeGroupIds.isEmpty()) {
        SiteMembershipPolicyUtil.propagateMembership(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addGroupIds), ArrayUtil.toLongArray(removeGroupIds));
    }

    if (!addOrganizationIds.isEmpty() || !removeOrganizationIds.isEmpty()) {
        OrganizationMembershipPolicyUtil.propagateMembership(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addOrganizationIds), ArrayUtil.toLongArray(removeOrganizationIds));
    }

    if (!addRoleIds.isEmpty() || !removeRoleIds.isEmpty()) {
        RoleMembershipPolicyUtil.propagateRoles(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addRoleIds), ArrayUtil.toLongArray(removeRoleIds));
    }

    if (!addSiteUserGroupRoles.isEmpty() || !removeSiteUserGroupRoles.isEmpty()) {

        SiteMembershipPolicyUtil.propagateRoles(addSiteUserGroupRoles, removeSiteUserGroupRoles);
    }

    if (!addOrganizationUserGroupRoles.isEmpty() || !removeOrganizationUserGroupRoles.isEmpty()) {

        OrganizationMembershipPolicyUtil.propagateRoles(addOrganizationUserGroupRoles,
                removeOrganizationUserGroupRoles);
    }

    if (!addUserGroupIds.isEmpty() || !removeUserGroupIds.isEmpty()) {
        UserGroupMembershipPolicyUtil.propagateMembership(new long[] { userToUpdate.getUserId() },
                ArrayUtil.toLongArray(addUserGroupIds), ArrayUtil.toLongArray(removeUserGroupIds));
    }

    return userToUpdate;
}

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

License:Open Source License

protected void checkDeleteUserPermission(long deleteUserId, long companyId, long userId,
        ServiceContext serviceContext) throws PortalException {

    Company company = CompanyLocalServiceUtil.getCompany(companyId);

    boolean anonymousUser = ParamUtil.getBoolean(serviceContext, "anonymousUser");

    long defaultUserId = userLocalService.getDefaultUserId(companyId);

    if (((deleteUserId != 0) && (deleteUserId != defaultUserId))
            || (!company.isStrangers() && !anonymousUser)) {

        PermissionChecker permissionChecker = getPermissionChecker();

        // Check if user has an according group added with assign members

        User creator = this.getUser(deleteUserId);

        long[] creatorUserGroupIds = creator.getGroupIds();
        boolean hasGroupRight = false;

        // Either group needs right ADD_USER
        if (creatorUserGroupIds != null && creatorUserGroupIds.length > 0) {
            int index = 0;
            while (!hasGroupRight && index < creatorUserGroupIds.length) {
                hasGroupRight = UserGroupPermissionUtil.contains(getPermissionChecker(),
                        creatorUserGroupIds[index++], ActionKeys.DELETE_USER);
            }/*from  w  w w.  j a va2s  .co  m*/
        }

        // or the user itself
        if (!hasGroupRight && !PortalPermissionUtil.contains(permissionChecker, ActionKeys.DELETE_USER)) {

            throw new PrincipalException.MustHavePermission(permissionChecker, Organization.class.getName(), 0,
                    ActionKeys.UPDATE_USER, ActionKeys.ASSIGN_MEMBERS);
        }

    }

}

From source file:it.sysdata.base.service.impl.UserHelperLocalServiceImpl.java

License:Open Source License

public User updateUserInfo(String emailAddress, String password, String firstName, String lastName,
        ServiceContext serviceContext) throws PortalException, SystemException {

    User user = UserLocalServiceUtil.getUserByEmailAddress(serviceContext.getCompanyId(), emailAddress);

    long userId = user.getUserId();
    String oldPassword = password;
    String newPassword1 = password;
    String newPassword2 = password;
    boolean passwordReset = false;

    String reminderQueryQuestion = null;
    String reminderQueryAnswer = null;
    String screenName = user.getScreenName();

    long facebookId = user.getFacebookId();
    String openId = user.getOpenId();
    String languageId = user.getLanguageId();
    String timeZoneId = user.getTimeZoneId();
    String greeting = user.getGreeting();
    String comments = null;//w w  w .ja  va2  s . c o  m
    String middleName = user.getMiddleName();

    int prefixId = 0;
    int suffixId = 0;
    boolean male = user.getMale();
    int birthdayMonth = 0;
    int birthdayDay = 0;
    int birthdayYear = 0;

    String smsSn = null;
    String aimSn = null;
    String facebookSn = null;
    String icqSn = null;
    String jabberSn = null;
    String msnSn = null;
    String mySpaceSn = null;
    String skypeSn = null;
    String twitterSn = null;
    String ymSn = null;
    String jobTitle = user.getJobTitle();

    long[] groupIds = user.getGroupIds();
    long[] organizationIds = user.getOrganizationIds();
    long[] roleIds = user.getRoleIds();
    List<UserGroupRole> userGroupRoles = null;
    long[] userGroupIds = user.getUserGroupIds();

    return UserLocalServiceUtil.updateUser(userId, oldPassword, newPassword1, newPassword2, passwordReset,
            reminderQueryQuestion, reminderQueryAnswer, screenName, emailAddress, facebookId, openId, true,
            null, languageId, timeZoneId, greeting, comments, firstName, middleName, lastName, prefixId,
            suffixId, male, birthdayMonth, birthdayDay, birthdayYear, smsSn, facebookSn, jabberSn, skypeSn,
            twitterSn, jobTitle, groupIds, organizationIds, roleIds, userGroupRoles, userGroupIds,
            serviceContext);
}