Skip to content

Commit

Permalink
LPD-25508 Delay company creation via OSGI configs, until initial request
Browse files Browse the repository at this point in the history
This company creation mechanism (via OSGI config), was intended to
be used with DBPartition enabled. But, with the current state of
DBPartition, creating a new partition requires the default company
to first be fully ready and populated, since it needs to copy over
certain tables from the default company to the new partition.

And so, delaying the company creation until the initial request
should help to ensure that the default company is fully ready and
populated, before attempting to create a new company and partition.
  • Loading branch information
ericyanLr authored and brianchandotcom committed Oct 3, 2024
1 parent c533f91 commit d0732f9
Showing 1 changed file with 57 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import com.liferay.portal.instances.service.PortalInstancesLocalService;
import com.liferay.portal.kernel.exception.NoSuchCompanyException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Company;
import com.liferay.portal.kernel.module.framework.ModuleServiceLifecycle;
import com.liferay.portal.kernel.service.CompanyLocalService;
import com.liferay.portal.kernel.servlet.InitialRequestSyncUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.util.PortalInstances;

Expand All @@ -35,56 +35,62 @@
public class PortalInstancesConfigurationFactory {

@Activate
protected void activate(Map<String, Object> properties)
throws PortalException {

PortalInstancesConfiguration portalInstancesConfiguration =
ConfigurableUtil.createConfigurable(
PortalInstancesConfiguration.class, properties);

String webId = _getWebId(properties);
String virtualHostname = portalInstancesConfiguration.virtualHostname();
String mx = portalInstancesConfiguration.mx();
int maxUsers = portalInstancesConfiguration.maxUsers();
boolean active = portalInstancesConfiguration.active();

Company company = null;

try {
company = _companyLocalService.getCompanyByWebId(webId);
}
catch (NoSuchCompanyException noSuchCompanyException) {
if (_log.isDebugEnabled()) {
_log.debug(noSuchCompanyException);
}
}

if (company == null) {
PortalInstances.addCompany(
portalInstancesConfiguration.siteInitializerKey(),
() -> _companyLocalService.addCompany(
null, webId, virtualHostname, mx, maxUsers,
portalInstancesConfiguration.active(),
portalInstancesConfiguration.addDefaultAdminUser(),
portalInstancesConfiguration.adminPassword(),
portalInstancesConfiguration.adminScreenName(),
portalInstancesConfiguration.adminEmailAddress(),
portalInstancesConfiguration.adminFirstName(),
portalInstancesConfiguration.adminMiddleName(),
portalInstancesConfiguration.adminLastName()));
}
else {
if (company.getCompanyId() ==
_portalInstancesLocalService.getDefaultCompanyId()) {

active = true;
}

_companyLocalService.updateCompany(
company.getCompanyId(), virtualHostname, mx, maxUsers, active);
}

_portalInstancesLocalService.synchronizePortalInstances();
protected void activate(Map<String, Object> properties) {
InitialRequestSyncUtil.registerSyncCallable(
() -> {
PortalInstancesConfiguration portalInstancesConfiguration =
ConfigurableUtil.createConfigurable(
PortalInstancesConfiguration.class, properties);
String webId = _getWebId(properties);

String virtualHostname =
portalInstancesConfiguration.virtualHostname();
String mx = portalInstancesConfiguration.mx();
int maxUsers = portalInstancesConfiguration.maxUsers();
boolean active = portalInstancesConfiguration.active();

Company company = null;

try {
company = _companyLocalService.getCompanyByWebId(webId);
}
catch (NoSuchCompanyException noSuchCompanyException) {
if (_log.isDebugEnabled()) {
_log.debug(noSuchCompanyException);
}
}

if (company == null) {
PortalInstances.addCompany(
portalInstancesConfiguration.siteInitializerKey(),
() -> _companyLocalService.addCompany(
null, webId, virtualHostname, mx, maxUsers,
portalInstancesConfiguration.active(),
portalInstancesConfiguration.addDefaultAdminUser(),
portalInstancesConfiguration.adminPassword(),
portalInstancesConfiguration.adminScreenName(),
portalInstancesConfiguration.adminEmailAddress(),
portalInstancesConfiguration.adminFirstName(),
portalInstancesConfiguration.adminMiddleName(),
portalInstancesConfiguration.adminLastName()));
}
else {
if (company.getCompanyId() ==
_portalInstancesLocalService.
getDefaultCompanyId()) {

active = true;
}

_companyLocalService.updateCompany(
company.getCompanyId(), virtualHostname, mx, maxUsers,
active);
}

_portalInstancesLocalService.synchronizePortalInstances();

return null;
});
}

private String _getWebId(Map<String, Object> properties) {
Expand Down

0 comments on commit d0732f9

Please sign in to comment.