From 78cce328039810027616b0dfe4fb3362f5b573af Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Wed, 24 Apr 2013 17:10:05 -0400 Subject: [PATCH] Adds SP extensions to Pazpar2 commands and parameters --- .../mkjsf/pazpar2/commands/BytargetCommand.java | 14 +++++++++- .../mkjsf/pazpar2/commands/InitCommand.java | 16 ++++++++++- .../mkjsf/pazpar2/commands/Pazpar2Command.java | 20 ++++++-------- .../mkjsf/pazpar2/commands/PingCommand.java | 14 +++++++++- .../mkjsf/pazpar2/commands/RecordCommand.java | 13 ++++++++- .../mkjsf/pazpar2/commands/SearchCommand.java | 8 +++++- .../mkjsf/pazpar2/commands/SettingsCommand.java | 16 ++++++++++- .../mkjsf/pazpar2/commands/ShowCommand.java | 8 +++++- .../mkjsf/pazpar2/commands/StatCommand.java | 17 +++++++++++- .../mkjsf/pazpar2/commands/TermlistCommand.java | 19 ++++++++++++- .../mkjsf/pazpar2/commands/sp/AuthCommand.java | 29 ++++++++++++++++++++ .../mkjsf/pazpar2/commands/sp/RecordCommandSp.java | 26 ++++++++++++++++++ .../pazpar2/commands/sp/ServiceProxyCommand.java | 5 ++++ .../mkjsf/pazpar2/sp/ServiceProxyClient.java | 10 +++---- 14 files changed, 189 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java create mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java create mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/ServiceProxyCommand.java diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java index 57c66de..7f39b70 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java @@ -1,8 +1,9 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class BytargetCommand extends Pazpar2Command { +public class BytargetCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 9070458716105294392L; @@ -10,4 +11,15 @@ public class BytargetCommand extends Pazpar2Command { super("bytarget",stateMgr); } + public BytargetCommand copy () { + BytargetCommand newCommand = new BytargetCommand(stateMgr); + for (String parameterName : parameters.keySet()) { + newCommand.setParameterInState(parameters.get(parameterName).copy()); + } + return newCommand; + } + + public ServiceProxyCommand getSp() { + return this; + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java index 2ae51a5..144a1a7 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java @@ -1,8 +1,9 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class InitCommand extends Pazpar2Command { +public class InitCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = -4915976465898889987L; @@ -27,5 +28,18 @@ public class InitCommand extends Pazpar2Command { public String getSession () { throw new UnsupportedOperationException("Cannot set or get session id on init command"); } + + public InitCommand copy () { + InitCommand newCommand = new InitCommand(stateMgr); + for (String parameterName : parameters.keySet()) { + newCommand.setParameterInState(parameters.get(parameterName).copy()); + } + return newCommand; + } + + public ServiceProxyCommand getSp() { + return this; + } + } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java index 9a3695b..871eb30 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java @@ -6,29 +6,24 @@ import java.util.Map; import org.apache.log4j.Logger; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class Pazpar2Command implements Serializable { +public abstract class Pazpar2Command implements Serializable { private static Logger logger = Logger.getLogger(Pazpar2Command.class); private static final long serialVersionUID = -6825491856480675917L; - private String name = ""; + protected String name = ""; protected Map parameters = new HashMap(); - StateManager stateMgr; + protected StateManager stateMgr; public Pazpar2Command (String name, StateManager stateMgr) { this.name = name; this.stateMgr = stateMgr; } - public Pazpar2Command copy () { - Pazpar2Command newCommand = new Pazpar2Command(name,stateMgr); - for (String parameterName : parameters.keySet()) { - newCommand.setParameterInState(parameters.get(parameterName).copy()); - } - return newCommand; - } + public abstract Pazpar2Command copy (); public String getName() { return name; @@ -125,7 +120,7 @@ public class Pazpar2Command implements Serializable { } public String getParameterValue(String parameterName) { - return getParameter(parameterName).getValueWithExpressions(); + return getParameter(parameterName)==null ? "" : getParameter(parameterName).getValueWithExpressions(); } @@ -148,4 +143,7 @@ public class Pazpar2Command implements Serializable { logger.info("Command '" + command.getName() + "' not affecting state (history) as no state manager was defined for this command."); } } + + public abstract ServiceProxyCommand getSp(); + } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java index 05c1934..5a75e56 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java @@ -1,8 +1,9 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class PingCommand extends Pazpar2Command { +public class PingCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 8876721711326535847L; @@ -10,4 +11,15 @@ public class PingCommand extends Pazpar2Command { super("ping",stateMgr); } + public PingCommand copy () { + PingCommand newCommand = new PingCommand(stateMgr); + for (String parameterName : parameters.keySet()) { + newCommand.setParameterInState(parameters.get(parameterName).copy()); + } + return newCommand; + } + + public ServiceProxyCommand getSp() { + return this; + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java index 8713ece..028b0d5 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java @@ -1,8 +1,10 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.RecordCommandSp; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class RecordCommand extends Pazpar2Command { +public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 2817539422114569506L; @@ -70,4 +72,13 @@ public class RecordCommand extends Pazpar2Command { } return newCommand; } + + + /** + * Returns a record command object with Service Proxy extension parameters + * + */ + public RecordCommandSp getSp () { + return new RecordCommandSp(this); + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java index 5e4e07b..cae510e 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java @@ -4,10 +4,11 @@ import javax.enterprise.context.SessionScoped; import org.apache.log4j.Logger; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; @SessionScoped -public class SearchCommand extends Pazpar2Command { +public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = -1888520867838597236L; private static Logger logger = Logger.getLogger(SearchCommand.class); @@ -202,4 +203,9 @@ public class SearchCommand extends Pazpar2Command { return newCommand; } + @Override + public ServiceProxyCommand getSp() { + return this; + } + } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java index 55a417e..11d624f 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java @@ -1,8 +1,9 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class SettingsCommand extends Pazpar2Command { +public class SettingsCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 2291179325470387102L; @@ -10,5 +11,18 @@ public class SettingsCommand extends Pazpar2Command { super("settings",stateMgr); // TODO Auto-generated constructor stub } + + public SettingsCommand copy () { + SettingsCommand newCommand = new SettingsCommand(stateMgr); + for (String parameterName : parameters.keySet()) { + newCommand.setParameterInState(parameters.get(parameterName).copy()); + } + return newCommand; + } + + @Override + public ServiceProxyCommand getSp() { + return this; + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java index f9e7931..375f600 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java @@ -1,8 +1,9 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class ShowCommand extends Pazpar2Command { +public class ShowCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = -8242768313266051307L; @@ -99,4 +100,9 @@ public class ShowCommand extends Pazpar2Command { return newCommand; } + @Override + public ServiceProxyCommand getSp() { + return this; + } + } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java index 6b885bc..0243315 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java @@ -1,13 +1,28 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class StatCommand extends Pazpar2Command { +public class StatCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 3980630346114157336L; public StatCommand(StateManager stateMgr) { super("stat",stateMgr); } + + public StatCommand copy () { + StatCommand newCommand = new StatCommand(stateMgr); + for (String parameterName : parameters.keySet()) { + newCommand.setParameterInState(parameters.get(parameterName).copy()); + } + return newCommand; + } + + @Override + public ServiceProxyCommand getSp() { + return this; + } + } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java index 3188b64..bc3e8c2 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java @@ -1,8 +1,9 @@ package com.indexdata.mkjsf.pazpar2.commands; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.state.StateManager; -public class TermlistCommand extends Pazpar2Command { +public class TermlistCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = -7067878552863021727L; @@ -25,4 +26,20 @@ public class TermlistCommand extends Pazpar2Command { public String getNum () { return getParameterValue("num"); } + + public TermlistCommand copy () { + TermlistCommand newCommand = new TermlistCommand(stateMgr); + for (String parameterName : parameters.keySet()) { + newCommand.setParameterInState(parameters.get(parameterName).copy()); + } + return newCommand; + } + + @Override + public ServiceProxyCommand getSp() { + return this; + } + + + } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java new file mode 100644 index 0000000..698f265 --- /dev/null +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java @@ -0,0 +1,29 @@ +package com.indexdata.mkjsf.pazpar2.commands.sp; + +import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; +import com.indexdata.mkjsf.pazpar2.state.StateManager; + +public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand { + + private static final long serialVersionUID = 5487611235664162578L; + + public AuthCommand(StateManager stateMgr) { + super("auth", stateMgr); + // TODO Auto-generated constructor stub + } + + public AuthCommand copy () { + AuthCommand newCommand = new AuthCommand(stateMgr); + for (String parameterName : parameters.keySet()) { + newCommand.setParameterInState(parameters.get(parameterName).copy()); + } + return newCommand; + } + + @Override + public ServiceProxyCommand getSp() { + return this; + } + + +} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java new file mode 100644 index 0000000..2775ccb --- /dev/null +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/RecordCommandSp.java @@ -0,0 +1,26 @@ +package com.indexdata.mkjsf.pazpar2.commands.sp; + +import java.io.Serializable; + +import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; +import com.indexdata.mkjsf.pazpar2.commands.RecordCommand; + +public class RecordCommandSp implements Serializable, ServiceProxyCommand { + + private static final long serialVersionUID = -3901864271733337221L; + private RecordCommand command = null; + + public RecordCommandSp(RecordCommand command) { + this.command = command; + } + + public void setRecordquery (String recordQuery) { + command.setParameter(new CommandParameter("recordquery","=",recordQuery)); + } + + public String getRecordquery() { + return command.getParameterValue("recordquery"); + } + + +} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/ServiceProxyCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/ServiceProxyCommand.java new file mode 100644 index 0000000..65a06d0 --- /dev/null +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/ServiceProxyCommand.java @@ -0,0 +1,5 @@ +package com.indexdata.mkjsf.pazpar2.commands.sp; + +public interface ServiceProxyCommand { + +} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/sp/ServiceProxyClient.java b/src/main/java/com/indexdata/mkjsf/pazpar2/sp/ServiceProxyClient.java index 520ca3e..fdf0e97 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/sp/ServiceProxyClient.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/sp/ServiceProxyClient.java @@ -12,9 +12,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.enterprise.context.SessionScoped; -import javax.inject.Inject; - import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -43,6 +40,7 @@ import com.indexdata.mkjsf.pazpar2.CommandResponse; import com.indexdata.mkjsf.pazpar2.SearchClient; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; +import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand; import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser; import com.indexdata.mkjsf.utils.Utils; @@ -76,9 +74,9 @@ public class ServiceProxyClient implements SearchClient { config = configReader.getConfiguration(this); serviceUrl = config.getMandatory(SERVICE_PROXY_URL); this.initDocPaths = getMultiProperty(config.get(SP_INIT_DOC_PATHS)); - checkAuth = new Pazpar2Command("auth",null); + checkAuth = new AuthCommand(null); checkAuth.setParameterInState(new CommandParameter("action","=","check")); - ipAuth = new Pazpar2Command("auth",null); + ipAuth = new AuthCommand(null); ipAuth.setParameterInState(new CommandParameter("action","=","ipauth")); } catch (ConfigurationException c) { c.printStackTrace(); @@ -98,7 +96,7 @@ public class ServiceProxyClient implements SearchClient { public boolean authenticate (ServiceProxyUser user) { try { logger.info("Authenticating [" + user.getProperty("name") + "]"); - Pazpar2Command auth = new Pazpar2Command("auth",null); + Pazpar2Command auth = new AuthCommand(null); auth.setParametersInState(new CommandParameter("action","=","login"), new CommandParameter("username","=",user.getProperty("name")), new CommandParameter("password","=",user.getProperty("password"))); -- 1.7.10.4