List of usage examples for org.springframework.core.env Environment getRequiredProperty
String getRequiredProperty(String key) throws IllegalStateException;
From source file:io.lavagna.config.DataSourceConfig.java
private static void urlAndCredentials(HikariDataSource dataSource, Environment env) { dataSource.setJdbcUrl(env.getRequiredProperty("datasource.url")); dataSource.setUsername(env.getRequiredProperty("datasource.username")); dataSource.setPassword(/* w w w.ja v a2 s. c o m*/ env.getProperty("datasource.password") != null ? env.getProperty("datasource.password") : ""); }
From source file:io.lavagna.config.DataSourceConfig.java
/** * for supporting heroku style url:/*from w ww. java 2 s . c om*/ * * <pre> * [database type]://[username]:[password]@[host]:[port]/[database name] * </pre> * * @param dataSource * @param env * @throws URISyntaxException */ private static void urlWithCredentials(HikariDataSource dataSource, Environment env) throws URISyntaxException { URI dbUri = new URI(env.getRequiredProperty("datasource.url")); dataSource.setUsername(dbUri.getUserInfo().split(":")[0]); dataSource.setPassword(dbUri.getUserInfo().split(":")[1]); dataSource.setJdbcUrl( String.format("%s://%s:%s%s", scheme(dbUri), dbUri.getHost(), dbUri.getPort(), dbUri.getPath())); }
From source file:ch.sdi.core.impl.cfg.ConfigUtils.java
/** * Tries to read the value from the given environment. * <p>/* w ww . j av a2s .co m*/ * If the converstion fails, an excption is thrown. * <p> * * @param aEnv * @param aKey * @return * @throws SdiException */ public static String getStringProperty(Environment aEnv, String aKey) throws SdiException { try { return aEnv.getRequiredProperty(aKey); } catch (Throwable t) { throw new SdiException("No value found for property " + aKey, t, SdiException.EXIT_CODE_CONFIG_ERROR); } }
From source file:ch.sdi.core.impl.cfg.ConfigUtils.java
/** * Tries to read the value from the given environment and to convert it to an int. * <p>//from w w w . j a va 2 s . c o m * If the converstion fails, the default value is returned. * <p> * * @param aEnv * @param aKey * @param aDefault * @return */ public static int getIntProperty(Environment aEnv, String aKey, int aDefault) { try { checkConversionServiceInitialized(); return myConversionService.convert(aEnv.getRequiredProperty(aKey), Integer.class); } catch (Throwable t) { return aDefault; } }
From source file:ch.sdi.core.impl.cfg.ConfigUtils.java
/** * Tries to read the value from the given environment and to convert it to a boolean. * <p>/*from www .j a va 2s. c om*/ * If the conversion fails, an excption is thrown. * <p> * * @param aEnv * @param aKey * @return * @throws SdiException */ public static boolean getBooleanProperty(Environment aEnv, String aKey) throws SdiException { try { checkConversionServiceInitialized(); return myConversionService.convert(aEnv.getRequiredProperty(aKey), Boolean.class); } catch (Throwable t) { throw new SdiException("No boolean value found for property " + aKey, SdiException.EXIT_CODE_CONFIG_ERROR); } }
From source file:ch.sdi.core.impl.cfg.ConfigUtils.java
/** * Tries to read the value from the given environment and to convert it to an int. * <p>/*from w w w. j a va 2 s. co m*/ * If the converstion fails, an excption is thrown. * <p> * * @param aEnv * @param aKey * @param aDefault * @return * @throws SdiException */ public static int getIntProperty(Environment aEnv, String aKey) throws SdiException { try { checkConversionServiceInitialized(); return myConversionService.convert(aEnv.getRequiredProperty(aKey), Integer.class); } catch (Throwable t) { throw new SdiException("No integer value found for property " + aKey, t, SdiException.EXIT_CODE_CONFIG_ERROR); } }
From source file:nl.dtls.fairdatapoint.api.config.RestApiTestContext.java
@Bean(name = "baseURI") public String baseURI(Environment env) { String rdfBaseURI = env.getRequiredProperty("base-uri"); return rdfBaseURI; }
From source file:io.lavagna.service.DatabaseMigrator.java
private void doMigration(Environment env, DataSource dataSource, MigrationVersion version) { String sqlDialect = env.getRequiredProperty("datasource.dialect"); Flyway migration = new Flyway(); migration.setDataSource(dataSource); // FIXME remove the validation = false when the schemas will be stable migration.setValidateOnMigrate(false); ///*from ww w .j a v a 2 s.co m*/ migration.setTarget(version); migration.setLocations("io/lavagna/db/" + sqlDialect + "/"); migration.migrate(); }
From source file:com.querydsl.webhooks.GithubReviewWindow.java
@Bean public PullRequestHandler reviewWindowHandler(Environment environment) { Duration defaultReviewWindow = Duration.parse(environment.getRequiredProperty("duration")); //duration is the default window Map<String, ScheduledFuture<?>> asyncTasks = Maps.newConcurrentMap(); return payload -> { PullRequest pullRequest = payload.getPullRequest(); Ref head = pullRequest.getHead(); try {/*from w w w . j a va2 s . c o m*/ GHRepository repository = github.getRepository(payload.getRepository().getFullName()); Collection<GHLabel> labels = repository.getIssue(pullRequest.getNumber()).getLabels(); Duration reviewTime = labels.stream().map(label -> "duration." + label.getName()) //for all duration.[label] properties .map(environment::getProperty).filter(Objects::nonNull) //look for a Duration .findFirst().map(Duration::parse).orElse(defaultReviewWindow); //if none found, use the default window ZonedDateTime creationTime = pullRequest.getCreatedAt(); ZonedDateTime windowCloseTime = creationTime.plus(reviewTime); boolean windowPassed = now().isAfter(windowCloseTime); logger.info("creationTime({}) + reviewTime({}) = windowCloseTime({}), so windowPassed = {}", creationTime, reviewTime, windowCloseTime, windowPassed); if (windowPassed) { completeAndCleanUp(asyncTasks, repository, head); } else { createPendingMessage(repository, head, reviewTime); ScheduledFuture<?> scheduledTask = taskScheduler.schedule( () -> completeAndCleanUp(asyncTasks, repository, head), Date.from(windowCloseTime.toInstant())); replaceCompletionTask(asyncTasks, scheduledTask, head); } } catch (IOException ex) { throw Throwables.propagate(ex); } }; }