From: Niels Erik G. Nielsen Date: Mon, 13 May 2013 15:57:51 +0000 (-0400) Subject: Prevents automatic show,stat,.. updates on search errors X-Git-Tag: v0.0.7~110 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=753638f22814ee59667015172d8d53c9c9a8e771;p=mkjsf-moved-to-github.git Prevents automatic show,stat,.. updates on search errors --- diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java index 4faef7b..16abd12 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java @@ -25,10 +25,10 @@ import com.indexdata.mkjsf.errors.ErrorCentral; import com.indexdata.mkjsf.errors.ErrorHelper; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands; +import com.indexdata.mkjsf.pazpar2.data.RecordResponse; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; import com.indexdata.mkjsf.pazpar2.data.Responses; -import com.indexdata.mkjsf.pazpar2.data.RecordResponse; import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser; import com.indexdata.mkjsf.pazpar2.state.StateListener; import com.indexdata.mkjsf.pazpar2.state.StateManager; @@ -130,6 +130,26 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria logger.debug("Updating show,stat,termlist,bytarget from pazpar2"); return update("show,stat,termlist,bytarget"); } + + public boolean validateUpdateRequest(String commands) { + if (errors.hasConfigurationErrors()) { + logger.error("The command(s) " + commands + " are cancelled due to configuration errors."); + return false; + } else if (!commands.equals("search") && pzresp.getSearch().hasApplicationError()) { + logger.error("The command(s) " + commands + " are cancelled because the latest search command had an error."); + return false; + } else if (!commandsAreValid(commands)) { + logger.debug("The command(s) " + commands + " are cancelled because the were not found to be ready/valid."); + return false; + } else if (!hasQuery() && !(commands.equals("record") && pzreq.getCommand("record").hasParameterValue("recordquery"))) { + logger.debug("The command(s) " + commands + " are held off because there's not yet a query."); + return false; + } else { + return true; + } + + + } /** * Refreshes the data objects listed in 'commands' from pazpar2 @@ -138,11 +158,16 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria * @return Number of activeclients at the time of the 'show' command */ public String update (String commands) { + logger.info("Request to update: " + commands); try { - if (! errors.hasConfigurationErrors()) { - if (commandsAreValid(commands)) { - if (hasQuery() || (commands.equals("record") && pzreq.getCommand("record").hasParameterValue("recordquery"))) { - handleQueryStateChanges(commands); + if (! validateUpdateRequest(commands)) { + return "0"; + } else { + handleQueryStateChanges(commands); + if (!commands.equals("search") && pzresp.getSearch().hasApplicationError()) { + logger.error("The command(s) " + commands + " are cancelled because the latest search command had an error."); + return "0"; + } else { logger.debug("Processing request for " + commands); List threadList = new ArrayList(); StringTokenizer tokens = new StringTokenizer(commands,","); @@ -182,20 +207,9 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria return pzresp.getRecord().getActiveClients(); } else { return pzresp.getActiveClients(); - } - } else { - logger.debug("Skipped requests for " + commands + " as there's not yet a query."); - pzresp.resetSearchResponses(); - return "0"; + } } - } else { - logger.debug("Did not attempt to run command(s) that were not ready."); - return "0"; - } - } else { - logger.error("Did not attempt to execute query since there are configuration errors."); - return "0"; - } + } } catch (ClassCastException cce) { cce.printStackTrace(); return ""; @@ -212,7 +226,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria public boolean commandsAreValid(String commands) { if (commands.equals("record")) { if (!pzreq.getCommand("record").hasParameterValue("id")) { - logger.debug("Attempt to send record command without the id parameter"); + logger.debug("Skips sending record command due to lacking id parameter"); return false; } } @@ -264,7 +278,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria protected void handleQueryStateChanges (String commands) { if (stateMgr.hasPendingStateChange("search") && hasQuery()) { - logger.debug("Found pending search change. Doing search before updating " + commands); + logger.info("Triggered search: Found pending search change, doing search before updating " + commands); doSearch(); } if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java index 7ab5ec5..2e6ca31 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java @@ -126,7 +126,7 @@ public class Pz2Client implements SearchClient { logger.error(e.getMessage()); e.printStackTrace(); logger.error("Creating error XML"); - commandResponse = new ClientCommandResponse(500,CommandError.createErrorXml(command.getCommandName(), "", "Pazpar2Error", e.getMessage(),""),"text/xml"); + commandResponse = new ClientCommandResponse(0,CommandError.createErrorXml(command.getCommandName(), "", "Pazpar2Error", e.getMessage(),""),"text/xml"); } long end = System.currentTimeMillis(); logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );