package org.geneontology.minerva.server.external;

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

import org.bbop.golr.java.RetrieveGolrBioentities;
import org.bbop.golr.java.RetrieveGolrBioentities.GolrBioentityDocument;

public class GolrExternalLookupService implements ExternalLookupService {
	
	private final RetrieveGolrBioentities client;
	
	public GolrExternalLookupService(String golrUrl) {
		this(new RetrieveGolrBioentities(golrUrl, 2));
	}
	
	protected GolrExternalLookupService(RetrieveGolrBioentities client) {
		this.client = client;
	}

	@Override
	public List<LookupEntry> lookup(String id) {
		List<LookupEntry> result = new ArrayList<LookupEntry>();
		try {
			List<GolrBioentityDocument> bioentites = client.getGolrBioentites(id);
			if (bioentites != null && !bioentites.isEmpty()) {
				result = new ArrayList<ExternalLookupService.LookupEntry>(bioentites.size());
				for(GolrBioentityDocument doc : bioentites) {
					result.add(new LookupEntry(doc.bioentity, doc.bioentity_label, doc.type, doc.taxon));
				}
			}
		}
		catch(IOException exception) {
			return null;
		}
		return result;
	}

	@Override
	public LookupEntry lookup(String id, String taxon) {
		throw new RuntimeException("This method is not implemented.");
	}

}

@@ -72,16 +72,37 @@
 eption;%0A
+import java.net.URI;%0A
 import j
@@ -145,16 +145,48 @@
 .List;%0A%0A
+import org.apache.log4j.Logger;%0A
 import o
@@ -378,16 +378,104 @@
 ice %7B%0A%09%0A
+%09private final static Logger LOG = Logger.getLogger(GolrExternalLookupService.class);%0A%09%0A
 %09private
@@ -512,16 +512,42 @@
  client;
+%0A%0A%09private String golrUrl;
 %0A%09%0A%09publ
@@ -639,17 +639,186 @@
 rUrl, 2)
-)
+%7B%0A%0A%09%09%09@Override%0A%09%09%09protected void logRequest(URI uri) %7B%0A%09%09%09%09if(LOG.isDebugEnabled()) %7B%0A%09%09%09%09%09LOG.debug(%22Golr request: %22+uri);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09%0A%09%09%7D);%0A%09%09this.golrUrl = golrUrl
 ;%0A%09%7D%0A%09%0A%09
@@ -1438,16 +1438,138 @@
 tion) %7B%0A
+%09%09%09if (LOG.isDebugEnabled()) %7B%0A%09%09%09%09LOG.debug(%22Error during retrieval for id: %22+id+%22 GOLR-URL: %22+golrUrl, exception);%0A%09%09%09%7D%0A
 %09%09%09retur

add debug messages for GOLR lookups