package ar.edu.utn.frro.config;

import java.net.URI;
import java.net.URISyntaxException;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

@Configuration
@Profile(Constants.SPRING_PROFILE_HEROKU)
public class HerokuDatabaseConfiguration {

	private final Logger log = LoggerFactory
			.getLogger(HerokuDatabaseConfiguration.class);

	@Bean
	public DataSource dataSource(DataSourceProperties dataSourceProperties,
			JHipsterProperties jHipsterProperties) throws URISyntaxException {
		log.debug("Configuring Heroku Datasource");

		String herokuDatabaseUrl = System.getenv("DATABASE_URL");
		if (herokuDatabaseUrl != null) {
			HikariConfig config = new HikariConfig();
			java.net.URI databaseURI = new URI(herokuDatabaseUrl);
			String jdbcDatabaseURL = "jdbc:postgresql://"
					+ databaseURI.getHost() + ':' + databaseURI.getPort()
					+ databaseURI.getPath();
			String username = databaseURI.getUserInfo().split(":")[0];
			String password = databaseURI.getUserInfo().split(":")[1];

			config.setDataSourceClassName(dataSourceProperties
					.getDriverClassName());
			config.addDataSourceProperty("url", jdbcDatabaseURL);
			config.addDataSourceProperty("user", username);
			config.addDataSourceProperty("password", password);

			return new HikariDataSource(config);
		} else {
			throw new ApplicationContextException(
					"Heroku database URL is not configured, you must set $DATABASE_URL");
		}
	}
}

@@ -908,55 +908,8 @@
 n %7B%0A
-%09%09log.debug(%22Configuring Heroku Datasource%22);%0A%0A
 %09%09St
@@ -913,22 +913,20 @@
 %09String 
-heroku
+jdbc
 Database
@@ -946,16 +946,21 @@
 getenv(%22
+JDBC_
 DATABASE
@@ -971,20 +971,19 @@
 %22);%0A
+%0A
 %09%09if (
-heroku
+jdbc
 Data
@@ -1053,323 +1053,127 @@
 %0A%09%09%09
-java.net.URI databaseURI = new URI(herokuDatabaseUrl);%0A%09%09%09String jdbcDatabaseURL = %22jdbc:postgresql://%22%0A%09%09%09%09%09+ databaseURI.getHost() + ':' + databaseURI.getPort()%0A%09%09%09%09%09+ databaseURI.getPath();%0A%09%09%09String username = databaseURI.getUserInfo().split(%22:%22)%5B0%5D;%0A%09%09%09String password = databaseURI.getUserInfo().split(%22:%22)%5B1%5D
+String username = System.getenv(%22JDBC_DATABASE_USERNAME%22);%0A%09%09%09String password = System.getenv(%22JDBC_DATABASE_PASSWORD%22)
 ;%0A%0A%09
@@ -1306,18 +1306,18 @@
 atabaseU
-RL
+rl
 );%0A%09%09%09co

Fix #10 - Env vars desde heroku para la db