Use context refresh event to ensure handler is called

This commit is contained in:
Roy Wetherall
2016-02-25 12:02:13 +11:00
parent e0b203207f
commit 8436efbf1f
3 changed files with 42 additions and 13 deletions

View File

@@ -55,4 +55,9 @@ log4j.logger.org.alfresco.module.org_alfresco_module_rm.patch=info
# #
# Job debug # Job debug
# #
#log4j.logger.org.alfresco.module.org_alfresco_module_rm.job=debug #log4j.logger.org.alfresco.module.org_alfresco_module_rm.job=debug
#
# Module compatibility debug
#
log4j.logger.org.alfresco.module.org_alfresco_module_rm.bootstrap.ModuleCompatibilityComponent=debug

View File

@@ -10,7 +10,7 @@
<!-- Module compatibility component --> <!-- Module compatibility component -->
<bean name="rm.moduleCompatibilityComponent" class="org.alfresco.module.org_alfresco_module_rm.bootstrap.ModuleCompatibilityComponent"> <bean name="rm.moduleCompatibilityComponent" class="org.alfresco.module.org_alfresco_module_rm.bootstrap.ModuleCompatibilityComponent">
<property name="descriptorService" ref="DescriptorService"/> <property name="descriptorService" ref="descriptorComponent"/>
<property name="moduleService" ref="ModuleService"/> <property name="moduleService" ref="ModuleService"/>
</bean> </bean>

View File

@@ -26,7 +26,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.ContextStartedEvent; import org.springframework.context.event.ContextRefreshedEvent;
/** /**
* Module compatibility component. * Module compatibility component.
@@ -37,7 +37,7 @@ import org.springframework.context.event.ContextStartedEvent;
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.4 * @since 2.4
*/ */
public class ModuleCompatibilityComponent implements ApplicationListener<ContextStartedEvent> public class ModuleCompatibilityComponent implements ApplicationListener<ContextRefreshedEvent>
{ {
/** Logger */ /** Logger */
private static Log logger = LogFactory.getLog(ModuleCompatibilityComponent.class); private static Log logger = LogFactory.getLog(ModuleCompatibilityComponent.class);
@@ -71,28 +71,52 @@ public class ModuleCompatibilityComponent implements ApplicationListener<Context
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent) * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/ */
@Override @Override
public void onApplicationEvent(ContextStartedEvent contextStartedEvent) public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent)
{ {
// get the license mode // grab the application context
LicenseMode licenseMode = descriptorService.getLicenseDescriptor().getLicenseMode(); ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
if (LicenseMode.ENTERPRISE.equals(licenseMode) && // get the license mode
moduleService.getModule(RM_ENT_MODULE_ID) == null) LicenseMode licenseMode = descriptorService.getServerDescriptor().getLicenseMode();
// determine whether RM Enterprise is installed or not
boolean isRMEnterprise = isRMEnterprise();
// debug log
if (logger.isDebugEnabled())
{
logger.debug("Module compatibility information:");
logger.debug(" Repository licence mode = " + licenseMode.toString());
logger.debug(" RM Enterprise installed = " + isRMEnterprise);
}
if (LicenseMode.ENTERPRISE.equals(licenseMode) && !isRMEnterprise)
{ {
// running enterprise rm on community core so close application context // running enterprise rm on community core so close application context
closeApplicationContext(contextStartedEvent.getApplicationContext(), closeApplicationContext(
applicationContext,
"Running Community Records Management Module on Enterprise Alfresco One is not a supported configuration."); "Running Community Records Management Module on Enterprise Alfresco One is not a supported configuration.");
} }
else if (!LicenseMode.ENTERPRISE.equals(licenseMode) && else if (!LicenseMode.ENTERPRISE.equals(licenseMode) && isRMEnterprise)
moduleService.getModule(RM_ENT_MODULE_ID) != null)
{ {
// running community rm on enterprise core so close application context // running community rm on enterprise core so close application context
closeApplicationContext(contextStartedEvent.getApplicationContext(), closeApplicationContext(
applicationContext,
"Running Enterprise Records Management module on Community Alfresco One is not a supported configuration."); "Running Enterprise Records Management module on Community Alfresco One is not a supported configuration.");
} }
} }
/**
* Indicates whether RM Enterprise module is installed or not.
*
* @return boolean true if RM Enterprise is installed, false otherwise
*/
private boolean isRMEnterprise()
{
return (moduleService.getModule(RM_ENT_MODULE_ID) != null);
}
/** /**
* Close application context, logging message. * Close application context, logging message.
* *