From 62a1b44f130d55254ae69c7ff99a508b0079c92e Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Sun, 14 Apr 2013 19:30:27 -0400 Subject: [PATCH] Avoids state changes on cascading command updates .. when a new query changes the state, and the record command is reset due to the new search, the reset process should not trigger yet another state change --- .../com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java | 10 ++++++---- .../pz2utils4jsf/pazpar2/commands/Pazpar2Command.java | 17 +++++++++-------- .../pazpar2/commands/Pazpar2Commands.java | 8 ++++++++ .../pz2utils4jsf/pazpar2/commands/ShowCommand.java | 1 + .../pz2utils4jsf/pazpar2/state/StateManager.java | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index 65706a9..d948152 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -34,6 +34,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { private static final long serialVersionUID = 3440277287081557861L; private static Logger logger = Logger.getLogger(Pz2Bean.class); + private static Logger responseLogger = Logger.getLogger("com.indexdata.pz2utils4jsf.pazpar2.responses"); protected SearchClient searchClient = null; @@ -94,9 +95,10 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { public void doSearch() { stateMgr.hasPendingStateChange("search",false); pzresp.reset(); - // TODO: avoid state proliferation here: - pzreq.getRecord().removeParameters(); - pzreq.getShow().setParameter(new CommandParameter("start","=",0)); + // resets some record and show command parameters without + // changing state or creating state change feedback + pzreq.getRecordInState().removeParametersSilently(); + pzreq.getShowInState().setParameterSilently(new CommandParameter("start","=",0)); logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommandReadOnly("search").getUrlEncodedParameterValue("query")); doCommand("search"); } @@ -140,7 +142,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { for (CommandThread thread : threadList) { String commandName = thread.getCommand().getName(); String response = thread.getResponse(); - logger.debug("Response was: " + response); + responseLogger.debug("Response was: " + response); Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(response); pzresp.put(commandName, responseObject); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java index 296f2ef..97be62d 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java @@ -40,14 +40,14 @@ public class Pazpar2Command implements CommandReadOnly, Serializable { } public void setParameter (CommandParameter parameter) { - logger.debug("Setting parameter " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName()); + logger.debug(name + " setting parameter " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName()); parameters.put(parameter.getName(),parameter); stateMgr.checkIn(this); } public void setParameters (CommandParameter... params) { for (CommandParameter param : params) { - logger.debug("Setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName()); + logger.debug(name + " setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName()); parameters.put(param.getName(),param); } stateMgr.checkIn(this); @@ -55,7 +55,7 @@ public class Pazpar2Command implements CommandReadOnly, Serializable { public void setParameterSilently (CommandParameter parameter) { - logger.debug("Setting parameter silently " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName()); + logger.debug(name + " setting parameter silently " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName()); parameters.put(parameter.getName(),parameter); } @@ -74,6 +74,11 @@ public class Pazpar2Command implements CommandReadOnly, Serializable { stateMgr.checkIn(this); } + public void removeParametersSilently() { + parameters = new HashMap(); + } + + public boolean hasParameters () { return (parameters.keySet().size()>0); } @@ -131,9 +136,5 @@ public class Pazpar2Command implements CommandReadOnly, Serializable { public String getSession() { return getParameterValue("session"); - } - - - - + } } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Commands.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Commands.java index f1ed7f6..b91b0c6 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Commands.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Commands.java @@ -63,10 +63,18 @@ public class Pazpar2Commands implements Serializable { return (ShowCommand) (stateMgr.checkOut(SHOW)); } + public ShowCommand getShowInState () { + return (ShowCommand) (stateMgr.getCurrentState().getCommand(SHOW)); + } + public RecordCommand getRecord() { return (RecordCommand) (stateMgr.checkOut(RECORD)); } + public RecordCommand getRecordInState() { + return (RecordCommand)stateMgr.getCurrentState().getCommand(RECORD); + } + public TermlistCommand getTermlist() { return (TermlistCommand) (stateMgr.checkOut(TERMLIST)); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java index 12347c6..b783529 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java @@ -8,6 +8,7 @@ public class ShowCommand extends Pazpar2Command { public ShowCommand(StateManager stateMgr) { super("show",stateMgr); + setParameterSilently(new CommandParameter("start","=","0")); } /** diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/state/StateManager.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/state/StateManager.java index 618d880..3c09920 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/state/StateManager.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/state/StateManager.java @@ -89,7 +89,7 @@ public class StateManager implements Serializable { logger.debug("Getting " + commandName + " from state manager."); return getCurrentState().getCommand(commandName).copy(); } - + public CommandReadOnly getCommand (String commandName) { return getCurrentState().getCommand(commandName); } -- 1.7.10.4