From: Niels Erik G. Nielsen Date: Fri, 24 May 2013 19:42:49 +0000 (-0400) Subject: Moves request logic from pz2bean to individual commands X-Git-Tag: v0.0.7~81 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=5745961a862c1f07e9abcb084f43c205f01631be;p=mkjsf-moved-to-github.git Moves request logic from pz2bean to individual commands Simplifies the main bean and makes command execution from UI more intuitive --- diff --git a/src/META-INF/resources/pz2utils/pz2watch.xhtml b/src/META-INF/resources/pz2utils/pz2watch.xhtml index b681b98..94ec94e 100644 --- a/src/META-INF/resources/pz2utils/pz2watch.xhtml +++ b/src/META-INF/resources/pz2utils/pz2watch.xhtml @@ -38,7 +38,7 @@ - + diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java b/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java index 78c5652..7ebdf9f 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/CommandThread.java @@ -3,17 +3,20 @@ package com.indexdata.mkjsf.pazpar2; import org.apache.log4j.Logger; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; +import com.indexdata.mkjsf.pazpar2.data.Responses; public class CommandThread extends Thread { private static Logger logger = Logger.getLogger(CommandThread.class); Pazpar2Command command; SearchClient client; + Responses pzresp; HttpResponseWrapper commandResponse = null; - public CommandThread (Pazpar2Command command, SearchClient client) { + public CommandThread (Pazpar2Command command, SearchClient client, Responses pzresp) { this.command = command; this.client = client; + this.pzresp = pzresp; } /** @@ -21,7 +24,7 @@ public class CommandThread extends Thread { */ public void run() { logger.debug(command.getCommandName() + " executing asynchronously"); - commandResponse = client.executeCommand(command); + command.run(client,pzresp); } /** diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java index 05744cd..8e3a14d 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Bean.java @@ -28,12 +28,10 @@ import com.indexdata.mkjsf.errors.ConfigurationError; import com.indexdata.mkjsf.errors.ConfigurationException; import com.indexdata.mkjsf.errors.ErrorCentral; import com.indexdata.mkjsf.errors.ErrorHelper; -import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands; import com.indexdata.mkjsf.pazpar2.data.RecordResponse; 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.state.StateListener; import com.indexdata.mkjsf.pazpar2.state.StateManager; @@ -54,8 +52,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria private static final long serialVersionUID = 3440277287081557861L; - private static Logger logger = Logger.getLogger(Pz2Bean.class); - private static Logger responseLogger = Logger.getLogger("com.indexdata.mkjsf.pazpar2.responses"); + private static Logger logger = Logger.getLogger(Pz2Bean.class); protected Pz2Client pz2Client = null; protected ServiceProxyClient spClient = null; protected SearchClient searchClient = null; @@ -113,25 +110,24 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria public @interface Preferred{} @Produces @Preferred @SessionScoped @Named("pzresp") public Responses getPzresp () { - logger.info("Producing pzresp"); + logger.trace("Producing pzresp"); return pzresp; } @Produces @Preferred @SessionScoped @Named("pzreq") public Pazpar2Commands getPzreq () { - logger.info("Producing pzreq"); + logger.trace("Producing pzreq"); return pzreq; } @Produces @Preferred @SessionScoped @Named("errors") public ErrorCentral getErrors() { - logger.info("Producing errors"); + logger.trace("Producing errors"); return errors; } @Produces @Preferred @SessionScoped @Named("stateMgr") public StateManager getStateMgr() { - logger.info("Produces stateMgr"); + logger.trace("Producing stateMgr"); return stateMgr; } - public void configureClient(SearchClient client, ConfigurationReader configReader) { logger.debug(Utils.objectId(this) + " will configure search client for the session"); @@ -149,49 +145,6 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria pzreq.getRecord().removeParametersInState(); pzreq.getSearch().removeParametersInState(); } - - public void doSearch(String query) { - pzreq.getSearch().setParameter(new CommandParameter("query","=",query)); - doSearch(); - } - - public void doSearch() { - try { - if (errors.hasConfigurationErrors()) { - logger.error("Ignoring search request due to configuration errors."); - } else if (searchClient == null){ - logger.error("No search client defined. A client must either be pre-configured or selected before searching."); - errors.addConfigurationError(new ConfigurationError("No client defined","Client is null","No search client defined. A client must be pre-configured or selected runtime, prior to searching.")); - } else { - stateMgr.hasPendingStateChange("search",false); - pzresp.resetSearchAndBeyond(); - pzreq.getRecord().removeParametersInState(); - pzreq.getShow().setParameterInState(new CommandParameter("start","=",0)); - logger.debug(Utils.objectId(this) + " is searching using "+pzreq.getCommand("search").getUrlEncodedParameterValue("query")); - searchClient.setSearchCommand(pzreq.getCommand("search")); - doCommand("search"); - } - } catch (NullPointerException npe) { - npe.printStackTrace(); - } - } - - public String doRecord() { - if (errors.hasConfigurationErrors()) { - logger.error("Ignoring record request due to configuration errors."); - return ""; - } else if (!pzreq.getCommand("record").hasParameterValue("id")) { - logger.debug("Ignoring record request due to no id parameter."); - return ""; - } else if (pzresp.getSearch().hasApplicationError()) { - logger.debug("Ignoring record request due search error."); - return ""; - } else { - logger.debug("Executing record command"); - doCommand("record"); - return pzresp.getRecord().getActiveClients(); - } - } /** * Refreshes 'show', 'stat', 'termlist', and 'bytarget' data object from pazpar2 @@ -225,10 +178,11 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria logger.debug("Request to update: " + commands); try { if (commands.equals("search")) { - doSearch(); + pzreq.getSearch().run(); return "new"; } else if (commands.equals("record")) { - return doRecord(); + pzreq.getRecord().run(); + return pzresp.getRecord().getActiveClients(); } else if (pzresp.getSearch().isNew()) { // For returning notification of 'search started' quickly to UI logger.info("New search. Marking it old, then returning 'new' to trigger another round-trip."); @@ -247,7 +201,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria List threadList = new ArrayList(); StringTokenizer tokens = new StringTokenizer(commands,","); while (tokens.hasMoreElements()) { - threadList.add(new CommandThread(pzreq.getCommand(tokens.nextToken()),searchClient)); + threadList.add(new CommandThread(pzreq.getCommand(tokens.nextToken()),searchClient,Pz2Bean.get().getPzresp())); } for (CommandThread thread : threadList) { thread.start(); @@ -259,17 +213,6 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria e.printStackTrace(); } } - for (CommandThread thread : threadList) { - String commandName = thread.getCommand().getCommandName(); - ClientCommandResponse response = (ClientCommandResponse) thread.getCommandResponse(); - responseLogger.debug("Response was: " + response.getResponseString()); - ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(response); - if (ResponseParser.docTypes.contains(responseObject.getType())) { - pzresp.put(commandName, responseObject); - } else { - logger.info("Unknown doc type [" + responseObject.getType() + "]. Was not cached."); - } - } return pzresp.getActiveClients(); } } @@ -345,16 +288,12 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria protected void handleQueryStateChanges (String commands) { if (stateMgr.hasPendingStateChange("search") && hasQuery()) { logger.info("Triggered search: Found pending search change [" + pzreq.getCommand("search").toString() + "], doing search before updating " + commands); - doSearch(); + pzreq.getSearch().run(); } if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { logger.debug("Found pending record ID change. Doing record before updating " + commands); stateMgr.hasPendingStateChange("record",false); - if (pzreq.getCommand("record").hasParameterValue("id")) { - doRecord(); - } else { - pzresp.put("record", new RecordResponse()); - } + pzreq.getRecord().run(); } } @@ -425,7 +364,6 @@ public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Seria pzreq.getSearch().removeParametersInState(); pzresp.getSp().resetAuthAndBeyond(true); searchClient.setServiceUrl(url); - // pzreq.setService(this); } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java index ca515d6..2122743 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Interface.java @@ -11,18 +11,18 @@ public interface Pz2Interface extends Serializable { * * @param query */ - public void doSearch(String query); + //public void doSearch(String query); /** * Executes a Pazpar2 search using the current query */ - public void doSearch(); + // public void doSearch(); /** * Executes a Pazpar2 record requests * @return Active clients for the record request */ - public String doRecord(); + // public String doRecord(); /** * Updates display data objects by issuing the following pazpar2 commands: diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java index d085c31..6595059 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java @@ -30,8 +30,7 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab private String initDocResponse = ""; private InitDocUpload initDocUpload; - @Inject ConfigurationReader configurator; - @Inject Pz2Bean pz2; + @Inject ConfigurationReader configurator; public ServiceProxyExtensions() { this.initDocUpload = new InitDocUpload(this); @@ -40,24 +39,12 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab } public void authenticate() { - if (pz2.getPzresp().getSp().getAuth().unsupportedCommand()) { + if (Pz2Bean.get().getPzresp().getSp().getAuth().unsupportedCommand()) { logger.warn("Running seemingly unsupported command [auth] against SP."); } - pz2.resetSearchAndRecordCommands(); - 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())) { - pz2.getPzresp().put(auth.getCommandName(), responseObject); - } - if (responseObject.unsupportedCommand()) { - logger.error("auth command does not seem to be supported by this Service Proxy"); - } - String responseStr = commandResponse.getResponseString(); - logger.info(responseStr); + Pz2Bean.get().resetSearchAndRecordCommands(); + Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true); + Pz2Bean.get().getPzreq().getSp().getAuth().run(); } public void login(String un, String pw) { @@ -65,33 +52,27 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab } public void login(String un, String pw, String navigateTo) { - pz2.getPzreq().getSp().getAuth().setUsername(un); - pz2.getPzreq().getSp().getAuth().setPassword(pw); + Pz2Bean.get().getPzreq().getSp().getAuth().setUsername(un); + Pz2Bean.get().getPzreq().getSp().getAuth().setPassword(pw); login(""); } @Override public String login(String navigateTo) { - AuthCommand auth = pz2.getPzreq().getSp().getAuth(); + AuthCommand auth = Pz2Bean.get().getPzreq().getSp().getAuth(); auth.setParameterInState(new CommandParameter("action","=","login")); authenticate(); return navigateTo; } public void ipAuthenticate () { - AuthCommand auth = pz2.getPzreq().getSp().getAuth(); + AuthCommand auth = Pz2Bean.get().getPzreq().getSp().getAuth(); auth.setParameterInState(new CommandParameter("action","=","ipAuth")); authenticate(); } - - private String renameResponseElement(String responseString, String newName) { - responseString = responseString.replace("", "<" + newName + ">"); - responseString = responseString.replace("", ""); - return responseString; - } - + public String getInitDocPath () { - return pz2.getSpClient().getConfiguration().get("INIT_DOC_PATH"); + return Pz2Bean.get().getSpClient().getConfiguration().get("INIT_DOC_PATH"); } @Override @@ -107,20 +88,20 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab @Override public ClientCommandResponse postInit() throws UnsupportedEncodingException, IOException { - String initDocPath = pz2.getSpClient().getInitDocPaths().get(0); - logger.info("Paths: " + pz2.getSpClient().getInitDocPaths()); + String initDocPath = Pz2Bean.get().getSpClient().getInitDocPaths().get(0); + logger.info("Paths: " + Pz2Bean.get().getSpClient().getInitDocPaths()); logger.info("Path: " + initDocPath); - pz2.resetSearchAndRecordCommands(); - pz2.getPzresp().getSp().resetAuthAndBeyond(true); - ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDocPath + getInitFileName()); + Pz2Bean.get().resetSearchAndRecordCommands(); + Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true); + ClientCommandResponse response = Pz2Bean.get().getSpClient().postInitDoc(initDocPath + getInitFileName()); return response; } @Override public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { - pz2.resetSearchAndRecordCommands(); - pz2.getPzresp().getSp().resetAuthAndBeyond(true); - HttpResponseWrapper response = pz2.getSpClient().postInitDoc(initDoc,includeDebug); + Pz2Bean.get().resetSearchAndRecordCommands(); + Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true); + HttpResponseWrapper response = Pz2Bean.get().getSpClient().postInitDoc(initDoc,includeDebug); return response; } @@ -139,9 +120,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(pz2.getPzresp())); - pz2.getPzresp().put("init", responseObject); + ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(response); + Pz2Bean.get().getPzresp().put("init", responseObject); } public void setIncludeInitDocDebug(boolean bool) { @@ -160,12 +140,12 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab public CategoriesResponse getCategories () { String command="categories"; - if (pz2.isServiceProxyService()) { - if (pz2.getPzresp().getSp().getCategories().unsupportedCommand()) { + if (Pz2Bean.get().isServiceProxyService()) { + if (Pz2Bean.get().getPzresp().getSp().getCategories().unsupportedCommand()) { logger.info("Skipping seemingly unsupported command: " + command); return new CategoriesResponse(); } else { - SpResponseDataObject response = (SpResponseDataObject) pz2.doCommand(command); + SpResponseDataObject response = (SpResponseDataObject) Pz2Bean.get().getPzreq().getSp().getCategories().run(); if (response.unsupportedCommand()) { logger.warn("Command 'categories' not supported by this Service Proxy"); } else if (response.hasApplicationError()) { 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 06aebf3..5979ad3 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/Pazpar2Command.java @@ -9,9 +9,11 @@ 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.SearchClient; import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; +import com.indexdata.mkjsf.pazpar2.data.Responses; public abstract class Pazpar2Command implements Serializable { @@ -20,8 +22,7 @@ public abstract class Pazpar2Command implements Serializable { protected String name = ""; protected Map parameters = new HashMap(); - public Pazpar2Command () { - + public Pazpar2Command () { } public void setCommandName(String name) { @@ -39,14 +40,29 @@ public abstract class Pazpar2Command implements Serializable { } public ResponseDataObject run() { - logger.info("Running " + getCommandName() + " using " + Pz2Bean.get().getSearchClient()); - HttpResponseWrapper httpResponse = Pz2Bean.get().getSearchClient().executeCommand(this); + return run(Pz2Bean.get().getSearchClient(), + Pz2Bean.get().getPzresp()); + } + + /** + * For running the command in a thread. Client and Responses must be + * provided because at this point the CDI bean cannot be retrieved + * from within a thread. + * + * @param client + * @param pzresp + * @return + */ + public ResponseDataObject run(SearchClient client,Responses pzresp) { + logger.info("Running " + getCommandName() + " using " + client); + HttpResponseWrapper httpResponse = client.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; + pzresp.put(getCommandName(), responseObject); + return responseObject; } + public void setParameter (CommandParameter parameter) { Pazpar2Command copy = this.copy(); @@ -143,8 +159,7 @@ public abstract class Pazpar2Command implements Serializable { } public String getParameterValue(String parameterName) { - return getParameter(parameterName)==null ? "" : getParameter(parameterName).getValueWithExpressions(); - + return getParameter(parameterName)==null ? "" : getParameter(parameterName).getValueWithExpressions(); } public String getUrlEncodedParameterValue(String parameterName) { @@ -161,11 +176,6 @@ public abstract class Pazpar2Command implements Serializable { private void checkInState(Pazpar2Command 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/RecordCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java index e52afac..50e33d1 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java @@ -22,31 +22,37 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand @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()); + if (hasParameterValue("id")) { + HttpResponseWrapper commandResponse = Pz2Bean.get().getSearchClient().executeCommand(this); + 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); } else { - logger.error("Response was not found to be XML or binary. The response was not handled."); + logger.debug("No record id parameter on this command. Ignoring request but clearing any previous record result."); + Pz2Bean.get().getPzresp().put(getCommandName(), new RecordResponse()); } - Pz2Bean.get().getPzresp().put(getCommandName(), responseObject); return responseObject; } 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 654df45..a95ac09 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/SearchCommand.java @@ -5,12 +5,9 @@ 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.data.ResponseDataObject; -import com.indexdata.mkjsf.pazpar2.data.ResponseParser; @SessionScoped @Named public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand { @@ -25,14 +22,12 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand public ResponseDataObject run() { logger.info("Running " + getCommandName()); - logger.info("Using client " + Pz2Bean.get().getSearchClient()); - logger.info("Storing responses to " + Pz2Bean.get().getPzresp()); + Pz2Bean.get().getStateMgr().hasPendingStateChange("search",false); + Pz2Bean.get().getPzresp().resetSearchAndBeyond(); + Pz2Bean.get().getPzreq().getRecord().removeParametersInState(); + Pz2Bean.get().getPzreq().getShow().setParameterInState(new CommandParameter("start","=",0)); 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; + return super.run(); } 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 9a4fad7..3c9617e 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 @@ -1,16 +1,44 @@ package com.indexdata.mkjsf.pazpar2.commands.sp; +import org.apache.log4j.Logger; + +import com.indexdata.mkjsf.pazpar2.ClientCommandResponse; +import com.indexdata.mkjsf.pazpar2.Pz2Bean; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; +import com.indexdata.mkjsf.pazpar2.data.ResponseParser; +import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 5487611235664162578L; + private static Logger logger = Logger.getLogger(AuthCommand.class); public AuthCommand() { super("auth"); } + public SpResponseDataObject run() { + ClientCommandResponse response = (ClientCommandResponse) Pz2Bean.get().getSearchClient().executeCommand(this); + String renamedResponse = renameResponseElement(response.getResponseString(), "auth"); + response.setResponseToParse(renamedResponse); + SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(response); + if (ResponseParser.docTypes.contains(responseObject.getType())) { + Pz2Bean.get().getPzresp().put(getCommandName(), responseObject); + } + if (responseObject.unsupportedCommand()) { + logger.error("auth command does not seem to be supported by this Service Proxy"); + } + return responseObject; + } + + private String renameResponseElement(String responseString, String newName) { + responseString = responseString.replace("", "<" + newName + ">"); + responseString = responseString.replace("", ""); + return responseString; + } + + public void setAction (String action) { setParameterInState(new CommandParameter("action","=",action)); } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java index 55aca4e..89f5fbb 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/RecordResponse.java @@ -23,7 +23,7 @@ public class RecordResponse extends ResponseDataObject { locations.add((Location)element); } } else { - logger.debug("Found no locations"); + logger.trace("Found no locations"); } return locations; }