updated method to retrieve default company id

This commit is contained in:
Massimiliano Assante 2020-09-24 16:22:22 +02:00
parent 80f9801db3
commit 2291ea443f
3 changed files with 28 additions and 8 deletions

View File

@ -7,6 +7,9 @@
<dependent-module archiveName="invites-common-library-1.5.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/invites-common-library/invites-common-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="email-templates-library-1.4.2.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/email-templates-library/email-templates-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="accept-invite-portlet"/>
<property name="java-output-path" value="/accept-invite-portlet/target/classes"/>
</wb-module>

View File

@ -29,7 +29,7 @@ public class InvitationAcceptedEvent extends PortalEvent {
protected String computeUsername(String email) {
try {
Long companyId = CompanyThreadLocal.getCompanyId();
Long companyId = PortletViewController.getCompany().getCompanyId();
Long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
return defaultScreenNameGenerator.generate(companyId, defaultUserId, email);
} catch (Exception e) {

View File

@ -13,8 +13,6 @@
*/
package org.gcube.portlets.user.acceptinvite;
import java.io.IOException;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -27,7 +25,6 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.codec.binary.Base64;
import org.gcube.common.portal.PortalContext;
import org.gcube.event.publisher.Event;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Invite;
@ -45,14 +42,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.model.Company;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.User;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
@Controller(value = "PortletViewController")
@ -194,5 +194,22 @@ public class PortletViewController {
Matcher matcher = VALID_EMAIL_ADDRESS_REGEX .matcher(emailStr);
return matcher.find();
}
public static Company getCompany() throws PortalException, SystemException {
return CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId());
}
/**
*
* @return the default company web-id (e.g. iMarine.eu)
*/
public static String getDefaultCompanyWebId() {
String defaultWebId = "";
try {
defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id"));
}
catch (NullPointerException e) {
_log.error("Cound not find property company.default.web.id in portal.ext file returning default web id: " + DEFAULT_COMPANY_WEB_ID);
return DEFAULT_COMPANY_WEB_ID;
}
return defaultWebId;
}
}