diff --git a/pom.xml b/pom.xml index 782f92985e..54ed7be762 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ ${alfresco.groupId} alfresco-platform-distribution - ${alfresco.version} + 5.1-20160302.012107-260 pom import diff --git a/rm-automation/pom.xml b/rm-automation/pom.xml index e4e77a69ff..b21356e74d 100644 --- a/rm-automation/pom.xml +++ b/rm-automation/pom.xml @@ -123,7 +123,7 @@ org.alfresco.test dataprep - 1.4 + 1.8 org.alfresco.test diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml index b0317256f9..50e505c39f 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml @@ -7,6 +7,12 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "> + + + + + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/ModuleCompatibilityComponent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/ModuleCompatibilityComponent.java new file mode 100644 index 0000000000..c5fedd96c4 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/ModuleCompatibilityComponent.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2005-2016 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.module.org_alfresco_module_rm.bootstrap; + +import org.alfresco.service.cmr.admin.RepoUsage.LicenseMode; +import org.alfresco.service.cmr.module.ModuleService; +import org.alfresco.service.descriptor.DescriptorService; +import org.alfresco.service.license.LicenseDescriptor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.event.ContextRefreshedEvent; + +/** + * Module compatibility component. + *

+ * Checks that the currently installed RM AMP licence mode matches that of the + * underlying repository. + * + * @author Roy Wetherall + * @since 2.4 + */ +public class ModuleCompatibilityComponent implements ApplicationListener +{ + /** Logger */ + private static Log logger = LogFactory.getLog(ModuleCompatibilityComponent.class); + + // TODO get this from somewhere + private static final String RM_ENT_MODULE_ID = "alfresco-rm-enterprise-repo"; + + /** descriptor service */ + private DescriptorService descriptorService; + + /** module service */ + private ModuleService moduleService; + + /** + * @param descriptorService descriptor service + */ + public void setDescriptorService(DescriptorService descriptorService) + { + this.descriptorService = descriptorService; + } + + /** + * @param moduleService module service + */ + public void setModuleService(ModuleService moduleService) + { + this.moduleService = moduleService; + } + + /** + * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent) + */ + @Override + public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) + { + // license mode + LicenseMode licenseMode = LicenseMode.UNKNOWN; + + // grab the application context + ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext(); + + // get the license mode + LicenseDescriptor license = descriptorService.getLicenseDescriptor(); + if (license != null) + { + licenseMode = license.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 + closeApplicationContext(applicationContext, + "Running Community Records Management Module on Enterprise Alfresco One is not a supported configuration."); + + } + else if (!LicenseMode.ENTERPRISE.equals(licenseMode) && isRMEnterprise) + { + // running community rm on enterprise core so close application + // context + closeApplicationContext(applicationContext, + "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. + * + * @param applicationContext application context + * @param message closure message + */ + private void closeApplicationContext(ApplicationContext applicationContext, String message) + { + // log closure message + if (logger.isErrorEnabled()) + { + logger.error(message); + } + + // close the application context! + ((ConfigurableApplicationContext) applicationContext).close(); + } +} diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/ModuleCompatibilityComponentUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/ModuleCompatibilityComponentUnitTest.java new file mode 100644 index 0000000000..e4c7eef75c --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/ModuleCompatibilityComponentUnitTest.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2005-2016 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.module.org_alfresco_module_rm.bootstrap; + +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.alfresco.service.cmr.admin.RepoUsage.LicenseMode; +import org.alfresco.service.cmr.module.ModuleDetails; +import org.alfresco.service.cmr.module.ModuleService; +import org.alfresco.service.descriptor.DescriptorService; +import org.alfresco.service.license.LicenseDescriptor; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.event.ContextRefreshedEvent; + +/** + * Module compatibility component unit test + * + * @author Roy Wetherall + * @since 2.4 + */ +public class ModuleCompatibilityComponentUnitTest +{ + /** mocks */ + @Mock private DescriptorService mockedDescriptorService; + @Mock private ModuleService mockedModuleService; + @Mock private ContextRefreshedEvent mockedContextRefreshedEvent; + @Mock private ConfigurableApplicationContext mockedApplicationContext; + @Mock private ModuleDetails mockedModuleDetails; + @Mock private LicenseDescriptor mockedDescriptor; + + /** object under test */ + @InjectMocks private ModuleCompatibilityComponent moduleCompatibilityComponent; + + /** + * Before test execution + */ + @Before + public void before() + { + MockitoAnnotations.initMocks(this); + + when(mockedContextRefreshedEvent.getApplicationContext()) + .thenReturn(mockedApplicationContext); + when(mockedDescriptorService.getLicenseDescriptor()) + .thenReturn(mockedDescriptor); + } + + /** + * Given that core community is installed + * And that RM community is installed + * When the application context is loaded + * Then it is successful + */ + @Test + public void communityOnCommunity() + { + // community core installed + when(mockedDescriptor.getLicenseMode()) + .thenReturn(LicenseMode.UNKNOWN); + + // community RM installed + when(mockedModuleService.getModule(anyString())) + .thenReturn(null); + + // on app context refresh + moduleCompatibilityComponent.onApplicationEvent(mockedContextRefreshedEvent); + + // verify close never called + verify(mockedApplicationContext, never()).close(); + + } + + /** + * Given that core community is installed + * And that RM enterprise is installed + * When the application context is loaded + * Then it fails + */ + @Test + public void enterpriseOnCommunity() + { + // community core installed + when(mockedDescriptor.getLicenseMode()) + .thenReturn(LicenseMode.UNKNOWN); + + // enterprise RM installed + when(mockedModuleService.getModule(anyString())) + .thenReturn(mockedModuleDetails); + + // on app context refresh + moduleCompatibilityComponent.onApplicationEvent(mockedContextRefreshedEvent); + + // verify close is called + verify(mockedApplicationContext).close(); + + } + + /** + * Given that core enterprise is installed + * And that RM community is installed + * When the application context is loaded + * Then it fails + */ + @Test + public void communityOnEnterprise() + { + // enterprise core installed + when(mockedDescriptor.getLicenseMode()) + .thenReturn(LicenseMode.ENTERPRISE); + + // community RM installed + when(mockedModuleService.getModule(anyString())) + .thenReturn(null); + + // on app context refresh + moduleCompatibilityComponent.onApplicationEvent(mockedContextRefreshedEvent); + + // verify close is called + verify(mockedApplicationContext).close(); + } + + /** + * Given that core enterprise is installed + * And that RM enterprise is installed + * When the application context is loaded + * Then it is successful + */ + @Test + public void enterpriseOnEnterprise() + { + // enterprise core installed + when(mockedDescriptor.getLicenseMode()) + .thenReturn(LicenseMode.ENTERPRISE); + + // enterprise RM installed + when(mockedModuleService.getModule(anyString())) + .thenReturn(mockedModuleDetails); + + // on app context refresh + moduleCompatibilityComponent.onApplicationEvent(mockedContextRefreshedEvent); + + // verify close never called + verify(mockedApplicationContext, never()).close(); + + } +}