From 11ff48b9d37193a89a4b74da75db8c58415c46a6 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Fri, 24 May 2013 13:41:51 -0400 Subject: [PATCH] Refactors commands and injection Trying to have command execute themselves (rather than pz2bean executing them) by giving them the request environment. That caused problems with injection - complex injection graphs and dependencies that were null at first use, so refactors this as well. --- .../com/indexdata/mkjsf/errors/ErrorCentral.java | 29 +++--- .../java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java | 108 ++++++++++++-------- .../com/indexdata/mkjsf/pazpar2/Pz2Interface.java | 1 + .../mkjsf/pazpar2/ServiceProxyClient.java | 4 +- .../mkjsf/pazpar2/ServiceProxyExtensions.java | 35 +++---- .../mkjsf/pazpar2/commands/BytargetCommand.java | 7 +- .../mkjsf/pazpar2/commands/InitCommand.java | 9 +- .../mkjsf/pazpar2/commands/Pazpar2Command.java | 42 ++++++-- .../mkjsf/pazpar2/commands/Pazpar2Commands.java | 52 +++++----- .../mkjsf/pazpar2/commands/PingCommand.java | 7 +- .../mkjsf/pazpar2/commands/RecordCommand.java | 46 ++++++++- .../mkjsf/pazpar2/commands/SearchCommand.java | 28 ++++- .../mkjsf/pazpar2/commands/SettingsCommand.java | 7 +- .../mkjsf/pazpar2/commands/ShowCommand.java | 7 +- .../mkjsf/pazpar2/commands/StatCommand.java | 7 +- .../mkjsf/pazpar2/commands/TermlistCommand.java | 7 +- .../mkjsf/pazpar2/commands/sp/AuthCommand.java | 7 +- .../pazpar2/commands/sp/CategoriesCommand.java | 7 +- .../indexdata/mkjsf/pazpar2/data/CommandError.java | 4 +- .../indexdata/mkjsf/pazpar2/data/Responses.java | 2 +- .../mkjsf/pazpar2/state/Pazpar2State.java | 30 +++--- .../mkjsf/pazpar2/state/StateManager.java | 9 +- 22 files changed, 268 insertions(+), 187 deletions(-) diff --git a/src/main/java/com/indexdata/mkjsf/errors/ErrorCentral.java b/src/main/java/com/indexdata/mkjsf/errors/ErrorCentral.java index 499fad8..71bb9c5 100644 --- a/src/main/java/com/indexdata/mkjsf/errors/ErrorCentral.java +++ b/src/main/java/com/indexdata/mkjsf/errors/ErrorCentral.java @@ -4,7 +4,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.inject.Inject; import javax.inject.Named; @@ -12,28 +11,24 @@ import javax.inject.Named; import org.apache.log4j.Logger; import com.indexdata.mkjsf.config.ConfigurationReader; -import com.indexdata.mkjsf.pazpar2.data.Responses; +import com.indexdata.mkjsf.pazpar2.Pz2Bean; -@Named("errors") @SessionScoped +@SessionScoped @Named public class ErrorCentral implements Serializable { private static final long serialVersionUID = -1658192041068396628L; private static Logger logger = Logger.getLogger(ErrorCentral.class); private ErrorHelper errorHelper = null; - - @Inject Responses pzresp; - @Inject ConfigurationReader configurator; + + @Inject ConfigurationReader configurator; private List configurationErrors = new ArrayList(); - public ErrorCentral() {} - - @PostConstruct - public void postConstruct() { - errorHelper = new ErrorHelper(configurator); - pzresp.setErrorHelper(errorHelper); + public ErrorCentral() { + logger.info("Instantiating ErrorCentral "+this); + errorHelper = new ErrorHelper(configurator); } - + public void addConfigurationError (ErrorInterface configError) { configError.setErrorHelper(errorHelper); configurationErrors.add(configError); @@ -44,11 +39,11 @@ public class ErrorCentral implements Serializable { } public boolean hasCommandErrors () { - return pzresp.hasApplicationError(); + return Pz2Bean.get().getPzresp().hasApplicationError(); } public ErrorInterface getCommandError () { - return pzresp.getCommandError(); + return Pz2Bean.get().getPzresp().getCommandError(); } /** @@ -62,6 +57,10 @@ public class ErrorCentral implements Serializable { public List getConfigurationErrors() { return configurationErrors; } + + public ErrorHelper getHelper () { + return errorHelper; + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java index 1c825a8..05744cd 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java @@ -1,6 +1,8 @@ package com.indexdata.mkjsf.pazpar2; import java.io.Serializable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -10,8 +12,11 @@ import java.util.StringTokenizer; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Produces; +import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Qualifier; import org.apache.log4j.Logger; @@ -56,10 +61,11 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria protected SearchClient searchClient = null; @Inject ConfigurationReader configurator; - @Inject StateManager stateMgr; - @Inject Pazpar2Commands pzreq; - @Inject Responses pzresp; - @Inject ErrorCentral errors; + + private StateManager stateMgr = null; + private Pazpar2Commands pzreq = null; + private Responses pzresp = null; + private ErrorCentral errors = null; protected ResultsPager pager = null; @@ -69,9 +75,21 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]"); } + public static Pz2Bean get() { + FacesContext context = FacesContext.getCurrentInstance(); + return (Pz2Bean) context.getApplication().evaluateExpressionGet(context, "#{pz2}", Object.class); + } + @PostConstruct - public void postConstruct() { - logger.debug("Pz2Bean post-construct: Configurator is " + configurator); + public void postConstruct() { + logger.info("Pz2Bean PostConstruct of " + this); + stateMgr = new StateManager(); + pzreq = new Pazpar2Commands(); + pzresp = new Responses(); + errors = new ErrorCentral(); + pzresp.setErrorHelper(errors.getHelper()); + + logger.debug("Pz2Bean PostConstruct: Configurator is " + configurator); logger.debug(Utils.objectId(this) + " will instantiate a Pz2Client next."); pz2Client = new Pz2Client(); configureClient(pz2Client,configurator); @@ -84,7 +102,36 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria e.printStackTrace(); } stateMgr.addStateListener(this); - } + } + + @Qualifier + @Target({java.lang.annotation.ElementType.TYPE, + java.lang.annotation.ElementType.METHOD, + java.lang.annotation.ElementType.PARAMETER, + java.lang.annotation.ElementType.FIELD}) + @Retention(java.lang.annotation.RetentionPolicy.RUNTIME) + public @interface Preferred{} + + @Produces @Preferred @SessionScoped @Named("pzresp") public Responses getPzresp () { + logger.info("Producing pzresp"); + return pzresp; + } + + @Produces @Preferred @SessionScoped @Named("pzreq") public Pazpar2Commands getPzreq () { + logger.info("Producing pzreq"); + return pzreq; + } + + @Produces @Preferred @SessionScoped @Named("errors") public ErrorCentral getErrors() { + logger.info("Producing errors"); + return errors; + } + + @Produces @Preferred @SessionScoped @Named("stateMgr") public StateManager getStateMgr() { + logger.info("Produces stateMgr"); + return stateMgr; + } + public void configureClient(SearchClient client, ConfigurationReader configReader) { logger.debug(Utils.objectId(this) + " will configure search client for the session"); @@ -109,6 +156,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria } public void doSearch() { + try { if (errors.hasConfigurationErrors()) { logger.error("Ignoring search request due to configuration errors."); } else if (searchClient == null){ @@ -123,6 +171,9 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria searchClient.setSearchCommand(pzreq.getCommand("search")); doCommand("search"); } + } catch (NullPointerException npe) { + npe.printStackTrace(); + } } public String doRecord() { @@ -315,44 +366,16 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria * @return An XML response parsed to form a response data object */ protected ResponseDataObject doCommand(String commandName) { - if (pzreq.getCommand(commandName).spOnly() && isPazpar2Service()) { - logger.warn("Skipping " + commandName + " - SP-only command, un-supported by Pazpar2"); + Pazpar2Command command = pzreq.getCommand(commandName); + if (command.spOnly() && isPazpar2Service()) { + logger.warn("Skipping " + commandName + " - SP-only command, not supported by Pazpar2"); return new ResponseDataObject(); } else { - ResponseDataObject responseObject = null; - logger.info("Request "+commandName + ": "+ pzreq.getCommand("search").toString()); - Pazpar2Command command = pzreq.getCommand(commandName); + logger.info("Request "+commandName + ". Search command is: "+ pzreq.getCommand("search").toString()); long start = System.currentTimeMillis(); - HttpResponseWrapper commandResponse = searchClient.executeCommand(command); + ResponseDataObject responseObject = command.run(); long end = System.currentTimeMillis(); logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." ); - responseLogger.debug("Response was: " + commandResponse.getResponseString()); - if (commandResponse.getContentType().contains("xml")) { - responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse); - if (ResponseParser.docTypes.contains(responseObject.getType())) { - logger.debug("Storing " + responseObject.getType() + " in pzresp. "); - pzresp.put(commandName, responseObject); - } else { - if (commandName.equals("record")) { - logger.debug("Command was 'record' but response not '' - assuming raw record response."); - ResponseDataObject recordResponse = new RecordResponse(); - recordResponse.setType("record"); - recordResponse.setXml(responseObject.getXml()); - recordResponse.setAttribute("activeclients", "0"); - pzresp.put("record", recordResponse); - } - } - } else if (commandResponse.isBinary()) { - responseObject = new RecordResponse(); - responseObject.setType(commandName); - logger.info("Binary response"); - responseObject.setAttribute("activeclients", "0"); - responseObject.setXml("binary response"); - responseObject.setBinary(commandResponse.getBytes()); - pzresp.put("record", responseObject); - } else { - logger.error("Response was not found to be XML or binary. The response was not handled."); - } return responseObject; } } @@ -402,6 +425,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria pzreq.getSearch().removeParametersInState(); pzresp.getSp().resetAuthAndBeyond(true); searchClient.setServiceUrl(url); + // pzreq.setService(this); } } @@ -551,4 +575,8 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria } } + public SearchClient getSearchClient() { + return searchClient; + } + } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java index b8b6d24..ca515d6 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java @@ -117,4 +117,5 @@ public interface Pz2Interface extends Serializable { public boolean isPazpar2Service (); public boolean isServiceProxyService(); public boolean serviceIsToBeDecided (); + public SearchClient getSearchClient(); } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java index 2db4558..67cc8ef 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java @@ -71,9 +71,9 @@ public class ServiceProxyClient implements SearchClient { config = configReader.getConfiguration(this); serviceUrl = config.get("SERVICE_PROXY_URL"); this.initDocPaths = config.getMultiProperty(SP_INIT_DOC_PATHS,","); - checkAuth = new AuthCommand(null); + checkAuth = new AuthCommand(); checkAuth.setParameterInState(new CommandParameter("action","=","check")); - ipAuth = new AuthCommand(null); + ipAuth = new AuthCommand(); ipAuth.setParameterInState(new CommandParameter("action","=","ipauth")); } catch (ConfigurationException c) { // TODO: diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java index c10c55e..d085c31 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java @@ -3,8 +3,6 @@ package com.indexdata.mkjsf.pazpar2; import java.io.IOException; import java.io.Serializable; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; import javax.enterprise.context.SessionScoped; import javax.inject.Inject; @@ -15,12 +13,10 @@ import org.apache.myfaces.custom.fileupload.UploadedFile; import com.indexdata.mkjsf.config.ConfigurationReader; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; -import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands; import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand; import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; -import com.indexdata.mkjsf.pazpar2.data.Responses; import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; import com.indexdata.mkjsf.utils.Utils; @@ -36,8 +32,6 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab @Inject ConfigurationReader configurator; @Inject Pz2Bean pz2; - @Inject Pazpar2Commands pzreq; - @Inject Responses pzresp; public ServiceProxyExtensions() { this.initDocUpload = new InitDocUpload(this); @@ -45,20 +39,19 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab //stateMgr.addStateListener(this); } - public void authenticate() { - String command = "auth"; - if (pzresp.getSp().getAuth().unsupportedCommand()) { + public void authenticate() { + if (pz2.getPzresp().getSp().getAuth().unsupportedCommand()) { logger.warn("Running seemingly unsupported command [auth] against SP."); } pz2.resetSearchAndRecordCommands(); - pzresp.getSp().resetAuthAndBeyond(true); - AuthCommand auth = pzreq.getSp().getAuth(); + pz2.getPzresp().getSp().resetAuthAndBeyond(true); + AuthCommand auth = pz2.getPzreq().getSp().getAuth(); ClientCommandResponse commandResponse = pz2.getSpClient().send(auth); String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth"); commandResponse.setResponseToParse(renamedResponse); SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(commandResponse); if (ResponseParser.docTypes.contains(responseObject.getType())) { - pzresp.put(auth.getCommandName(), responseObject); + pz2.getPzresp().put(auth.getCommandName(), responseObject); } if (responseObject.unsupportedCommand()) { logger.error("auth command does not seem to be supported by this Service Proxy"); @@ -72,21 +65,21 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab } public void login(String un, String pw, String navigateTo) { - pzreq.getSp().getAuth().setUsername(un); - pzreq.getSp().getAuth().setPassword(pw); + pz2.getPzreq().getSp().getAuth().setUsername(un); + pz2.getPzreq().getSp().getAuth().setPassword(pw); login(""); } @Override public String login(String navigateTo) { - AuthCommand auth = pzreq.getSp().getAuth(); + AuthCommand auth = pz2.getPzreq().getSp().getAuth(); auth.setParameterInState(new CommandParameter("action","=","login")); authenticate(); return navigateTo; } public void ipAuthenticate () { - AuthCommand auth = pzreq.getSp().getAuth(); + AuthCommand auth = pz2.getPzreq().getSp().getAuth(); auth.setParameterInState(new CommandParameter("action","=","ipAuth")); authenticate(); } @@ -118,7 +111,7 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab logger.info("Paths: " + pz2.getSpClient().getInitDocPaths()); logger.info("Path: " + initDocPath); pz2.resetSearchAndRecordCommands(); - pzresp.getSp().resetAuthAndBeyond(true); + pz2.getPzresp().getSp().resetAuthAndBeyond(true); ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDocPath + getInitFileName()); return response; } @@ -126,7 +119,7 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab @Override public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { pz2.resetSearchAndRecordCommands(); - pzresp.getSp().resetAuthAndBeyond(true); + pz2.getPzresp().getSp().resetAuthAndBeyond(true); HttpResponseWrapper response = pz2.getSpClient().postInitDoc(initDoc,includeDebug); return response; } @@ -147,8 +140,8 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab public void submitInitDoc () throws IOException { ClientCommandResponse response = (ClientCommandResponse) initDocUpload.submit(); ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(response); - logger.info("Putting init response to : " + Utils.objectId(pzresp)); - pzresp.put("init", responseObject); + logger.info("Putting init response to : " + Utils.objectId(pz2.getPzresp())); + pz2.getPzresp().put("init", responseObject); } public void setIncludeInitDocDebug(boolean bool) { @@ -168,7 +161,7 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab public CategoriesResponse getCategories () { String command="categories"; if (pz2.isServiceProxyService()) { - if (pzresp.getSp().getCategories().unsupportedCommand()) { + if (pz2.getPzresp().getSp().getCategories().unsupportedCommand()) { logger.info("Skipping seemingly unsupported command: " + command); return new CategoriesResponse(); } else { 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 b149808..89a5bbd 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/BytargetCommand.java @@ -1,18 +1,17 @@ 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 implements ServiceProxyCommand { private static final long serialVersionUID = 9070458716105294392L; - public BytargetCommand(StateManager stateMgr) { - super("bytarget",stateMgr); + public BytargetCommand() { + super("bytarget"); } public BytargetCommand copy () { - BytargetCommand newCommand = new BytargetCommand(stateMgr); + BytargetCommand newCommand = new BytargetCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 3166168..958aff7 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java @@ -1,14 +1,13 @@ 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 implements ServiceProxyCommand { private static final long serialVersionUID = -4915976465898889987L; - - public InitCommand(StateManager stateMgr) { - super("init",stateMgr); + + public InitCommand() { + super("init"); } public void setClear(String clear) { @@ -38,7 +37,7 @@ public class InitCommand extends Pazpar2Command implements ServiceProxyCommand { } public InitCommand copy () { - InitCommand newCommand = new InitCommand(stateMgr); + InitCommand newCommand = new InitCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 a67f829..06aebf3 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java @@ -6,28 +6,47 @@ import java.util.Map; import org.apache.log4j.Logger; +import com.indexdata.mkjsf.pazpar2.ClientCommandResponse; +import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper; +import com.indexdata.mkjsf.pazpar2.Pz2Bean; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; -import com.indexdata.mkjsf.pazpar2.state.StateManager; +import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +import com.indexdata.mkjsf.pazpar2.data.ResponseParser; public abstract class Pazpar2Command implements Serializable { private static Logger logger = Logger.getLogger(Pazpar2Command.class); private static final long serialVersionUID = -6825491856480675917L; protected String name = ""; - protected Map parameters = new HashMap(); + protected Map parameters = new HashMap(); - protected StateManager stateMgr; + public Pazpar2Command () { - public Pazpar2Command (String name, StateManager stateMgr) { + } + + public void setCommandName(String name) { this.name = name; - this.stateMgr = stateMgr; + } + + public Pazpar2Command (String name) { + this.name = name; } public abstract Pazpar2Command copy (); - + public String getCommandName() { return name; } + + public ResponseDataObject run() { + logger.info("Running " + getCommandName() + " using " + Pz2Bean.get().getSearchClient()); + HttpResponseWrapper httpResponse = Pz2Bean.get().getSearchClient().executeCommand(this); + logger.info("Parsing response for " + getCommandName()); + ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse) httpResponse); + logger.info("Storing response for " + getCommandName()); + Pz2Bean.get().getPzresp().put(getCommandName(), responseObject); + return responseObject; + } public void setParameter (CommandParameter parameter) { Pazpar2Command copy = this.copy(); @@ -141,11 +160,12 @@ public abstract class Pazpar2Command implements Serializable { } private void checkInState(Pazpar2Command command) { - if (stateMgr != null) { - stateMgr.checkIn(command); - } else { - logger.info("Command '" + command.getCommandName() + "' not affecting state (history) as no state manager was defined for this command."); - } + Pz2Bean.get().getStateMgr().checkIn(command); + // if (stateMgr() != null) { + // stateMgr().checkIn(command); + // } else { + // logger.info("Command '" + command.getCommandName() + "' 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/Pazpar2Commands.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Commands.java index 3ceaa8d..21f86ef 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Commands.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Commands.java @@ -2,18 +2,16 @@ package com.indexdata.mkjsf.pazpar2.commands; import java.io.Serializable; -import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; -import javax.inject.Inject; import javax.inject.Named; import org.apache.log4j.Logger; +import com.indexdata.mkjsf.pazpar2.Pz2Bean; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommands; -import com.indexdata.mkjsf.pazpar2.state.StateManager; import com.indexdata.mkjsf.utils.Utils; -@Named("pzreq") @SessionScoped +@SessionScoped @Named public class Pazpar2Commands implements Serializable { private static final long serialVersionUID = -5172466320351302413L; @@ -27,65 +25,61 @@ public class Pazpar2Commands implements Serializable { public static final String SHOW = "show"; public static final String RECORD = "record"; public static final String TERMLIST = "termlist"; - public static final String BYTARGET = "bytarget"; - - private ServiceProxyCommands sp = null; - - @Inject - protected StateManager stateMgr; + public static final String BYTARGET = "bytarget"; + private ServiceProxyCommands sp = null; public Pazpar2Commands() { - logger.info("Initializing Pazpar2Commands [" + Utils.objectId(this) + "]"); + logger.info("Initializing Pazpar2Commands [" + Utils.objectId(this) + "]"); } - - @PostConstruct - public void postConstruct() { - logger.info("in post-construct stateMgr is " + stateMgr); - } - + + // public void setService(Pz2Bean service) { + // this.pz2 = service; + // logger.info("Post construct Pazpar2Command: Service is " + pz2); + // } + public InitCommand getInit() { - return (InitCommand) (stateMgr.getCommand(INIT)); + return (InitCommand) (Pz2Bean.get().getStateMgr().getCommand(INIT)); } - + public PingCommand getPing() { - return (PingCommand) (stateMgr.getCommand(PING)); + return (PingCommand) (Pz2Bean.get().getStateMgr().getCommand(PING)); } public SettingsCommand getSettings() { - return (SettingsCommand) (stateMgr.getCommand(SETTINGS)); + return (SettingsCommand) (Pz2Bean.get().getStateMgr().getCommand(SETTINGS)); } public SearchCommand getSearch() { - return (SearchCommand) (stateMgr.getCommand(SEARCH)); + return (SearchCommand) (Pz2Bean.get().getStateMgr().getCommand(SEARCH)); } public StatCommand getStat() { - return (StatCommand) (stateMgr.getCommand(STAT)); + return (StatCommand) (Pz2Bean.get().getStateMgr().getCommand(STAT)); } public ShowCommand getShow() { - return (ShowCommand) (stateMgr.getCommand(SHOW)); + return (ShowCommand) (Pz2Bean.get().getStateMgr().getCommand(SHOW)); } public RecordCommand getRecord() { - return (RecordCommand) (stateMgr.getCommand(RECORD)); + return (RecordCommand) (Pz2Bean.get().getStateMgr().getCommand(RECORD)); } public TermlistCommand getTermlist() { - return (TermlistCommand) (stateMgr.getCommand(TERMLIST)); + return (TermlistCommand) (Pz2Bean.get().getStateMgr().getCommand(TERMLIST)); } public BytargetCommand getBytarget() { - return (BytargetCommand) (stateMgr.getCommand(BYTARGET)); + return (BytargetCommand) (Pz2Bean.get().getStateMgr().getCommand(BYTARGET)); } public Pazpar2Command getCommand(String name) { - return stateMgr.getCommand(name); + return Pz2Bean.get().getStateMgr().getCommand(name); } public ServiceProxyCommands getSp() { if (sp == null) { - sp = new ServiceProxyCommands(stateMgr); + sp = new ServiceProxyCommands(Pz2Bean.get().getStateMgr()); } return sp; } 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 b4f4f4a..8dbf348 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/PingCommand.java @@ -1,18 +1,17 @@ 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 implements ServiceProxyCommand { private static final long serialVersionUID = 8876721711326535847L; - public PingCommand(StateManager stateMgr) { - super("ping",stateMgr); + public PingCommand() { + super("ping"); } public PingCommand copy () { - PingCommand newCommand = new PingCommand(stateMgr); + PingCommand newCommand = new PingCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 cec9d67..e52afac 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java @@ -1,15 +1,53 @@ package com.indexdata.mkjsf.pazpar2.commands; +import org.apache.log4j.Logger; + +import com.indexdata.mkjsf.pazpar2.ClientCommandResponse; +import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper; +import com.indexdata.mkjsf.pazpar2.Pz2Bean; import com.indexdata.mkjsf.pazpar2.commands.sp.RecordCommandSp; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; -import com.indexdata.mkjsf.pazpar2.state.StateManager; +import com.indexdata.mkjsf.pazpar2.data.RecordResponse; +import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +import com.indexdata.mkjsf.pazpar2.data.ResponseParser; public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 2817539422114569506L; + private static Logger logger = Logger.getLogger(RecordCommand.class); - public RecordCommand(StateManager stateMgr) { - super("record",stateMgr); + public RecordCommand() { + super("record"); + } + + @Override + public ResponseDataObject run() { + HttpResponseWrapper commandResponse = Pz2Bean.get().getSearchClient().executeCommand(this); + ResponseDataObject responseObject = null; + if (commandResponse.getContentType().contains("xml")) { + responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse); + if (ResponseParser.docTypes.contains(responseObject.getType())) { + logger.debug("Storing " + responseObject.getType() + " in pzresp. "); + } else { + logger.debug("Command was 'record' but response not '' - assuming raw record response."); + ResponseDataObject recordResponse = new RecordResponse(); + recordResponse.setType("record"); + recordResponse.setXml(responseObject.getXml()); + recordResponse.setAttribute("activeclients", "0"); + } + } else if (commandResponse.isBinary()) { + responseObject = new RecordResponse(); + responseObject.setType(getCommandName()); + logger.info("Binary response"); + responseObject.setAttribute("activeclients", "0"); + responseObject.setXml("binary response"); + responseObject.setBinary(commandResponse.getBytes()); + + } else { + logger.error("Response was not found to be XML or binary. The response was not handled."); + } + Pz2Bean.get().getPzresp().put(getCommandName(), responseObject); + return responseObject; } public void setId(String recId) { @@ -70,7 +108,7 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand @Override public RecordCommand copy () { - RecordCommand newCommand = new RecordCommand(stateMgr); + RecordCommand newCommand = new RecordCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 c314ec6..654df45 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java @@ -1,22 +1,40 @@ package com.indexdata.mkjsf.pazpar2.commands; import javax.enterprise.context.SessionScoped; +import javax.inject.Named; import org.apache.log4j.Logger; +import com.indexdata.mkjsf.pazpar2.ClientCommandResponse; +import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper; +import com.indexdata.mkjsf.pazpar2.Pz2Bean; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; -import com.indexdata.mkjsf.pazpar2.state.StateManager; +import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; +import com.indexdata.mkjsf.pazpar2.data.ResponseParser; -@SessionScoped +@SessionScoped @Named public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = -1888520867838597236L; private static Logger logger = Logger.getLogger(SearchCommand.class); private SingleTargetFilter singleTargetFilter = null; + + public SearchCommand() { + super("search"); + } - public SearchCommand(StateManager stateMgr) { - super("search",stateMgr); + public ResponseDataObject run() { + logger.info("Running " + getCommandName()); + logger.info("Using client " + Pz2Bean.get().getSearchClient()); + logger.info("Storing responses to " + Pz2Bean.get().getPzresp()); + Pz2Bean.get().getSearchClient().setSearchCommand(this); + logger.info("Executing command " + getCommandName()); + HttpResponseWrapper httpResponse = Pz2Bean.get().getSearchClient().executeCommand(this); + ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse) httpResponse); + Pz2Bean.get().getPzresp().put(getCommandName(), responseObject); + return responseObject; } + public void setQuery(String query) { setParameter(new CommandParameter("query","=",query)); @@ -212,7 +230,7 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand } public SearchCommand copy () { - SearchCommand newCommand = new SearchCommand(stateMgr); + SearchCommand newCommand = new SearchCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 328d578..267e4f8 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SettingsCommand.java @@ -1,19 +1,18 @@ 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 implements ServiceProxyCommand { private static final long serialVersionUID = 2291179325470387102L; - public SettingsCommand(StateManager stateMgr) { - super("settings",stateMgr); + public SettingsCommand() { + super("settings"); // TODO Auto-generated constructor stub } public SettingsCommand copy () { - SettingsCommand newCommand = new SettingsCommand(stateMgr); + SettingsCommand newCommand = new SettingsCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 3b1cf01..89e6c73 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/ShowCommand.java @@ -1,14 +1,13 @@ 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 implements ServiceProxyCommand { private static final long serialVersionUID = -8242768313266051307L; - public ShowCommand(StateManager stateMgr) { - super("show",stateMgr); + public ShowCommand() { + super("show"); setParameterInState(new CommandParameter("start","=","0")); } @@ -105,7 +104,7 @@ public class ShowCommand extends Pazpar2Command implements ServiceProxyCommand { } public ShowCommand copy () { - ShowCommand newCommand = new ShowCommand(stateMgr); + ShowCommand newCommand = new ShowCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 590808d..73867fd 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/StatCommand.java @@ -1,18 +1,17 @@ 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 implements ServiceProxyCommand { private static final long serialVersionUID = 3980630346114157336L; - public StatCommand(StateManager stateMgr) { - super("stat",stateMgr); + public StatCommand() { + super("stat"); } public StatCommand copy () { - StatCommand newCommand = new StatCommand(stateMgr); + StatCommand newCommand = new StatCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 5db510c..2b725c2 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/TermlistCommand.java @@ -1,14 +1,13 @@ 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 implements ServiceProxyCommand { private static final long serialVersionUID = -7067878552863021727L; - public TermlistCommand(StateManager stateMgr) { - super("termlist",stateMgr); + public TermlistCommand() { + super("termlist"); } public void setName(String names) { @@ -28,7 +27,7 @@ public class TermlistCommand extends Pazpar2Command implements ServiceProxyComma } public TermlistCommand copy () { - TermlistCommand newCommand = new TermlistCommand(stateMgr); + TermlistCommand newCommand = new TermlistCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } 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 index 67ecb54..9a4fad7 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/AuthCommand.java @@ -2,14 +2,13 @@ package com.indexdata.mkjsf.pazpar2.commands.sp; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; 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); + public AuthCommand() { + super("auth"); } public void setAction (String action) { @@ -37,7 +36,7 @@ public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand { } public AuthCommand copy () { - AuthCommand newCommand = new AuthCommand(stateMgr); + AuthCommand newCommand = new AuthCommand(); for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java index 27be628..ad5723f 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java @@ -1,19 +1,18 @@ package com.indexdata.mkjsf.pazpar2.commands.sp; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; -import com.indexdata.mkjsf.pazpar2.state.StateManager; public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 5023993689780291641L; - public CategoriesCommand(StateManager stateMgr) { - super("categories", stateMgr); + public CategoriesCommand() { + super("categories"); } @Override public Pazpar2Command copy() { - CategoriesCommand newCommand = new CategoriesCommand(stateMgr); + CategoriesCommand newCommand = new CategoriesCommand(); return newCommand; } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java index 54aa8f6..db4a7bc 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java @@ -7,8 +7,8 @@ import java.util.List; import java.util.regex.Pattern; import com.indexdata.mkjsf.errors.ErrorHelper; -import com.indexdata.mkjsf.errors.ErrorInterface; import com.indexdata.mkjsf.errors.ErrorHelper.ErrorCode; +import com.indexdata.mkjsf.errors.ErrorInterface; import com.indexdata.utils.XmlUtils; /** @@ -53,7 +53,7 @@ public class CommandError extends ResponseDataObject implements ErrorInterface { } public List getSuggestions() { - if (errorHelper!=null) { + if (errorHelper!=null) { return errorHelper.getSuggestions(this); } else { List nohelper = new ArrayList(); diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java index ef6526b..1397023 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java @@ -20,7 +20,7 @@ import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses; import com.indexdata.mkjsf.utils.Utils; -@Named("pzresp") @SessionScoped +@SessionScoped @Named public class Responses implements Serializable { private static final long serialVersionUID = -7543231258346154642L; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/state/Pazpar2State.java b/src/main/java/com/indexdata/mkjsf/pazpar2/state/Pazpar2State.java index 0ac555e..b5b1d3e 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/state/Pazpar2State.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/state/Pazpar2State.java @@ -28,21 +28,23 @@ import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommands; public class Pazpar2State { String key = null; - Map commands = new HashMap();; + Map commands = new HashMap(); - public Pazpar2State (StateManager stateManager) { - commands.put(Pazpar2Commands.INIT, new InitCommand(stateManager)); - commands.put(Pazpar2Commands.PING, new PingCommand(stateManager)); - commands.put(Pazpar2Commands.SETTINGS, new SettingsCommand(stateManager)); - commands.put(Pazpar2Commands.SEARCH, new SearchCommand(stateManager)); - commands.put(Pazpar2Commands.STAT, new StatCommand(stateManager)); - commands.put(Pazpar2Commands.SHOW, new ShowCommand(stateManager)); - commands.put(Pazpar2Commands.RECORD, new RecordCommand(stateManager)); - commands.put(Pazpar2Commands.TERMLIST, new TermlistCommand(stateManager)); - commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand(stateManager)); + public Pazpar2State () { + + commands.put(Pazpar2Commands.INIT, new InitCommand()); + commands.put(Pazpar2Commands.PING, new PingCommand()); + commands.put(Pazpar2Commands.SETTINGS, new SettingsCommand()); + commands.put(Pazpar2Commands.SEARCH, new SearchCommand()); + commands.put(Pazpar2Commands.STAT, new StatCommand()); + commands.put(Pazpar2Commands.SHOW, new ShowCommand()); + commands.put(Pazpar2Commands.RECORD, new RecordCommand()); + commands.put(Pazpar2Commands.TERMLIST, new TermlistCommand()); + commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand()); - commands.put(ServiceProxyCommands.AUTH, new AuthCommand(stateManager)); - commands.put(ServiceProxyCommands.CATEGORIES, new CategoriesCommand(stateManager)); + commands.put(ServiceProxyCommands.AUTH, new AuthCommand()); + commands.put(ServiceProxyCommands.CATEGORIES, new CategoriesCommand()); + // key = "#1"; } @@ -58,7 +60,7 @@ public class Pazpar2State { this.commands.put(commandName, previousState.commands.get(commandName).copy()); } this.commands.put(newCommand.getCommandName(),newCommand); - this.key = getKey(); + this.key = getKey(); } /** diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/state/StateManager.java b/src/main/java/com/indexdata/mkjsf/pazpar2/state/StateManager.java index f052c37..7c6ac91 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/state/StateManager.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/state/StateManager.java @@ -7,14 +7,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.enterprise.context.SessionScoped; - import org.apache.log4j.Logger; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.utils.Utils; -@SessionScoped public class StateManager implements Serializable { private static final long serialVersionUID = 8152558351351730035L; @@ -25,16 +22,16 @@ public class StateManager implements Serializable { /* SP extras */ "auth","categories")); Map pendingStateChanges = new HashMap(); private static Logger logger = Logger.getLogger(StateManager.class); - private List listeners = new ArrayList(); + private List listeners = new ArrayList(); public StateManager () { logger.info("Initializing a Pazpar2 state manager [" + Utils.objectId(this) + "]"); - Pazpar2State initialState = new Pazpar2State(this); + Pazpar2State initialState = new Pazpar2State(); states.put(initialState.getKey(), initialState); currentKey = initialState.getKey(); for (String command : allCommands) { pendingStateChanges.put(command, new Boolean(false)); - } + } } public void addStateListener(StateListener listener) { -- 1.7.10.4