From e2c6257f11ed0b3a4f74554c306f6f82a5595a1d Mon Sep 17 00:00:00 2001
From: Schankula Christopher <schankuc@mcmaster.ca>
Date: Thu, 29 Mar 2018 12:27:48 -0400
Subject: [PATCH] working, sorted doBioLookup!

---
 src/data/TaxonNode.java            |  8 +++++++-
 src/web/Director.java              |  3 +--
 tomcat/webapps/Trawl/bioresult.jsp | 18 ++++++++++++++----
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/data/TaxonNode.java b/src/data/TaxonNode.java
index a40a599..e73396f 100644
--- a/src/data/TaxonNode.java
+++ b/src/data/TaxonNode.java
@@ -12,7 +12,7 @@ import java.util.ArrayList;
  * https://stackoverflow.com/questions/2697182/how-to-use-an-array-list
  */
 	
-public class TaxonNode implements Serializable {
+public class TaxonNode implements Serializable, Comparable<TaxonNode> {
 	/**
 	 * 
 	 */
@@ -142,4 +142,10 @@ public class TaxonNode implements Serializable {
 		s += String.format("%-20s%d\n", "Count:", childrenCount);
 		return s;
 	}
+
+	@Override
+	public int compareTo(TaxonNode o) {
+		// TODO Auto-generated method stub
+		return 0;
+	}
 }
diff --git a/src/web/Director.java b/src/web/Director.java
index 644210a..daa81d8 100755
--- a/src/web/Director.java
+++ b/src/web/Director.java
@@ -16,9 +16,8 @@ public class Director extends HttpServlet {
 	public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
 		RequestDispatcher view = null;
 		String req = getUrlDoPortion(request);
-	    //if (req == "doBioLookup.do")
+	    if (req.equals("doBioLookup.do"))
 	    		view = request.getRequestDispatcher("bioresult.jsp");
-	    		request.setAttribute("url", req);
 	    
 	    //RequestDispatcher view = request.getRequestDispatcher("histogram.jsp");
 	    view.forward(request, response);
diff --git a/tomcat/webapps/Trawl/bioresult.jsp b/tomcat/webapps/Trawl/bioresult.jsp
index 6eb76d7..cc2a416 100644
--- a/tomcat/webapps/Trawl/bioresult.jsp
+++ b/tomcat/webapps/Trawl/bioresult.jsp
@@ -1,19 +1,29 @@
 <%@page import="org.json.simple.JSONArray"%>
+<%@page import="sort.MergeSort"%>
+<%@page import="sort.GeneralCompare"%>
 <%@page import="org.json.simple.parser.JSONParser"%>
 <%@ page import="java.util.*, data.Record, model.TrawlExpert, search.BST, search.BasicSearchResult, org.json.simple.JSONObject, data.TaxonNode" %>
 <%
 	TrawlExpert te = (TrawlExpert)request.getServletContext().getAttribute("trawl");
-	Iterable<TaxonNode> txNodes = te.getTaxonRecord(2).getChildren();
 	JSONParser parser = new JSONParser();
-	//JSONObject req = (JSONObject) parser.parse(request.getReader().toString());
+	JSONObject req = (JSONObject) parser.parse(request.getReader().readLine());
 	
-	//Integer taxonId = (int) (long) req.get("taxonId");
+	Integer taxonId = (int) (long) req.get("taxid");
+	//System.out.println(taxonId);
+	ArrayList<TaxonNode> txNodes = ((ArrayList<TaxonNode>) te.getTaxonRecord(taxonId).getChildren());
+	TaxonNode[] txNodesAr = txNodes.toArray(new TaxonNode[txNodes.size()]);
+	
+	GeneralCompare<TaxonNode> gc = (tn0, tn1) -> ((TaxonNode) tn0).getName().compareTo(((TaxonNode) tn1).getName());
+	MergeSort.sort(txNodesAr, 0, txNodesAr.length - 1, gc);
 
 	JSONObject js = new JSONObject();
 	JSONArray taxonIds = new JSONArray();
 	JSONArray names    = new JSONArray();
 	
-	for (TaxonNode tx: txNodes){
+	taxonIds.add(-1);
+	names.add("Any");
+	
+	for (TaxonNode tx: txNodesAr){
 		taxonIds.add(tx.getTaxonId());
 		names.add(tx.getName());
 	}
-- 
GitLab