use of org.openmrs.module.Module in project openmrs-module-pihcore by PIH.
the class PihCoreActivator method configureSystem.
public void configureSystem() {
try {
log.info("Initiating pihcore configuration");
final ConfigurationSetup configurationSetup = Context.getRegisteredComponents(ConfigurationSetup.class).get(0);
configurationSetup.setupBase();
configurationSetup.configureNonConceptDependencies();
AdministrationService as = Context.getAdministrationService();
String runInSeparateThread = as.getGlobalProperty(PihCoreConstants.GP_RUN_CONCEPT_SETUP_TASK_IN_SEPARATE_THREAD);
if ("true".equalsIgnoreCase(runInSeparateThread)) {
// see https://pihemr.atlassian.net/browse/UHM-4459
log.info("Setting up configuration in a separate thread. Please monitor logs to check status.");
Daemon.runInDaemonThread(() -> {
try {
configurationSetup.configureConceptDependencies();
} catch (Exception e) {
log.error("Configuration Setup Failed", e);
throw new RuntimeException(e);
}
}, daemonToken);
} else {
configurationSetup.configureConceptDependencies();
}
log.info("Distribution startup complete.");
} catch (Exception e) {
Module mod = ModuleFactory.getModuleById("pihcore");
ModuleFactory.stopModule(mod, true, true);
throw new RuntimeException("An error occurred while starting the pihcore module", e);
}
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class MutableResourceBundleMessageSource method setBasenames.
/**
* Override to obtain a local reference to the basenames.
*
* @see org.springframework.context.support.ReloadableResourceBundleMessageSource#setBasenames(java.lang.String[])
*/
@Override
public void setBasenames(String... basenames) {
if (basenames == null) {
this.basenames = new String[0];
} else {
this.basenames = Arrays.copyOf(basenames, basenames.length);
}
// add module file urls to basenames used for locating message properties files
Collection<Module> modules = ModuleFactory.getStartedModules();
if (!modules.isEmpty()) {
String[] names = new String[this.basenames.length + modules.size()];
System.arraycopy(this.basenames, 0, names, 0, this.basenames.length);
int index = this.basenames.length;
for (Module module : modules) {
names[index] = "jar:file:" + module.getFile().getAbsolutePath() + "!/messages";
index++;
}
basenames = names;
}
super.setBasenames(basenames);
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class WebModuleActivatorTest method shouldUpgradeModule.
@Test
public void shouldUpgradeModule() {
Module module = ModuleFactory.getModuleById(MODULE3_ID);
assertTrue(module.getVersion().equals("1.0-SNAPSHOT"));
URL url = OpenmrsClassLoader.getInstance().getResource("org/openmrs/module/include/test3-2.0-SNAPSHOT.omod");
module.setDownloadURL("file:" + url.getFile());
createWebInfFolderIfNotExist();
// stop the module with these parameters so that mandatory modules can be upgraded
ModuleFactory.stopModule(module, false, true);
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext());
Module newModule = ModuleFactory.updateModule(module);
WebModuleUtil.startModule(newModule, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);
// module3 should have upgraded from version 1.0 to 2.0
module = ModuleFactory.getModuleById(MODULE3_ID);
assertTrue(module.getVersion().equals("2.0-SNAPSHOT"));
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class WebModuleActivatorTest method shouldRefreshOtherModulesOnInstallingNewModule.
@Test
public void shouldRefreshOtherModulesOnInstallingNewModule() {
// first completely remove module3
Module module = ModuleFactory.getModuleById(MODULE3_ID);
ModuleFactory.stopModule(module);
WebModuleUtil.stopModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext());
ModuleFactory.unloadModule(module);
// to initialize for the condition below:
init();
createWebInfFolderIfNotExist();
// When OpenMRS is running and you install a new module:
// willRefreshContext() and contextRefreshed() methods get called for all started modules' activators (including the newly installed module)
// willStart() and started() methods get called for ONLY the newly installed module's activator
// install a new module3
URL url = OpenmrsClassLoader.getInstance().getResource("org/openmrs/module/include/test3-1.0-SNAPSHOT.omod");
File file = new File(url.getFile());
module = ModuleFactory.loadModule(file);
ModuleFactory.startModule(module);
WebModuleUtil.startModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);
assertTrue(module.isStarted());
assertTrue(ModuleFactory.isModuleStarted(module));
// module1, module2 and module3 should refresh
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE3_ID) == 1);
// willStart() and started() methods get called for ONLY the newly installed module's activator
assertTrue(moduleTestData.getWillStartCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getStartedCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1);
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class WebModuleActivatorTest method shouldRefreshOtherModulesOnStartingStoppedModule.
@Test
public void shouldRefreshOtherModulesOnStartingStoppedModule() {
Module module = ModuleFactory.getModuleById(MODULE3_ID);
ModuleFactory.stopModule(module);
// to initialize for the condition below:
init();
createWebInfFolderIfNotExist();
// When OpenMRS is running and you start a stopped module:
// willRefreshContext() and contextRefreshed() methods get called for all started modules' activators (including the newly started module)
// willStart() and started() methods get called for ONLY the newly started module's activator
// start module3 which was previously stopped
ModuleFactory.startModule(module);
WebModuleUtil.startModule(module, ((XmlWebApplicationContext) applicationContext).getServletContext(), false);
assertTrue(module.isStarted());
assertTrue(ModuleFactory.isModuleStarted(module));
// module1, module2 and module3 should refresh
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getWillRefreshContextCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE1_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE2_ID) == 1);
assertTrue(moduleTestData.getContextRefreshedCallCount(MODULE3_ID) == 1);
// willStart() and started() methods get called for ONLY the newly started module's activator
assertTrue(moduleTestData.getWillStartCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getWillStartCallCount(MODULE3_ID) == 1);
assertTrue(moduleTestData.getStartedCallCount(MODULE1_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE2_ID) == 0);
assertTrue(moduleTestData.getStartedCallCount(MODULE3_ID) == 1);
}
Aggregations