import com.indexdata.mkjsf.errors.ErrorHelper;\r
import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
+import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
import com.indexdata.mkjsf.pazpar2.data.Responses;\r
-import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser;\r
import com.indexdata.mkjsf.pazpar2.state.StateListener;\r
import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
logger.debug("Updating show,stat,termlist,bytarget from pazpar2");\r
return update("show,stat,termlist,bytarget");\r
}\r
+ \r
+ public boolean validateUpdateRequest(String commands) {\r
+ if (errors.hasConfigurationErrors()) {\r
+ logger.error("The command(s) " + commands + " are cancelled due to configuration errors.");\r
+ return false;\r
+ } else if (!commands.equals("search") && pzresp.getSearch().hasApplicationError()) {\r
+ logger.error("The command(s) " + commands + " are cancelled because the latest search command had an error.");\r
+ return false;\r
+ } else if (!commandsAreValid(commands)) {\r
+ logger.debug("The command(s) " + commands + " are cancelled because the were not found to be ready/valid.");\r
+ return false;\r
+ } else if (!hasQuery() && !(commands.equals("record") && pzreq.getCommand("record").hasParameterValue("recordquery"))) {\r
+ logger.debug("The command(s) " + commands + " are held off because there's not yet a query.");\r
+ return false;\r
+ } else {\r
+ return true;\r
+ }\r
+ \r
+ \r
+ }\r
\r
/**\r
* Refreshes the data objects listed in 'commands' from pazpar2\r
* @return Number of activeclients at the time of the 'show' command\r
*/\r
public String update (String commands) {\r
+ logger.info("Request to update: " + commands);\r
try {\r
- if (! errors.hasConfigurationErrors()) {\r
- if (commandsAreValid(commands)) {\r
- if (hasQuery() || (commands.equals("record") && pzreq.getCommand("record").hasParameterValue("recordquery"))) {\r
- handleQueryStateChanges(commands);\r
+ if (! validateUpdateRequest(commands)) {\r
+ return "0";\r
+ } else {\r
+ handleQueryStateChanges(commands);\r
+ if (!commands.equals("search") && pzresp.getSearch().hasApplicationError()) {\r
+ logger.error("The command(s) " + commands + " are cancelled because the latest search command had an error.");\r
+ return "0";\r
+ } else {\r
logger.debug("Processing request for " + commands); \r
List<CommandThread> threadList = new ArrayList<CommandThread>();\r
StringTokenizer tokens = new StringTokenizer(commands,",");\r
return pzresp.getRecord().getActiveClients();\r
} else {\r
return pzresp.getActiveClients();\r
- } \r
- } else {\r
- logger.debug("Skipped requests for " + commands + " as there's not yet a query."); \r
- pzresp.resetSearchResponses();\r
- return "0";\r
+ }\r
}\r
- } else {\r
- logger.debug("Did not attempt to run command(s) that were not ready.");\r
- return "0";\r
- }\r
- } else { \r
- logger.error("Did not attempt to execute query since there are configuration errors.");\r
- return "0";\r
- }\r
+ } \r
} catch (ClassCastException cce) {\r
cce.printStackTrace(); \r
return "";\r
public boolean commandsAreValid(String commands) {\r
if (commands.equals("record")) {\r
if (!pzreq.getCommand("record").hasParameterValue("id")) {\r
- logger.debug("Attempt to send record command without the id parameter");\r
+ logger.debug("Skips sending record command due to lacking id parameter");\r
return false;\r
}\r
}\r
\r
protected void handleQueryStateChanges (String commands) {\r
if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
- logger.debug("Found pending search change. Doing search before updating " + commands); \r
+ logger.info("Triggered search: Found pending search change, doing search before updating " + commands); \r
doSearch();\r
} \r
if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { \r