Skip to content
Snippets Groups Projects
Commit e2c6257f authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

working, sorted doBioLookup!

parent 5aac4c93
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ import java.util.ArrayList; ...@@ -12,7 +12,7 @@ import java.util.ArrayList;
* https://stackoverflow.com/questions/2697182/how-to-use-an-array-list * 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 { ...@@ -142,4 +142,10 @@ public class TaxonNode implements Serializable {
s += String.format("%-20s%d\n", "Count:", childrenCount); s += String.format("%-20s%d\n", "Count:", childrenCount);
return s; return s;
} }
@Override
public int compareTo(TaxonNode o) {
// TODO Auto-generated method stub
return 0;
}
} }
...@@ -16,9 +16,8 @@ public class Director extends HttpServlet { ...@@ -16,9 +16,8 @@ public class Director extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException { public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
RequestDispatcher view = null; RequestDispatcher view = null;
String req = getUrlDoPortion(request); String req = getUrlDoPortion(request);
//if (req == "doBioLookup.do") if (req.equals("doBioLookup.do"))
view = request.getRequestDispatcher("bioresult.jsp"); view = request.getRequestDispatcher("bioresult.jsp");
request.setAttribute("url", req);
//RequestDispatcher view = request.getRequestDispatcher("histogram.jsp"); //RequestDispatcher view = request.getRequestDispatcher("histogram.jsp");
view.forward(request, response); view.forward(request, response);
......
<%@page import="org.json.simple.JSONArray"%> <%@page import="org.json.simple.JSONArray"%>
<%@page import="sort.MergeSort"%>
<%@page import="sort.GeneralCompare"%>
<%@page import="org.json.simple.parser.JSONParser"%> <%@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" %> <%@ 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"); TrawlExpert te = (TrawlExpert)request.getServletContext().getAttribute("trawl");
Iterable<TaxonNode> txNodes = te.getTaxonRecord(2).getChildren();
JSONParser parser = new JSONParser(); 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(); JSONObject js = new JSONObject();
JSONArray taxonIds = new JSONArray(); JSONArray taxonIds = new JSONArray();
JSONArray names = new JSONArray(); JSONArray names = new JSONArray();
for (TaxonNode tx: txNodes){ taxonIds.add(-1);
names.add("Any");
for (TaxonNode tx: txNodesAr){
taxonIds.add(tx.getTaxonId()); taxonIds.add(tx.getTaxonId());
names.add(tx.getName()); names.add(tx.getName());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment