Example usage for com.liferay.portal.kernel.service CompanyLocalService getCompanyById

List of usage examples for com.liferay.portal.kernel.service CompanyLocalService getCompanyById

Introduction

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

Prototype

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public Company getCompanyById(long companyId) throws PortalException;

Source Link

Document

Returns the company with the primary key.

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 w w w  .  ja v  a 2s. co  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");
    }
}