import org.apache.log4j.Logger;\r
\r
import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.CommandError;\r
\r
public class CommandThread extends Thread {\r
\r
private static Logger logger = Logger.getLogger(CommandThread.class);\r
- CommandReadOnly command;\r
+ Pazpar2Command command;\r
SearchClient client;\r
private ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
private StringBuilder response = new StringBuilder(""); \r
\r
- public CommandThread (CommandReadOnly command, SearchClient client) {\r
+ public CommandThread (Pazpar2Command command, SearchClient client) {\r
this.command = command;\r
this.client = client;\r
}\r
return response.toString();\r
}\r
\r
- public CommandReadOnly getCommand() {\r
+ public Pazpar2Command getCommand() {\r
return command;\r
}\r
\r
pzresp.reset();\r
// resets some record and show command parameters without \r
// changing state or creating state change feedback\r
- pzreq.getRecordInState().removeParametersSilently(); \r
- pzreq.getShowInState().setParameterSilently(new CommandParameter("start","=",0)); \r
- logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommandReadOnly("search").getUrlEncodedParameterValue("query"));\r
+ pzreq.getRecord().removeParametersInState(); \r
+ pzreq.getShow().setParameterInState(new CommandParameter("start","=",0)); \r
+ logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommand("search").getUrlEncodedParameterValue("query"));\r
doCommand("search"); \r
}\r
\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
+ threadList.add(new CommandThread(pzreq.getCommand(tokens.nextToken()),searchClient)); \r
}\r
for (CommandThread thread : threadList) {\r
thread.start();\r
\r
public boolean commandsAreValid(String commands) {\r
if (commands.equals("record")) {\r
- if (!pzreq.getCommandReadOnly("record").hasParameterSet("id")) {\r
+ if (!pzreq.getCommand("record").hasParameterSet("id")) {\r
logger.error("Attempt to send record command without the id parameter");\r
return false;\r
}\r
\r
@Override\r
public boolean hasRecord (String recId) {\r
- return pzreq.getCommandReadOnly("record").hasParameters() && pzresp.getRecord().getRecId().equals(recId);\r
+ return pzreq.getCommand("record").hasParameters() && pzresp.getRecord().getRecId().equals(recId);\r
}\r
\r
public String getCurrentStateKey () { \r
\r
\r
protected boolean hasQuery() { \r
- return pzreq.getCommandReadOnly("search").hasParameterSet("query"); \r
+ return pzreq.getCommand("search").hasParameterSet("query"); \r
}\r
\r
\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").hasParameterSet("id")) {\r
+ if (pzreq.getCommand("record").hasParameterSet("id")) {\r
update("record");\r
} else { \r
pzresp.put("record", new RecordResponse());\r
}\r
\r
protected String doCommand(String commandName) { \r
- logger.debug(pzreq.getCommandReadOnly(commandName).getEncodedQueryString() + ": Results for "+ pzreq.getCommandReadOnly("search").getEncodedQueryString());\r
+ logger.debug(pzreq.getCommand(commandName).getEncodedQueryString() + ": Results for "+ pzreq.getCommand("search").getEncodedQueryString());\r
return update(commandName);\r
}\r
\r
import com.indexdata.pz2utils4jsf.config.Configuration;\r
import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
public class Pz2Client implements SearchClient {\r
}\r
\r
@Override\r
- public void setSearchCommand(CommandReadOnly command) {\r
+ public void setSearchCommand(Pazpar2Command command) {\r
ClientCommand clientCommand = new ClientCommand(command.getName(), command.getEncodedQueryString());\r
client.setSearchCommand(clientCommand); \r
}\r
\r
@Override\r
- public CommandResponse executeCommand(CommandReadOnly command, ByteArrayOutputStream baos) \r
+ public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) \r
throws Pazpar2ErrorException, IOException {\r
ClientCommand clientCommand = new ClientCommand(command.getName(), command.getEncodedQueryString());\r
Pazpar2HttpResponse pz2HttpResponse = client.executeCommand(clientCommand, baos);\r
public String login(String navigateTo) {\r
logger.info("doing login");\r
((ServiceProxyClient)searchClient).authenticate(user); \r
- pzreq.getRecordInState().removeParametersSilently();\r
- pzreq.getSearchInState().removeParametersSilently();\r
+ pzreq.getRecord().removeParametersInState();\r
+ pzreq.getSearch().removeParametersInState();\r
pzresp.reset();\r
return navigateTo;\r
}\r
public void setServiceProxyUrl(String url) {\r
logger.info("Setting Service Proxy url: " + url);\r
serviceProxyUrl = url;\r
- pzreq.getRecordInState().removeParametersSilently();\r
- pzreq.getSearchInState().removeParametersSilently();\r
+ pzreq.getRecord().removeParametersInState();\r
+ pzreq.getSearch().removeParametersInState();\r
pzresp.reset();\r
}\r
\r
import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
import com.indexdata.pz2utils4jsf.config.Configurable;\r
import com.indexdata.pz2utils4jsf.config.Configuration;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
\r
public interface SearchClient extends Configurable, Serializable {\r
\r
- public void setSearchCommand(CommandReadOnly command);\r
- public CommandResponse executeCommand(CommandReadOnly command, ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException;\r
+ public void setSearchCommand(Pazpar2Command command);\r
+ public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException;\r
public SearchClient cloneMe();\r
public boolean isAuthenticatingClient(); \r
public Configuration getConfiguration();\r
+++ /dev/null
-package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
-\r
-/**\r
- * Interface to Pazpar2Command to be used when the given command\r
- * should not change. Meant to avoid redundant cloning of commands\r
- * for potential state changes. \r
- * \r
- * @author Niels Erik\r
- *\r
- */\r
-public interface CommandReadOnly {\r
-\r
- public String getName();\r
- public String getValueWithExpressions();\r
- public String getEncodedQueryString();\r
- public boolean hasParameters();\r
- public boolean hasParameterSet(String parameterName);\r
- public String getParameterValue(String parameterName);\r
- public String getUrlEncodedParameterValue(String parameterName);\r
- \r
-}\r
\r
import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
\r
-public class Pazpar2Command implements CommandReadOnly, Serializable {\r
+public class Pazpar2Command implements Serializable {\r
\r
private static Logger logger = Logger.getLogger(Pazpar2Command.class);\r
private static final long serialVersionUID = -6825491856480675917L; \r
public Pazpar2Command copy () {\r
Pazpar2Command newCommand = new Pazpar2Command(name,stateMgr);\r
for (String parameterName : parameters.keySet()) {\r
- newCommand.setParameterSilently(parameters.get(parameterName).copy()); \r
+ newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
return newCommand;\r
}\r
}\r
\r
public void setParameter (CommandParameter parameter) {\r
+ Pazpar2Command thisCommand = this.copy();\r
logger.debug(name + " setting parameter " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName());\r
- parameters.put(parameter.getName(),parameter);\r
- stateMgr.checkIn(this);\r
+ thisCommand.parameters.put(parameter.getName(),parameter);\r
+ stateMgr.checkIn(thisCommand);\r
}\r
\r
public void setParameters (CommandParameter... params) {\r
+ Pazpar2Command thisCommand = this.copy();\r
for (CommandParameter param : params) {\r
logger.debug(name + " setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName());\r
- parameters.put(param.getName(),param);\r
+ thisCommand.parameters.put(param.getName(),param);\r
}\r
- stateMgr.checkIn(this);\r
+ stateMgr.checkIn(thisCommand);\r
}\r
\r
- \r
- public void setParameterSilently (CommandParameter parameter) {\r
+ public void setParametersInState (CommandParameter... params) { \r
+ for (CommandParameter param : params) {\r
+ logger.debug(name + " setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName());\r
+ parameters.put(param.getName(),param);\r
+ } \r
+ }\r
+ \r
+ public void setParameterInState (CommandParameter parameter) {\r
logger.debug(name + " setting parameter silently " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName());\r
parameters.put(parameter.getName(),parameter); \r
}\r
}\r
\r
public void removeParameter (String name) {\r
- parameters.remove(name);\r
- stateMgr.checkIn(this);\r
+ Pazpar2Command thisCommand = this.copy();\r
+ thisCommand.parameters.remove(name);\r
+ stateMgr.checkIn(thisCommand);\r
}\r
\r
public void removeParameters() {\r
- parameters = new HashMap<String,CommandParameter>();\r
- stateMgr.checkIn(this);\r
+ Pazpar2Command thisCommand = this.copy();\r
+ thisCommand.parameters = new HashMap<String,CommandParameter>();\r
+ stateMgr.checkIn(thisCommand);\r
}\r
\r
- public void removeParametersSilently() {\r
+ public void removeParametersInState() {\r
parameters = new HashMap<String,CommandParameter>(); \r
}\r
\r
return parameters.toString();\r
}\r
\r
- @Override\r
public String getParameterValue(String parameterName) {\r
return getParameter(parameterName).getValueWithExpressions();\r
\r
}\r
\r
- @Override\r
public String getUrlEncodedParameterValue(String parameterName) {\r
return getParameter(parameterName).getEncodedQueryString();\r
}\r
}\r
\r
public InitCommand getInit() {\r
- return (InitCommand) (stateMgr.checkOut(INIT));\r
+ return (InitCommand) (stateMgr.getCommand(INIT));\r
}\r
\r
public PingCommand getPing() {\r
- return (PingCommand) (stateMgr.checkOut(PING));\r
+ return (PingCommand) (stateMgr.getCommand(PING));\r
}\r
\r
public SettingsCommand getSettings() {\r
- return (SettingsCommand) (stateMgr.checkOut(SETTINGS));\r
+ return (SettingsCommand) (stateMgr.getCommand(SETTINGS));\r
}\r
\r
public SearchCommand getSearch() {\r
- return (SearchCommand) (stateMgr.checkOut(SEARCH));\r
+ return (SearchCommand) (stateMgr.getCommand(SEARCH));\r
}\r
\r
- /**\r
- * Gets a mutable SearchCommand from current state (no checkout)\r
- * Can be used for updating Search parameters without spawning new state.\r
- * @return\r
- */\r
- public SearchCommand getSearchInState() {\r
- return (SearchCommand) (stateMgr.getCurrentState().getCommand(SEARCH));\r
- }\r
-\r
public StatCommand getStat() {\r
- return (StatCommand) (stateMgr.checkOut(STAT));\r
+ return (StatCommand) (stateMgr.getCommand(STAT));\r
}\r
\r
public ShowCommand getShow() {\r
- return (ShowCommand) (stateMgr.checkOut(SHOW));\r
- }\r
- \r
- /**\r
- * Gets a mutable ShowCommand from current state (no checkout)\r
- * Can be used for updating show parameters without spawning new state.\r
- * @return\r
- */\r
- public ShowCommand getShowInState () {\r
- return (ShowCommand) (stateMgr.getCurrentState().getCommand(SHOW));\r
+ return (ShowCommand) (stateMgr.getCommand(SHOW));\r
}\r
- \r
- /**\r
- * Gets a detached (copied) record command from the current state\r
- * \r
- * @return\r
- */\r
+ \r
public RecordCommand getRecord() {\r
- return (RecordCommand) (stateMgr.checkOut(RECORD));\r
+ return (RecordCommand) (stateMgr.getCommand(RECORD));\r
}\r
\r
- /**\r
- * Gets a mutable RecordCommand from current state (no checkout)\r
- * Can be used for updating record parameters without spawning new state.\r
- * @return\r
- */ \r
- public RecordCommand getRecordInState() {\r
- return (RecordCommand)stateMgr.getCurrentState().getCommand(RECORD);\r
- }\r
- \r
- /**\r
- * Gets a detached (copied) termlist command from the current state\r
- * \r
- * @return Mutable termlist command\r
- */\r
public TermlistCommand getTermlist() {\r
- return (TermlistCommand) (stateMgr.checkOut(TERMLIST));\r
+ return (TermlistCommand) (stateMgr.getCommand(TERMLIST));\r
}\r
\r
- /**\r
- * \r
- * @return\r
- */\r
public BytargetCommand getBytarget() {\r
- return (BytargetCommand) (stateMgr.checkOut(BYTARGET));\r
+ return (BytargetCommand) (stateMgr.getCommand(BYTARGET));\r
}\r
\r
public Pazpar2Command getCommand(String name) {\r
- return stateMgr.checkOut(name);\r
- }\r
- \r
- public CommandReadOnly getCommandReadOnly(String name) {\r
return stateMgr.getCommand(name);\r
}\r
- \r
+ \r
}\r
public RecordCommand copy () {\r
RecordCommand newCommand = new RecordCommand(stateMgr);\r
for (String parameterName : parameters.keySet()) {\r
- newCommand.setParameterSilently(parameters.get(parameterName).copy()); \r
+ newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
return newCommand;\r
}\r
public SearchCommand copy () {\r
SearchCommand newCommand = new SearchCommand(stateMgr);\r
for (String parameterName : parameters.keySet()) {\r
- newCommand.setParameterSilently(parameters.get(parameterName).copy()); \r
+ newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
}\r
newCommand.singleTargetFilter = this.singleTargetFilter;\r
return newCommand;\r
\r
public ShowCommand(StateManager stateMgr) {\r
super("show",stateMgr);\r
- setParameterSilently(new CommandParameter("start","=","0"));\r
+ setParameterInState(new CommandParameter("start","=","0"));\r
}\r
\r
/**\r
public int getNum () {\r
return getParameter("num") != null ? Integer.parseInt(getParameter("num").value) : 0;\r
}\r
-\r
-\r
\r
public ShowCommand copy () {\r
ShowCommand newCommand = new ShowCommand(stateMgr);\r
for (String parameterName : parameters.keySet()) {\r
- newCommand.setParameterSilently(parameters.get(parameterName).copy()); \r
+ newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
return newCommand;\r
}\r
import com.indexdata.pz2utils4jsf.pazpar2.CommandResponse;\r
import com.indexdata.pz2utils4jsf.pazpar2.SearchClient;\r
import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly;\r
import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.AuthenticationEntity;\r
import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.ServiceProxyUser;\r
logger.info("Authenticating [" + user.getProperty("name") + "]");\r
this.user = (ServiceProxyUser) user;\r
Pazpar2Command auth = new Pazpar2Command("auth",null);\r
- auth.setParameters(new CommandParameter("action","=","login"), \r
- new CommandParameter("username","=",user.getProperty("name")), \r
- new CommandParameter("password","=",user.getProperty("password")));\r
+ auth.setParametersInState(new CommandParameter("action","=","login"), \r
+ new CommandParameter("username","=",user.getProperty("name")), \r
+ new CommandParameter("password","=",user.getProperty("password")));\r
byte[] response = send(auth);\r
String responseStr = new String(response,"UTF-8");\r
logger.info(responseStr); \r
* @throws ClientProtocolException\r
* @throws IOException\r
*/\r
- private byte[] send(CommandReadOnly command) throws ClientProtocolException, IOException {\r
+ private byte[] send(Pazpar2Command command) throws ClientProtocolException, IOException {\r
String url = serviceUrl + "?" + command.getEncodedQueryString(); \r
logger.info("Sending request "+url); \r
HttpGet httpget = new HttpGet(url); \r
}\r
\r
@Override\r
- public void setSearchCommand(CommandReadOnly command) {\r
+ public void setSearchCommand(Pazpar2Command command) {\r
// Do nothing, Service Proxy is handling this \r
}\r
\r
@Override\r
- public CommandResponse executeCommand(CommandReadOnly command,\r
+ public CommandResponse executeCommand(Pazpar2Command command,\r
ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException {\r
byte[] response = send(command);\r
baos.write(response);\r
\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly;\r
import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
logger.debug("Command " + command.getName() + " not found to change the state [" + command.getEncodedQueryString() + "]");\r
}\r
}\r
- \r
- /**\r
- * Gets a detached copy of a command. For the change manager\r
- * to become aware of any changes to the copy it must be \r
- * checked back in with 'checkIn(Pazpar2Command)'\r
- * \r
- * @param commandName\r
- * @return Copy this state's instance of the given command\r
- */\r
- public Pazpar2Command checkOut (String commandName) {\r
- logger.debug("Getting " + commandName + " from state manager.");\r
- return getCurrentState().getCommand(commandName).copy();\r
- }\r
- \r
- public CommandReadOnly getCommand (String commandName) {\r
+ \r
+ public Pazpar2Command getCommand (String commandName) {\r
return getCurrentState().getCommand(commandName);\r
}\r
\r