/** * 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; }
/** * Map from properties to BootstrapConfig object * * @param bootstrapProperties * @return BootstrapConfig object mapped from provided properties. */ public static BootstrapConfig fromProperties(Properties bootstrapProperties) { return new BootstrapConfig(new DBConfig(bootstrapProperties.getProperty(BootstrapConfig.COUCHDB_URL), bootstrapProperties.getProperty(BootstrapConfig.COUCHDB_USERNAME), bootstrapProperties.getProperty(BootstrapConfig.COUCHDB_PASSWORD)), new SQLDBConfig(bootstrapProperties.getProperty(BootstrapConfig.SQL_URL), bootstrapProperties.getProperty(BootstrapConfig.SQL_DRIVER), bootstrapProperties.getProperty(BootstrapConfig.SQL_USER), bootstrapProperties.getProperty(BootstrapConfig.SQL_PASSWORD)), bootstrapProperties.getProperty(BootstrapConfig.TENANT_ID), ConfigSource.valueOf(bootstrapProperties.getProperty(BootstrapConfig.CONFIG_SOURCE))); } }
@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; }
private void setSqlProperties() { SQLDBConfig sqlConfig = coreConfigurationService.loadBootstrapConfig().getSqlConfig(); String sqlUrl = sqlConfig.getUrl(); sqlProperties.setProperty("sql.url", sqlUrl); String sqlUser = sqlConfig.getUsername(); if (sqlUser != null) { sqlProperties.setProperty("sql.user", sqlUser); } String sqlPassword = sqlConfig.getPassword(); if (sqlPassword != null) { sqlProperties.setProperty("sql.password", sqlPassword); } String sqlDriver = sqlConfig.getDriver(); if (sqlDriver != null) { sqlProperties.setProperty("sql.driver", sqlDriver); } }
private Properties getCouchdbProperties() { DBConfig dbConfig = coreConfigurationService.loadBootstrapConfig().getCouchDbConfig(); Properties mergedProps = new Properties(); mergedProps.putAll(couchdbProperties); mergedProps.setProperty(DB_URL, dbConfig.getUrl()); setKeyIfValueNotNull(mergedProps, DB_USERNAME, dbConfig.getUsername()); setKeyIfValueNotNull(mergedProps, DB_PASSWORD, dbConfig.getPassword()); return mergedProps; }
@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; } }
private BootstrapConfig readBootstrapConfigFromEnvironment() { String couchDbUrl = environment.getCouchDBUrl(); String couchDbUsername = environment.getCouchDBUsername(); String couchDbPassword = environment.getCouchDBPassword(); String sqlUrl = environment.getSqlUrl(); String sqlUsername = environment.getSqlUsername(); String sqlPassword = environment.getSqlPassword(); String tenantId = environment.getTenantId(); String configSource = environment.getConfigSource(); String sqlDriver = environment.getSqlDriver(); return new BootstrapConfig(new DBConfig(couchDbUrl, couchDbUsername, couchDbPassword), new SQLDBConfig(sqlUrl, sqlDriver, sqlUsername, sqlPassword), tenantId, ConfigSource.valueOf(configSource)); }
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.");
@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; }