package org.mousephenotype.cda.loads.annotations;

import org.mousephenotype.cda.db.statistics.MpTermService;
import org.mousephenotype.cda.loads.common.CdaSqlUtils;
import org.mousephenotype.cda.loads.common.config.DataSourceCdaConfig;
import org.mousephenotype.cda.loads.common.config.DataSourceCdabaseConfig;
import org.mousephenotype.cda.loads.common.config.DataSourceDccConfig;
import org.mousephenotype.cda.loads.statistics.generate.StatisticalDatasetGeneratorConfig;
import org.mousephenotype.cda.loads.statistics.load.StatisticalResultLoaderConfig;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

import javax.sql.DataSource;

import static org.mousephenotype.cda.db.utilities.SqlUtils.getConfiguredDatasource;

@Configuration
@ComponentScan(basePackages = {"org.mousephenotype.cda.loads.annotations", "org.mousephenotype.cda.loads.statistics.load", "org.mousephenotype.cda.db"},
        includeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
                        MpTermService.class
                })
        },
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {
                        DataSourceCdabaseConfig.class,
                        DataSourceCdaConfig.class,
                        DataSourceDccConfig.class,
                        StatisticalResultLoaderConfig.class,
                        StatisticalDatasetGeneratorConfig.class,
                        CdaSqlUtils.class})})
public class OntologyAnnotationGeneratorConfig {

    private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${datasource.komp2.jdbc-url}")
    String komp2Url;

    @Value("${datasource.komp2.username}")
    String komp2Username;

    @Value("${datasource.komp2.password}")
    String komp2Password;


//    @Bean
//    @Primary
//    @PersistenceContext(name = "komp2Context")
//    public LocalContainerEntityManagerFactoryBean emf(EntityManagerFactoryBuilder builder) {
//        return builder
//                .dataSource(komp2DataSource())
//                .packages("org.mousephenotype.cda.db")
//                .persistenceUnit("komp2")
//                .build();
//    }
//
//    @Bean(name = "sessionFactoryHibernate")
//    public LocalSessionFactoryBean sessionFactoryHibernate() {
//        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
//        sessionFactory.setDataSource(komp2DataSource());
//        sessionFactory.setPackagesToScan("org.mousephenotype.cda.db");
//        return sessionFactory;
//    }
//
//    @Bean(name = "sessionFactoryHibernate")
//    @Primary
//    public SessionFactory getSessionFactory() {
//
//        LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(komp2DataSource());
//        sessionBuilder.scanPackages("org.mousephenotype.cda.db.entity");
//        sessionBuilder.scanPackages("org.mousephenotype.cda.db.pojo");
//
//        return sessionBuilder.buildSessionFactory();
//    }

    @Bean(name = "komp2DataSource")
    @Primary
    public DataSource komp2DataSource() {
        return getConfiguredDatasource(komp2Url, komp2Username, komp2Password);
    }
}
@@ -613,38 +613,40 @@
 ork.
-beans.factory.annotation.Value
+context.annotation.ComponentScan
 ;%0Aim
@@ -693,123 +693,78 @@
 ion.
-*;%0A%0Aimport javax.sql.DataSource;%0A%0Aimport static org.mousephenotype.cda.db.utilities.SqlUtils.getConfiguredDatasourc
+Configuration;%0Aimport org.springframework.context.annotation.FilterTyp
 e;%0A%0A
@@ -1697,1576 +1697,5 @@
 );%0A%0A
-    @Value(%22$%7Bdatasource.komp2.jdbc-url%7D%22)%0A    String komp2Url;%0A%0A    @Value(%22$%7Bdatasource.komp2.username%7D%22)%0A    String komp2Username;%0A%0A    @Value(%22$%7Bdatasource.komp2.password%7D%22)%0A    String komp2Password;%0A%0A%0A//    @Bean%0A//    @Primary%0A//    @PersistenceContext(name = %22komp2Context%22)%0A//    public LocalContainerEntityManagerFactoryBean emf(EntityManagerFactoryBuilder builder) %7B%0A//        return builder%0A//                .dataSource(komp2DataSource())%0A//                .packages(%22org.mousephenotype.cda.db%22)%0A//                .persistenceUnit(%22komp2%22)%0A//                .build();%0A//    %7D%0A//%0A//    @Bean(name = %22sessionFactoryHibernate%22)%0A//    public LocalSessionFactoryBean sessionFactoryHibernate() %7B%0A//        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();%0A//        sessionFactory.setDataSource(komp2DataSource());%0A//        sessionFactory.setPackagesToScan(%22org.mousephenotype.cda.db%22);%0A//        return sessionFactory;%0A//    %7D%0A//%0A//    @Bean(name = %22sessionFactoryHibernate%22)%0A//    @Primary%0A//    public SessionFactory getSessionFactory() %7B%0A//%0A//        LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(komp2DataSource());%0A//        sessionBuilder.scanPackages(%22org.mousephenotype.cda.db.entity%22);%0A//        sessionBuilder.scanPackages(%22org.mousephenotype.cda.db.pojo%22);%0A//%0A//        return sessionBuilder.buildSessionFactory();%0A//    %7D%0A%0A    @Bean(name = %22komp2DataSource%22)%0A    @Primary%0A    public DataSource komp2DataSource() %7B%0A        return getConfiguredDatasource(komp2Url, komp2Username, komp2Password);%0A    %7D%0A
 %7D

Remove deplicate datasource definition