List of usage examples for com.liferay.portal.kernel.service CompanyLocalService getCompanyById
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true) public Company getCompanyById(long companyId) throws PortalException;
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"); } }