package uk.ac.ebi.quickgo.solr.indexing.service.annotation;

import java.io.IOException;
import java.util.Collection;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.stereotype.Service;

import uk.ac.ebi.quickgo.solr.indexing.Indexer;
import uk.ac.ebi.quickgo.solr.model.annotation.GOAnnotation;
import uk.ac.ebi.quickgo.solr.server.SolrServerProcessor;

/**
 * Index Annotation objects in Solr
 * 
 * @author cbonill
 * 
 */
@Service("annotationIndexer")
public class AnnotationIndexer implements Indexer<GOAnnotation> {

	private SolrServerProcessor solrServerProcessor;

	// Log
	private static final Logger logger = LoggerFactory.getLogger(AnnotationIndexer.class);

	/**
	 * See {@link Indexer#index(List)}
	 */
	public void index(List<GOAnnotation> list) {
		Collection<GOAnnotation> annotationBeans = mapBeans(list);

		try {
			solrServerProcessor.indexBeansAutoCommit(annotationBeans);
		} catch (SolrServerException | IOException e) {
			logger.error(e.getMessage());
		}
	}

	/**
	 * Map Annotations to Solr objects
	 */
	private Collection<GOAnnotation> mapBeans(List<GOAnnotation> annotations) {
		// Iterate over all the annotations and convert them into Solr objects to be indexed
		for (GOAnnotation annotation : annotations) {
			annotation.setDocType(GOAnnotation.SolrAnnotationDocumentType.ANNOTATION.getValue());
		}
		return annotations;
	}

	/**
	 * Deletes everything from the schema
	 * @throws SolrServerException
	 * @throws IOException
	 */
	public void deleteAll() throws SolrServerException, IOException{
		solrServerProcessor.deleteAll();		
	}
	
	public void setSolrServerProcessor(SolrServerProcessor solrServerProcessor) {
		this.solrServerProcessor = solrServerProcessor;
	}
}

@@ -520,25 +520,24 @@
  in Solr%0D%0A *
- 
 %0D%0A * @author
@@ -548,17 +548,16 @@
 nill%0D%0A *
- 
 %0D%0A */%0D%0A@
@@ -906,16 +906,18 @@
 t) %7B%0D%0A%09%09
+//
 Collecti
@@ -1023,31 +1023,20 @@
 oCommit(
-annotationBeans
+list
 );%0D%0A%09%09%7D 
@@ -1176,16 +1176,18 @@
 %0D%0A%09 */%0D%0A
+//
 %09private
@@ -1252,24 +1252,26 @@
 tations) %7B%0D%0A
+//
 %09%09// Iterate
@@ -1346,16 +1346,18 @@
 ndexed%0D%0A
+//
 %09%09for (G
@@ -1397,16 +1397,18 @@
 ons) %7B%0D%0A
+//
 %09%09%09annot
@@ -1489,21 +1489,25 @@
 ue());%0D%0A
+//
 %09%09%7D%0D%0A
+//
 %09%09return
@@ -1521,16 +1521,18 @@
 tions;%0D%0A
+//
 %09%7D%0D%0A%0D%0A%09/
@@ -1744,17 +1744,14 @@
 l();
-%09%09
 %0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09p

Remove the mapBeans method as this is done in the calling class now.