// Path: opentipbot-persistence/src/main/java/opentipbot/persistence/config/PersistenceContext.java
// @Configuration
// @EnableJpaRepositories(basePackages = {
//         "opentipbot.persistence.repository"
// })
// @PropertySource("classpath:application.properties")
// public class PersistenceContext {
//     //Entity package
//     private static final String[] PROPERTY_PACKAGES_TO_SCAN = {
//             "opentipbot.persistence.model"
//     };
// 
//     //Database properties
//     protected static final String PROPERTY_NAME_DATABASE_DRIVER = "db.driver";
//     protected static final String PROPERTY_NAME_DATABASE_PASSWORD = "db.password";
//     protected static final String PROPERTY_NAME_DATABASE_URL = "db.url";
//     protected static final String PROPERTY_NAME_DATABASE_USERNAME = "db.username";
// 
//     //Hibernate Properties
//     private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "hibernate.dialect";
//     private static final String PROPERTY_NAME_HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
//     private static final String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO = "hibernate.hbm2ddl.auto";
//     private static final String PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY = "hibernate.ejb.naming_strategy";
//     private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "hibernate.show_sql";
//     private static final String PROPERTY_NAME_HIBERNATE_CONNECTION_AUTOCOMMIT = "hibernate.connection.autocommit";
// 
//     @Autowired
//     private Environment env;
// 
//     @Bean
//     public DataSource dataSource() {
//         BoneCPDataSource dataSource = new BoneCPDataSource();
// 
//         dataSource.setDriverClass(env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
//         dataSource.setJdbcUrl(env.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
//         dataSource.setUsername(env.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
//         dataSource.setPassword(env.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));
// 
//         return dataSource;
//     }
// 
//     @Bean
//     public JpaTransactionManager transactionManager() {
//         JpaTransactionManager transactionManager = new JpaTransactionManager();
// 
//         transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
// 
//         return transactionManager;
//     }
// 
//     @Bean
//     public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
//         LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
// 
//         entityManagerFactoryBean.setDataSource(dataSource());
//         entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
//         entityManagerFactoryBean.setPackagesToScan(PROPERTY_PACKAGES_TO_SCAN);
// 
//         Properties jpaProperties = new Properties();
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_DIALECT, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
//         jpaProperties.put("hibernate.jdbc.use_streams_for_binary", "false");
// 
//         entityManagerFactoryBean.setJpaProperties(jpaProperties);
// 
//         return entityManagerFactoryBean;
//     }
// 
//     @Bean
//     public BitcoinJSONRPCClient bitcoinJSONRPCClient() throws MalformedURLException {
//         return new BitcoinJSONRPCClient(env.getRequiredProperty("coind.url"));
//     }
// 
// }
// 
// Path: opentipbot-service/src/main/java/opentipbot/service/config/ServiceSocialConfig.java
// @Configuration
// public class ServiceSocialConfig {
//     @Bean
//     public TwitterTemplate getTwitterTemplate(Environment env){
//         String consumerKey = env.getProperty("opentipbot.notifier.twitter.appKey");
//         String consumerSecret = env.getProperty("opentipbot.notifier.twitter.appSecret");
//         String accessToken = env.getProperty("opentipbot.notifier.twitter.accessToken");
//         String accessTokenSecret = env.getProperty("opentipbot.notifier.twitter.accessTokenSecret");
//         Preconditions.checkNotNull(consumerKey);
//         Preconditions.checkNotNull(consumerSecret);
//         Preconditions.checkNotNull(accessToken);
//         Preconditions.checkNotNull(accessTokenSecret);
//         return new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
//     }
// }


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.core.env.Environment;
import opentipbot.persistence.config.PersistenceContext;
import opentipbot.service.config.ServiceSocialConfig;
package opentipbot.web.config;


/**
 * @author Gilles Cadignan
 *
 * Opentipbot application conctext declaring message source ressource bundle
 * and Property Placeholder
 */
@Configuration
@ComponentScan(basePackages = {
        "opentipbot.service"
})
@Import({WebAppContext.class, PersistenceContext.class,  SocialContext.class, ServiceSocialConfig.class})
@PropertySource("classpath:application.properties")
public class OpenTipBotApplicationContext {

    private static final String MESSAGE_SOURCE_BASE_NAME = "i18n/messages";

    @Autowired
    private Environment env;

    @Bean
// Path: opentipbot-persistence/src/main/java/opentipbot/persistence/config/PersistenceContext.java
// @Configuration
// @EnableJpaRepositories(basePackages = {
//         "opentipbot.persistence.repository"
// })
// @PropertySource("classpath:application.properties")
// public class PersistenceContext {
//     //Entity package
//     private static final String[] PROPERTY_PACKAGES_TO_SCAN = {
//             "opentipbot.persistence.model"
//     };
// 
//     //Database properties
//     protected static final String PROPERTY_NAME_DATABASE_DRIVER = "db.driver";
//     protected static final String PROPERTY_NAME_DATABASE_PASSWORD = "db.password";
//     protected static final String PROPERTY_NAME_DATABASE_URL = "db.url";
//     protected static final String PROPERTY_NAME_DATABASE_USERNAME = "db.username";
// 
//     //Hibernate Properties
//     private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "hibernate.dialect";
//     private static final String PROPERTY_NAME_HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
//     private static final String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO = "hibernate.hbm2ddl.auto";
//     private static final String PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY = "hibernate.ejb.naming_strategy";
//     private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "hibernate.show_sql";
//     private static final String PROPERTY_NAME_HIBERNATE_CONNECTION_AUTOCOMMIT = "hibernate.connection.autocommit";
// 
//     @Autowired
//     private Environment env;
// 
//     @Bean
//     public DataSource dataSource() {
//         BoneCPDataSource dataSource = new BoneCPDataSource();
// 
//         dataSource.setDriverClass(env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
//         dataSource.setJdbcUrl(env.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
//         dataSource.setUsername(env.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
//         dataSource.setPassword(env.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));
// 
//         return dataSource;
//     }
// 
//     @Bean
//     public JpaTransactionManager transactionManager() {
//         JpaTransactionManager transactionManager = new JpaTransactionManager();
// 
//         transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
// 
//         return transactionManager;
//     }
// 
//     @Bean
//     public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
//         LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
// 
//         entityManagerFactoryBean.setDataSource(dataSource());
//         entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
//         entityManagerFactoryBean.setPackagesToScan(PROPERTY_PACKAGES_TO_SCAN);
// 
//         Properties jpaProperties = new Properties();
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_DIALECT, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
//         jpaProperties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
//         jpaProperties.put("hibernate.jdbc.use_streams_for_binary", "false");
// 
//         entityManagerFactoryBean.setJpaProperties(jpaProperties);
// 
//         return entityManagerFactoryBean;
//     }
// 
//     @Bean
//     public BitcoinJSONRPCClient bitcoinJSONRPCClient() throws MalformedURLException {
//         return new BitcoinJSONRPCClient(env.getRequiredProperty("coind.url"));
//     }
// 
// }
// 
// Path: opentipbot-service/src/main/java/opentipbot/service/config/ServiceSocialConfig.java
// @Configuration
// public class ServiceSocialConfig {
//     @Bean
//     public TwitterTemplate getTwitterTemplate(Environment env){
//         String consumerKey = env.getProperty("opentipbot.notifier.twitter.appKey");
//         String consumerSecret = env.getProperty("opentipbot.notifier.twitter.appSecret");
//         String accessToken = env.getProperty("opentipbot.notifier.twitter.accessToken");
//         String accessTokenSecret = env.getProperty("opentipbot.notifier.twitter.accessTokenSecret");
//         Preconditions.checkNotNull(consumerKey);
//         Preconditions.checkNotNull(consumerSecret);
//         Preconditions.checkNotNull(accessToken);
//         Preconditions.checkNotNull(accessTokenSecret);
//         return new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
//     }
// }


// Path: opentipbot-webapp/src/main/java/opentipbot/web/config/OpenTipBotApplicationContext.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.core.env.Environment;
import opentipbot.persistence.config.PersistenceContext;
import opentipbot.service.config.ServiceSocialConfig;

package opentipbot.web.config;


/**
 * @author Gilles Cadignan
 *
 * Opentipbot application conctext declaring message source ressource bundle
 * and Property Placeholder
 */
@Configuration
@ComponentScan(basePackages = {
        "opentipbot.service"
})
@Import({WebAppContext.class, PersistenceContext.class,  SocialContext.class, ServiceSocialConfig.class})
@PropertySource("classpath:application.properties")
public class OpenTipBotApplicationContext {

    private static final String MESSAGE_SOURCE_BASE_NAME = "i18n/messages";

    @Autowired
    private Environment env;

    @Bean
    public MessageSource messageSource() {