Search in sources :

Example 1 with Module

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);
    }
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) ConfigurationSetup(org.openmrs.module.pihcore.setup.ConfigurationSetup) Module(org.openmrs.module.Module)

Example 2 with Module

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);
}
Also used : Module(org.openmrs.module.Module)

Example 3 with Module

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"));
}
Also used : Module(org.openmrs.module.Module) URL(java.net.URL) Test(org.junit.Test) BaseModuleActivatorTest(org.openmrs.module.BaseModuleActivatorTest)

Example 4 with Module

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);
}
Also used : Module(org.openmrs.module.Module) File(java.io.File) URL(java.net.URL) Test(org.junit.Test) BaseModuleActivatorTest(org.openmrs.module.BaseModuleActivatorTest)

Example 5 with Module

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);
}
Also used : Module(org.openmrs.module.Module) Test(org.junit.Test) BaseModuleActivatorTest(org.openmrs.module.BaseModuleActivatorTest)

Aggregations

Module (org.openmrs.module.Module)22 File (java.io.File)8 Test (org.junit.Test)7 BaseModuleActivatorTest (org.openmrs.module.BaseModuleActivatorTest)5 IOException (java.io.IOException)3 URL (java.net.URL)3 Properties (java.util.Properties)3 JarFile (java.util.jar.JarFile)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 AdministrationService (org.openmrs.api.AdministrationService)2 MandatoryModuleException (org.openmrs.module.MandatoryModuleException)2 ModuleMustStartException (org.openmrs.module.ModuleMustStartException)2 OpenmrsCoreModuleException (org.openmrs.module.OpenmrsCoreModuleException)2 Config (org.openmrs.module.pihcore.config.Config)2 DatabaseUpdateException (org.openmrs.util.DatabaseUpdateException)2 InputRequiredException (org.openmrs.util.InputRequiredException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 FileInputStream (java.io.FileInputStream)1