package org.mousephenotype.cda.solr.service;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mousephenotype.cda.db.dao.PhenotypePipelineDAO;
import org.mousephenotype.cda.db.dao.PhenotypePipelineDAOImpl;
import org.mousephenotype.cda.solr.TestConfigSolr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import javax.validation.constraints.NotNull;
import java.util.*;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.FacetField.Count;
import org.springframework.transaction.PlatformTransactionManager;

import java.util.Map;


@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {TestConfigSolr.class} )
@TestPropertySource("file:${user.home}/configfiles/${profile:dev}/application.properties")
public class ExpressionServiceTest {


	@Autowired
	private ExpressionService expressionService;

	@Autowired
	ExperimentService experimentService;


	@Test
	public void getLacDataForAnatomogram() {

		expressionService.initialiseAbnormalOntologyMaps();
		String geneAccession = "MGI:1922730";
		try {
			List<Count> parameterCounts = expressionService.getLaczCategoricalParametersForGene(geneAccession);
			List<AnatomogramDataBean> beans = expressionService.getAnatomogramDataBeans(parameterCounts);
			for (AnatomogramDataBean bean : beans) {
				System.out.println("AnatomogramDataBean" + bean);
			}


			Map<String, Long> anatomogramDataBeans = expressionService.getLacSelectedTopLevelMaCountsForAnatomogram(beans);
			for (String topMa : anatomogramDataBeans.keySet()) {
				System.out.println("topMa=" + topMa + " total count " + anatomogramDataBeans.get(topMa));
			}

		} catch (SolrServerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Test
	public void getDataForAnatomyPage() throws SolrServerException {
		expressionService.getFacets("MA:0000004");
	}


}

@@ -136,1976 +136,429 @@
 lrj.
-impl.HttpSolrServer;%0Aimport org.apache.solr.client.solrj.response.QueryResponse;%0Aimport org.hibernate.SessionFactory;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mousephenotype.cda.db.dao.PhenotypePipelineDAO;%0Aimport org.mousephenotype.cda.db.dao.PhenotypePipelineDAOImpl;%0Aimport org.mousephenotype.cda.solr.TestConfigSolr;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.beans.factory.annotation.Value;%0Aimport org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;%0Aimport org.springframework.boot.context.properties.ConfigurationProperties;%0Aimport org.springframework.boot.test.SpringApplicationConfiguration;%0Aimport org.springframework.context.annotation.*;%0Aimport org.springframework.context.support.PropertySourcesPlaceholderConfigurer;%0Aimport org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;%0Aimport org.springframework.orm.hibernate4.HibernateTransactionManager;%0Aimport org.springframework.orm.hibernate4.LocalSessionFactoryBean;%0Aimport org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;%0Aimport org.springframework.orm.jpa.JpaTransactionManager;%0Aimport org.springframework.orm.jpa.JpaVendorAdapter;%0Aimport org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;%0Aimport org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;%0Aimport org.springframework.test.context.ContextConfiguration;%0Aimport org.springframework.test.context.TestPropertySource;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0Aimport org.springframework.test.context.support.AnnotationConfigContextLoader;%0A%0Aimport javax.persistence.EntityManagerFactory;%0Aimport javax.sql.DataSource;%0Aimport javax.validation.constraints.NotNull;%0Aimport java.util.*;%0A%0Aimport org.apache.solr.client.solrj.SolrServerException;%0Aimport org.apache.solr.client.solrj.response.FacetField.Count;%0Aimport org.springframework.transaction.PlatformTransactionManager;%0A
+response.FacetField.Count;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mousephenotype.cda.solr.TestConfigSolr;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.test.SpringApplicationConfiguration;%0Aimport org.springframework.test.context.TestPropertySource;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0A%0Aimport java.util.List;
 %0Aimp
@@ -682,17 +682,16 @@
 r.class%7D
- 
 )%0A@TestP
@@ -1693,46 +1693,8 @@
 ) %7B%0A
-%09%09%09// TODO Auto-generated catch block%0A
 %09%09%09e

clean up code and organise imports