Example usage for com.liferay.portal.kernel.service UserLocalServiceUtil getUserIdByEmailAddress

List of usage examples for com.liferay.portal.kernel.service UserLocalServiceUtil getUserIdByEmailAddress

Introduction

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

Prototype

public static long getUserIdByEmailAddress(long companyId, String emailAddress)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns the primary key of the user with the email address.

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   ww  w  . 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");
    }
}