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

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

Introduction

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

Prototype

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public User getUserByEmailAddress(long companyId, String emailAddress) throws PortalException;

Source Link

Document

Returns 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 {/*  w ww  . j a v a2s  .  c o  m*/
            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");
    }
}