Search in sources :

Example 1 with InputRequiredException

use of org.openmrs.util.InputRequiredException in project openmrs-core by openmrs.

the class Listener method startOpenmrs.

/**
 * Do the work of starting openmrs.
 *
 * @param servletContext
 * @throws ServletException
 */
public static void startOpenmrs(ServletContext servletContext) throws ServletException {
    // start openmrs
    try {
        // load bundled modules that are packaged into the webapp
        Listener.loadBundledModules(servletContext);
        Context.startup(getRuntimeProperties());
    } catch (DatabaseUpdateException | InputRequiredException updateEx) {
        throw new ServletException("Should not be here because updates were run previously", updateEx);
    } catch (MandatoryModuleException mandatoryModEx) {
        throw new ServletException(mandatoryModEx);
    } catch (OpenmrsCoreModuleException coreModEx) {
        // in the StartupErrorFilter class
        throw coreModEx;
    }
    try {
        // web load modules
        Listener.performWebStartOfModules(servletContext);
        // start the scheduled tasks
        SchedulerUtil.startup(getRuntimeProperties());
    } catch (Exception t) {
        Context.shutdown();
        WebModuleUtil.shutdownModules(servletContext);
        throw new ServletException(t);
    } finally {
        Context.closeSession();
    }
}
Also used : ServletException(javax.servlet.ServletException) InputRequiredException(org.openmrs.util.InputRequiredException) DatabaseUpdateException(org.openmrs.util.DatabaseUpdateException) OpenmrsCoreModuleException(org.openmrs.module.OpenmrsCoreModuleException) MandatoryModuleException(org.openmrs.module.MandatoryModuleException) ServletException(javax.servlet.ServletException) DatabaseUpdateException(org.openmrs.util.DatabaseUpdateException) InputRequiredException(org.openmrs.util.InputRequiredException) ModuleMustStartException(org.openmrs.module.ModuleMustStartException) OpenmrsCoreModuleException(org.openmrs.module.OpenmrsCoreModuleException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) MandatoryModuleException(org.openmrs.module.MandatoryModuleException) IOException(java.io.IOException)

Example 2 with InputRequiredException

use of org.openmrs.util.InputRequiredException in project openmrs-core by openmrs.

the class ModuleFactory method runLiquibase.

/**
 * Execute all not run changeSets in liquibase.xml for the given module
 *
 * @param module the module being executed on
 */
private static void runLiquibase(Module module) {
    JarFile jarFile = null;
    boolean liquibaseFileExists;
    try {
        try {
            jarFile = new JarFile(module.getFile());
        } catch (IOException e) {
            throw new ModuleException("Unable to get jar file", module.getName(), e);
        }
        // check whether module has a liquibase.xml
        InputStream inStream = null;
        ZipEntry entry = null;
        try {
            inStream = ModuleUtil.getResourceFromApi(jarFile, module.getModuleId(), module.getVersion(), MODULE_CHANGELOG_FILENAME);
            if (inStream == null) {
                // Try the old way. Loading from the root of the omod
                entry = jarFile.getEntry(MODULE_CHANGELOG_FILENAME);
            }
            liquibaseFileExists = (inStream != null) || (entry != null);
        } finally {
            IOUtils.closeQuietly(inStream);
        }
    } finally {
        try {
            if (jarFile != null) {
                jarFile.close();
            }
        } catch (IOException e) {
            log.warn("Unable to close jarfile: " + jarFile.getName());
        }
    }
    if (liquibaseFileExists) {
        try {
            // run liquibase.xml by Liquibase API
            DatabaseUpdater.executeChangelog(MODULE_CHANGELOG_FILENAME, null, null, null, getModuleClassLoader(module));
        } catch (InputRequiredException ire) {
            // the user would be stepped through the questions returned here.
            throw new ModuleException("Input during database updates is not yet implemented.", module.getName(), ire);
        } catch (Exception e) {
            throw new ModuleException("Unable to update data model using liquibase.xml.", module.getName(), e);
        }
    }
}
Also used : InputRequiredException(org.openmrs.util.InputRequiredException) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CycleException(org.openmrs.util.CycleException) InputRequiredException(org.openmrs.util.InputRequiredException)

Aggregations

IOException (java.io.IOException)2 InputRequiredException (org.openmrs.util.InputRequiredException)2 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 JarFile (java.util.jar.JarFile)1 ZipEntry (java.util.zip.ZipEntry)1 ServletException (javax.servlet.ServletException)1 MandatoryModuleException (org.openmrs.module.MandatoryModuleException)1 ModuleMustStartException (org.openmrs.module.ModuleMustStartException)1 OpenmrsCoreModuleException (org.openmrs.module.OpenmrsCoreModuleException)1 CycleException (org.openmrs.util.CycleException)1 DatabaseUpdateException (org.openmrs.util.DatabaseUpdateException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1