@Override public void validate(StartupForm target, List<String> errors, ConfigSource configSource) { if (isNullOrEmpty(fieldValue)) { if (!configSource.isFile()) { errors.add(String.format(ERROR_REQUIRED, fieldName)); } } }
public static boolean isValid(String name) { try { valueOf(name); return true; } catch (MotechConfigurationException e) { return false; } }
/** * 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; }
@Override public void validate(StartupForm target, List<String> errors, ConfigSource configSource) { if (isNullOrEmpty(target.getProviderName())) { if (!configSource.isFile()) { errors.add(String.format(ERROR_REQUIRED, PROVIDER_NAME)); } } if (isNullOrEmpty(target.getProviderUrl())) { errors.add(String.format(ERROR_REQUIRED, PROVIDER_URL)); } else if (!urlValidator.isValid(target.getProviderUrl())) { errors.add(String.format(ERROR_INVALID, PROVIDER_URL)); } } }
/** * 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 void validate(StartupForm target, List<String> errors, ConfigSource configSource) { if (isNullOrEmpty(target.getQueueUrl())) { if (!configSource.isFile()) { errors.add(String.format(ERROR_REQUIRED, QUEUE_URL)); } return; } try { String value = target.getQueueUrl().replace("localhost", "127.0.0.1"); URI brokerURL = new URI(value); if (isCompositeURI(brokerURL)) { URISupport.CompositeData data = parseComposite(brokerURL); String scheme = data.getScheme(); if (scheme != null && ("failover".equals(scheme) || "fanout".equals(scheme) || "vm".equals(scheme))) { for (URI uri : data.getComponents()) { validateUriContainSpecificScheme(target, errors, uri); } } else { errors.add(String.format(ERROR_INVALID, QUEUE_URL)); } } else { isValidUri(target, errors, value); } } catch (URISyntaxException e) { errors.add(String.format(ERROR_INVALID, QUEUE_URL)); } }
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)); }
@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; } }
@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; }