Example usage for com.liferay.portal.kernel.service UserLocalService addGroupUser

List of usage examples for com.liferay.portal.kernel.service UserLocalService addGroupUser

Introduction

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

Prototype

public void addGroupUser(long groupId, User user);

Source Link

Usage

From source file:com.liferay.faces.demos.bean.TestSetupBackingBean.java

License:Open Source License

public void resetUsers(ActionEvent actionEvent) throws PortalException {

    FacesContext facesContext = FacesContext.getCurrentInstance();

    if (!companyLocalServiceTracker.isEmpty()) {

        CompanyLocalService companyLocalService = companyLocalServiceTracker.getService();

        try {/*from   www  . j a  v  a 2 s  .com*/
            long companyId = LiferayPortletHelperUtil.getCompanyId(facesContext);
            long groupId = LiferayPortletHelperUtil.getLayout(facesContext).getGroupId();
            Company company = companyLocalService.getCompanyById(companyId);
            User defaultUser = company.getDefaultUser();
            UserLocalService userLocalService = userLocalServiceTracker.getService();
            User testUser = userLocalService.getUserByEmailAddress(companyId, "test@liferay.com");
            userLocalService.addGroupUser(groupId, testUser);

            long userId = defaultUser.getUserId();
            setupNewUsers(companyId, groupId, userId);

            try {

                long registrantUserId = UserLocalServiceUtil.getUserIdByEmailAddress(companyId,
                        "registrant@liferay.com");
                UserLocalServiceUtil.deleteUser(registrantUserId);
            } catch (NoSuchUserException e) {
                // Do nothing since the user already does not exist.
            }

            usersModelBean.forceListReload();
        } catch (NoSuchCompanyException e) {
            FacesContextHelperUtil.addGlobalErrorMessage(facesContext, "is-temporarily-unavailable",
                    "Company service");
            logger.error(e);
        }
    } else {
        FacesContextHelperUtil.addGlobalErrorMessage(facesContext, "is-temporarily-unavailable",
                "Company service");
    }
}