@Override public BootstrapConfig loadBootstrapConfig() { if (logger.isDebugEnabled()) { logger.debug("Loading bootstrap configuration."); } final BootstrapConfig bootstrapConfig; try { bootstrapConfig = coreConfigurationService == null ? null : coreConfigurationService.loadBootstrapConfig(); } catch (MotechConfigurationException e) { return null; } if (null != bootstrapConfig) { configSource = bootstrapConfig.getConfigSource(); } if (logger.isDebugEnabled()) { logger.debug("BootstrapConfig:" + bootstrapConfig); } return bootstrapConfig; }
@PostConstruct public void init() throws IOException { BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig(); if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) { // allow custom monitors to be injected if (fileMonitor == null) { fileMonitor = new DefaultFileMonitor(this); } fileMonitor.setDelay(DELAY); final List<File> files = new ArrayList<>(); try { files.addAll(configLoader.findExistingConfigs()); } catch (MotechConfigurationException ex) { LOGGER.error(ex.getMessage(), ex); return; } configurationService.processExistingConfigs(files); startFileMonitor(); } }
@Override public boolean requiresConfigurationFiles() { try { if (getConfigSource() == null) { configSource = loadBootstrapConfig().getConfigSource(); } if (!configSource.isFile()) { return false; } ConfigLocation configLocation = coreConfigurationService.getConfigLocation(); return !configLocation.hasPlatformConfigurationFile(); } catch (MotechConfigurationException ex) { logger.error(ex.getMessage(), ex); return true; } }
if (bootstrapConfig.getConfigSource() == ConfigSource.FILE) { settingsRecord = configurationService.loadConfig(); syncSettingsWithDb(); if (bootstrapConfig.getConfigSource() == ConfigSource.FILE) { LOGGER.info("Config source is FILE, and no settings in DB.");
/** * Map from BootstrapConfig to Properties * * @param bootstrapConfig * @return Properties mapped from provided bootstrapConfig. */ public static Properties toProperties(BootstrapConfig bootstrapConfig) { Properties properties = new Properties(); properties.setProperty(BootstrapConfig.COUCHDB_URL, bootstrapConfig.getCouchDbConfig().getUrl()); setIfNotBlank(properties, BootstrapConfig.COUCHDB_USERNAME, bootstrapConfig.getCouchDbConfig().getUsername()); setIfNotBlank(properties, BootstrapConfig.COUCHDB_PASSWORD, bootstrapConfig.getCouchDbConfig().getPassword()); properties.setProperty(BootstrapConfig.SQL_URL, bootstrapConfig.getSqlConfig().getUrl()); properties.setProperty(BootstrapConfig.SQL_DRIVER, bootstrapConfig.getSqlConfig().getDriver()); setIfNotBlank(properties, BootstrapConfig.SQL_USER, bootstrapConfig.getSqlConfig().getUsername()); setIfNotBlank(properties, BootstrapConfig.SQL_PASSWORD, bootstrapConfig.getSqlConfig().getPassword()); properties.setProperty(BootstrapConfig.TENANT_ID, bootstrapConfig.getTenantId()); properties.setProperty(BootstrapConfig.CONFIG_SOURCE, bootstrapConfig.getConfigSource().getName()); return properties; }
@RequestMapping(value = "/startup", method = RequestMethod.POST) @ResponseBody public List<String> submitForm(@RequestBody StartupForm startupSettings) throws IOException { ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI; StartupFormValidator startupFormValidator = startupFormValidatorFactory.getStartupFormValidator(startupSettings, userService); List<String> errors = startupFormValidator.validate(startupSettings, configurationService.getConfigSource()); if (!errors.isEmpty()) { return errors; } else if (!startupManager.canLaunchBundles()) { if (ConfigSource.UI.equals(configSource)) { MotechSettings settings = startupManager.getDefaultSettings(); settings.setLanguage(startupSettings.getLanguage()); settings.setLoginModeValue(startupSettings.getLoginMode()); settings.savePlatformSetting(AMQ_BROKER_URL, startupSettings.getQueueUrl()); settings.setProviderName(startupSettings.getProviderName()); settings.setProviderUrl(startupSettings.getProviderUrl()); configurationService.savePlatformSettings(settings); if (LoginMode.REPOSITORY.equals(LoginMode.valueOf(startupSettings.getLoginMode()))) { registerAdminUser(startupSettings); } } else { registerAdminUser(startupSettings); } startupManager.startup(); } return errors; }
@RequestMapping(value = "/startupviewdata", method = RequestMethod.GET) @ResponseBody public StartupViewData getStartupViewData(final HttpServletRequest request) { StartupViewData viewData = new StartupViewData(); if (startupManager.canLaunchBundles()) { viewData.setRedirectHome(true); return viewData; } else { Locale userLocale = localeService.getUserLocale(request); ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI; boolean requiresConfigFiles = configSource.isFile() && configurationService.requiresConfigurationFiles(); StartupForm startupSettings = new StartupForm(); startupSettings.setLanguage(userLocale.getLanguage()); viewData.setRequireConfigFiles(requiresConfigFiles); viewData.setSuggestions(createSuggestions()); viewData.setStartupSettings(startupSettings); viewData.setLanguages(localeService.getSupportedLanguages()); viewData.setPageLang(userLocale); viewData.setIsFileMode(ConfigSource.FILE.equals(configSource)); viewData.setIsAdminRegistered(userService.hasActiveAdminUser()); viewData.setRedirectHome(false); } return viewData; }