From 913968b04f505acf837648e1e1b1a3b23459741d Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Wed, 29 Dec 2021 01:10:54 -0700 Subject: [PATCH] Search facility exception handling --- doc/release.txt | 2 +- .../antweb/search/AdvancedSearch.java | 6 ++-- .../antweb/search/AdvancedSearchAction.java | 8 ++--- .../antweb/search/GenericSearch.java | 25 ++++++++------- .../antweb/util/UtilDataAction.java | 31 +++++++++++++------ 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/doc/release.txt b/doc/release.txt index 7f3f3084..a17bec73 100755 --- a/doc/release.txt +++ b/doc/release.txt @@ -1,5 +1,5 @@ Release 8.68.2 - Exception handling refinement in specimen upload. + Exception handling refinement in specimen upload and search facility. New profileQuery system. manager class reload tuning. diff --git a/src/org/calacademy/antweb/search/AdvancedSearch.java b/src/org/calacademy/antweb/search/AdvancedSearch.java index b3978a4e..d693a312 100755 --- a/src/org/calacademy/antweb/search/AdvancedSearch.java +++ b/src/org/calacademy/antweb/search/AdvancedSearch.java @@ -111,7 +111,7 @@ public class AdvancedSearch extends GenericSearch implements Serializable { public static String s_query = null; - protected ArrayList createInitialResults() throws SearchException { + protected ArrayList createInitialResults() throws SearchException, SQLException { int sufficientCriteria = 3; // We expect to receive status and family so have 2 already by default. If family @@ -391,7 +391,7 @@ protected ArrayList createInitialResults() throws SearchException { } catch (SQLException e) { s_log.error("createInitialResults() e:" + e + " query:" + theQuery); //AntwebUtil.logShortStackTrace(e, 18); - return null; + throw e; } } @@ -408,7 +408,7 @@ public static String getQuery() { add status to specimen */ - public void setResults() throws SearchException { + public void setResults() throws SearchException, SQLException { // first do a big search getting images, types, and the validity // then for the invalid ones - do another search to get the valid names // put all of these in an array diff --git a/src/org/calacademy/antweb/search/AdvancedSearchAction.java b/src/org/calacademy/antweb/search/AdvancedSearchAction.java index 5fdad737..7055f953 100755 --- a/src/org/calacademy/antweb/search/AdvancedSearchAction.java +++ b/src/org/calacademy/antweb/search/AdvancedSearchAction.java @@ -99,7 +99,7 @@ private void addToSearch(StringBuffer sb, String field, String value, String sea } // This is a method called by ObjectMapDb. Used on geolocale pages. - public Map getGoogleMap(String country, String adm1, String resultRank, String output, Connection connection) { + public Map getGoogleMap(String country, String adm1, String resultRank, String output, Connection connection) throws SQLException { //A.log("getGoogleMapFunction() country:" + country + " adm1:" + adm1 + " resultRank:" + resultRank + " output:" + output); SearchParameters searchParameters = new SearchParameters(); searchParameters.setFamily(Family.FORMICIDAE); @@ -130,7 +130,7 @@ public Map getGoogleMap(String country, String adm1, String resultRank, String o } // This is a method called by ObjectMapDb. Used on museum pages. - public Map getGoogleMap(Museum museum, String resultRank, String output, Connection connection) { + public Map getGoogleMap(Museum museum, String resultRank, String output, Connection connection) throws SQLException { String museumCode = museum.getCode(); //A.log("getGoogleMapFunction() country:" + country + " adm1:" + adm1 + " resultRank:" + resultRank + " output:" + output); SearchParameters searchParameters = new SearchParameters(); @@ -161,7 +161,7 @@ public Map getGoogleMap(Museum museum, String resultRank, String output, Connect } // This is a method called by ObjectMapDb. Used on group pages. - public Map getGoogleMap(Group group, String resultRank, String output, Connection connection) { + public Map getGoogleMap(Group group, String resultRank, String output, Connection connection) throws SQLException { int groupId = group.getId(); //A.log("getGoogleMap() groupId:" + groupId + " resultRank:" + resultRank + " output:" + output); SearchParameters searchParameters = new SearchParameters(); @@ -226,7 +226,7 @@ public ArrayList getSearchResults(HttpServletRequest request, // This version is used internally, for instance to create the geolocale maps. (Object_Maps table) public ArrayList getSearchResults(Connection connection, SearchParameters searchParameters) - throws IOException, ServletException, SearchException { + throws IOException, ServletException, SearchException, SQLException { // s_log.warn("getSearchResults()"); AdvancedSearchResults results = new AdvancedSearchResults(); diff --git a/src/org/calacademy/antweb/search/GenericSearch.java b/src/org/calacademy/antweb/search/GenericSearch.java index ece40565..c8f54ef4 100755 --- a/src/org/calacademy/antweb/search/GenericSearch.java +++ b/src/org/calacademy/antweb/search/GenericSearch.java @@ -36,7 +36,7 @@ public class GenericSearch implements Serializable { protected ArrayList results; protected Pattern inQuotes = Pattern.compile("(\".*?\")"); - public ArrayList getResults() throws SearchException { + public ArrayList getResults() throws SearchException, SQLException { if (results == null) { setResults(); @@ -46,7 +46,7 @@ public ArrayList getResults() throws SearchException { return results; } - public void setResults() throws SearchException { + public void setResults() throws SearchException, SQLException { //A.log("GenericSearch.setResults()"); // first do a big search getting images, types, and the validity // then for the invalid ones - do another search to get the valid names @@ -85,7 +85,7 @@ public void setResults() throws SearchException { } - protected ArrayList filterByProject(ArrayList currentList, String project) { + protected ArrayList filterByProject(ArrayList currentList, String project) throws SQLException { //A.log("GenericSearch.filterByProject() project:" + project); if ((project == null) || (project.length() <= 0) @@ -149,7 +149,7 @@ protected ArrayList filterByProject(ArrayList currentLis return theList; } catch (SQLException e) { s_log.error("filterByProject() query:" + theQuery + " " + e); - return null; + throw e; } finally { DBUtil.close(stmt, rset, this, "filterByProject()"); } @@ -162,7 +162,7 @@ protected ArrayList filterByProject(ArrayList currentLis // The second pass deals with cases where we don't have the specimen // code. For these, we'll execute a prepared statement // - protected ArrayList setResultTypes(ArrayList currentList, String project) { + protected ArrayList setResultTypes(ArrayList currentList, String project) throws SQLException { //A.log("GenericSearch.setResultTypes() project:" + project); if ((currentList == null) || (currentList.size() == 0)) { @@ -239,6 +239,7 @@ protected ArrayList setResultTypes(ArrayList currentList } catch (SQLException e) { s_log.error("setResultTypes() 1 theQuery:" + theQuery + " e:" + e); org.calacademy.antweb.util.AntwebUtil.logStackTrace(e); + throw e; } finally { DBUtil.close(prepStmt, rset, this, "setResultTypes() 1"); } @@ -289,7 +290,8 @@ protected ArrayList setResultTypes(ArrayList currentList } } catch (SQLException e) { s_log.error("setResultTypes() 2 theQuery:" + theQuery + " e:" + e); - org.calacademy.antweb.util.AntwebUtil.logStackTrace(e); + org.calacademy.antweb.util.AntwebUtil.logShortStackTrace(e); + throw e; } finally { DBUtil.close(stmt, rset, this, "setResultTypes() 2"); } @@ -318,7 +320,7 @@ protected ArrayList setResultTypes(ArrayList currentList return currentList; } - protected ArrayList createInitialResults() throws SearchException { + protected ArrayList createInitialResults() throws SearchException, SQLException { //A.log("GenericSearch.createInitialResults()"); // Need Subspecies logic?! @@ -368,13 +370,13 @@ protected ArrayList createInitialResults() throws SearchException { return getListFromRset(GENERIC, rset, null, theQuery); } catch (SQLException e) { s_log.error("createInitialResults() query:" + theQuery + " e:" + e); - throw new SearchException(e.toString()); + throw e; } finally { DBUtil.close(stmt, rset, this, "createInitialResults()"); } } - protected ArrayList getListFromRset(ResultSet rset, SearchItem synonymousItem, String theQuery, int numToShow) { + protected ArrayList getListFromRset(ResultSet rset, SearchItem synonymousItem, String theQuery, int numToShow) throws SQLException { //A.log("GenericSearch.getListFromRset(rset..)"); ArrayList bigList = getListFromRset(GENERIC, rset, synonymousItem, theQuery); ArrayList smallList = new ArrayList<>(); @@ -395,7 +397,7 @@ protected ArrayList getListFromRset(ResultSet rset, SearchItem synon public static int DESC_EDIT = 5; public static int SEARCH = 6; - protected ArrayList getListFromRset(int searchType, ResultSet rset, SearchItem synonymousItem, String theQuery) { + protected ArrayList getListFromRset(int searchType, ResultSet rset, SearchItem synonymousItem, String theQuery) throws SQLException { //A.log("GenericSearch.getListFromRset(searchType...)"); ArrayList theList = new ArrayList<>(); String family = null; @@ -636,7 +638,8 @@ protected ArrayList getListFromRset(int searchType, ResultSet rset, } } catch (SQLException e) { s_log.error("getListFromRset() e:" + e + " query:" + theQuery); - AntwebUtil.logStackTrace(e); + AntwebUtil.logShortStackTrace(e); + throw e; } // AntwebUtil.logStackTrace(); diff --git a/src/org/calacademy/antweb/util/UtilDataAction.java b/src/org/calacademy/antweb/util/UtilDataAction.java index ae1c9515..e1172a6a 100755 --- a/src/org/calacademy/antweb/util/UtilDataAction.java +++ b/src/org/calacademy/antweb/util/UtilDataAction.java @@ -483,17 +483,28 @@ private OperationDetails doAction(String action, UtilForm form, Login accessLogi } if (action.equals("regenerateAllAntweb")) { - ProjTaxonDb projTaxonDb = (new ProjTaxonDb(connection)); - projTaxonDb.regenerateAllAntweb(); // Proj_taxon records - message = "All Antweb regenerated"; - - /* moved into regen - (new ProjTaxonCountDb(connection)).countCrawl("allantwebants"); // Proj_taxon counts - projTaxonDb.finishRegenerateAllAntweb(); - (new ProjectDb(connection)).updateCounts("allantwebants"); // Project counts - */ - } + ProjTaxonDb projTaxonDb = (new ProjTaxonDb(connection)); + projTaxonDb.regenerateAllAntweb(); // Proj_taxon records + message = "All Antweb regenerated"; + } + + /* + if (action.equals("runCountCrawls")) { + ProjTaxonCountDb projTaxonCountDb = (new ProjTaxonCountDb(connection)); + projTaxonCountDb.countCrawl("allantwebants"); // Proj_taxon counts + //projTaxonDb.finishRegenerateAllAntweb(); + //projTaxonDb.updateCounts("allantwebants"); // Project counts + + BioregionTaxonCountDb bioregionTaxonCountDb = (new BioregionTaxonCountDb(connection)); + bioregionTaxonCountDb.childrenCountCrawl(); + GeolocaleTaxonCountDb geolocaleTaxonCountDb = (new GeolocaleTaxonCountDb(connection)); + geolocaleTaxonCountDb.childrenCountCrawl(num); + + MuseumTaxonCountDb museumTaxonCountDb = (new MuseumTaxonCountDb(connection)); + museumTaxonCountDb.childrenCountCrawl(); + } +*/ // ---------- Count Crawls ------------------------- // https://antweb-stg/utilData.do?action=geolocaleTaxonCountCrawl&num=392 if (action.equals("geolocaleTaxonCountCrawl")) {