From: <hs...@us...> - 2013-06-14 00:29:41
|
Revision: 1103 http://sourceforge.net/p/treebase/code/1103 Author: hshyket Date: 2013-06-14 00:29:39 +0000 (Fri, 14 Jun 2013) Log Message: ----------- Adding exception handling for classification search where ncbi identifier is invalid. Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ClassificationSearchController.java Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ClassificationSearchController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ClassificationSearchController.java 2013-06-06 19:32:24 UTC (rev 1102) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/ClassificationSearchController.java 2013-06-14 00:29:39 UTC (rev 1103) @@ -41,14 +41,28 @@ @SuppressWarnings("unchecked") private Collection<PhyloTree> doSearch( - String searchTerm - ) { - + HttpServletRequest request, + HttpServletResponse response, + BindException errors, + String searchTerm) throws InstantiationException { + Collection<PhyloTree> matches = null; - PhyloTreeService phyloTreeService = getSearchService().getPhyloTreeService(); - matches = phyloTreeService.findTreesByNCBINodes(searchTerm); + PhyloTreeService phyloTreeService = getSearchService().getPhyloTreeService(); + + try { + matches = phyloTreeService.findTreesByNCBINodes(searchTerm); + } + catch ( NumberFormatException e ) { + addMessage(request, "Malformed NCBI identifier '" + searchTerm ); + LOGGER.error("Couldn't parse NCBI identifier: "+e.getMessage()); + } + catch ( NullPointerException e) { + addMessage(request, "NCBI identifier not found '" + searchTerm ); + LOGGER.error("Couldn't find NCBI identifier: "+e.getMessage()); + + } + return matches; - } @Override @@ -59,7 +73,7 @@ CQLParser parser = new CQLParser(); CQLNode root = parser.parse(query); root = normalizeParseTree(root); - HashSet<PhyloTree> queryResults = doCQLQuery(root, new HashSet<PhyloTree>(),request); + HashSet<PhyloTree> queryResults = doCQLQuery(root, new HashSet<PhyloTree>(),request, response, errors); TreeSearchResults tsr = new TreeSearchResults(queryResults); saveSearchResults(request, tsr); @@ -86,10 +100,16 @@ } } - protected HashSet<PhyloTree> doCQLQuery(CQLNode node, HashSet<PhyloTree> results, HttpServletRequest request) { + protected HashSet<PhyloTree> doCQLQuery( + CQLNode node, + HashSet<PhyloTree> results, + HttpServletRequest request, + HttpServletResponse response, + BindException errors + ) throws InstantiationException { if ( node instanceof CQLBooleanNode ) { - HashSet<PhyloTree> resultsLeft = doCQLQuery(((CQLBooleanNode)node).left,results, request); - HashSet<PhyloTree> resultsRight = doCQLQuery(((CQLBooleanNode)node).right,results, request); + HashSet<PhyloTree> resultsLeft = doCQLQuery(((CQLBooleanNode)node).left,results, request, response, errors); + HashSet<PhyloTree> resultsRight = doCQLQuery(((CQLBooleanNode)node).right,results, request, response, errors); if ( node instanceof CQLNotNode ) { for ( PhyloTree rightTree : resultsRight ) { if ( resultsLeft.contains(rightTree) ) @@ -114,7 +134,10 @@ String index = term.getIndex(); if ( index.startsWith("tb.identifier") ) { if ( index.endsWith("ncbi") ) { - results.addAll(doSearch(term.getTerm())); + Collection<PhyloTree> trees = doSearch(request, response, errors, term.getTerm()); + if ( null != trees ) { + results.addAll(trees); + } } else { // issue warnings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |