*/\r
public String update (String commands) {\r
if (! hasConfigurationErrors()) {\r
- if (hasQuery()) {\r
- handleQueryStateChanges(commands);\r
- logger.debug("Processing request for " + commands); \r
- List<CommandThread> threadList = new ArrayList<CommandThread>();\r
- StringTokenizer tokens = new StringTokenizer(commands,",");\r
- while (tokens.hasMoreElements()) { \r
- threadList.add(new CommandThread(pzreq.getCommandReadOnly(tokens.nextToken()),searchClient)); \r
- }\r
- for (CommandThread thread : threadList) {\r
- thread.start();\r
- }\r
- for (CommandThread thread : threadList) {\r
- try {\r
- thread.join();\r
- } catch (InterruptedException e) {\r
- e.printStackTrace();\r
+ if (commandsAreValid(commands)) {\r
+ if (hasQuery()) {\r
+ handleQueryStateChanges(commands);\r
+ logger.debug("Processing request for " + commands); \r
+ List<CommandThread> threadList = new ArrayList<CommandThread>();\r
+ StringTokenizer tokens = new StringTokenizer(commands,",");\r
+ while (tokens.hasMoreElements()) { \r
+ threadList.add(new CommandThread(pzreq.getCommandReadOnly(tokens.nextToken()),searchClient)); \r
}\r
- }\r
- for (CommandThread thread : threadList) {\r
- String commandName = thread.getCommand().getName();\r
- String response = thread.getResponse();\r
- responseLogger.debug("Response was: " + response);\r
- Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(response);\r
- pzresp.put(commandName, responseObject); \r
- }\r
- if (commands.equals("record")) {\r
- logger.debug("Record: Active clients: "+pzresp.getRecord().getActiveClients());\r
- return pzresp.getRecord().getActiveClients();\r
+ for (CommandThread thread : threadList) {\r
+ thread.start();\r
+ }\r
+ for (CommandThread thread : threadList) {\r
+ try {\r
+ thread.join();\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ for (CommandThread thread : threadList) {\r
+ String commandName = thread.getCommand().getName();\r
+ String response = thread.getResponse();\r
+ responseLogger.debug("Response was: " + response);\r
+ Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(response);\r
+ pzresp.put(commandName, responseObject); \r
+ }\r
+ if (commands.equals("record")) {\r
+ logger.debug("Record: Active clients: "+pzresp.getRecord().getActiveClients());\r
+ return pzresp.getRecord().getActiveClients();\r
+ } else {\r
+ return pzresp.getActiveClients();\r
+ } \r
} else {\r
- return pzresp.getActiveClients();\r
- } \r
+ logger.debug("Skipped requests for " + commands + " as there's not yet a query."); \r
+ pzresp.reset();\r
+ return "0";\r
+ }\r
} else {\r
- logger.debug("Skipped requests for " + commands + " as there's not yet a query."); \r
- pzresp.reset();\r
+ logger.error("Did not attemt to run command(s) due to a validation error.");\r
return "0";\r
}\r
- } else {\r
+ } else { \r
logger.error("Did not attempt to execute query since there are configuration errors.");\r
return "0";\r
}\r
\r
}\r
+ \r
+ public boolean commandsAreValid(String commands) {\r
+ if (commands.equals("record")) {\r
+ if (!pzreq.getCommandReadOnly("record").hasParameterSet("id")) {\r
+ logger.error("Attempt to send record command without the id parameter");\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ }\r
\r
public String toggleRecord (String recId) {\r
if (hasRecord(recId)) {\r
if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { \r
logger.debug("Found pending record ID change. Doing record before updating " + commands);\r
stateMgr.hasPendingStateChange("record",false);\r
- if (pzreq.getCommandReadOnly("record").hasParameters()) {\r
+ if (pzreq.getCommandReadOnly("record").hasParameterSet("id")) {\r
update("record");\r
} else { \r
pzresp.put("record", new RecordResponse());\r
commands.put(Pazpar2Commands.RECORD, new RecordCommand(mgr));\r
commands.put(Pazpar2Commands.TERMLIST, new TermlistCommand(mgr));\r
commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand(mgr)); \r
- key = "#initial";\r
+ key = "#1";\r
}\r
\r
/**\r
*/\r
public String getKey() {\r
if (key == null) {\r
- StringBuilder querystatebuilder = new StringBuilder("#");\r
+ StringBuilder querystatebuilder = new StringBuilder("");\r
for (Pazpar2Command command : commands.values()) {\r
if (command.hasParameters()) {\r
querystatebuilder.append("||"+command.getName()+"::");\r
querystatebuilder.append(command.getValueWithExpressions());\r
} \r
} \r
- key = querystatebuilder.toString();\r
+ key = "#"+querystatebuilder.toString().hashCode();\r
return key;\r
} else { \r
return key;\r
states.put(state.getKey(), state);\r
currentKey = state.getKey();\r
hasPendingStateChange(command.getName(),new Boolean(true)); \r
- logger.debug("Updating listeners with state change from " + command);\r
+ logger.debug("Updating " + listeners.size() + " listener(s) with state change from " + command);\r
updateListeners(command.getName()); \r
} else {\r
logger.debug("Command " + command.getName() + " not found to change the state [" + command.getEncodedQueryString() + "]");\r
logger.debug("setCurrentStateKey: no key change detected");\r
} else {\r
logger.debug("State key change. Was: [" + currentKey + "]. Will be ["+key+"]");\r
- if (states.get(key).getCommand("search").equals(states.get(currentKey).getCommand("search"))) {\r
- logger.debug("No search change detected");\r
+ if (states.get(key)==null) {\r
+ logger.error("The back-end received an unknow state key."); \r
} else {\r
- hasPendingStateChange("search",true);\r
- }\r
- if (states.get(key).getCommand("record").equals(states.get(currentKey).getCommand("record"))) {\r
- logger.debug("No record change detected");\r
- } else {\r
- hasPendingStateChange("record",true);\r
- }\r
- currentKey = key;\r
+ if (states.get(key).getCommand("search").equals(states.get(currentKey).getCommand("search"))) {\r
+ logger.debug("No search change detected");\r
+ } else {\r
+ hasPendingStateChange("search",true);\r
+ }\r
+ if (states.get(key).getCommand("record").equals(states.get(currentKey).getCommand("record"))) {\r
+ logger.debug("No record change detected");\r
+ } else {\r
+ hasPendingStateChange("record",true);\r
+ }\r
+ currentKey = key;\r
+ } \r
}\r
}\r
\r