import java.util.ArrayList;\r
import java.util.List;\r
\r
-import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
import javax.inject.Inject;\r
import javax.inject.Named;\r
import org.apache.log4j.Logger;\r
\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
-import com.indexdata.mkjsf.pazpar2.data.Responses;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
\r
-@Named("errors") @SessionScoped\r
+@SessionScoped @Named\r
public class ErrorCentral implements Serializable {\r
\r
private static final long serialVersionUID = -1658192041068396628L;\r
private static Logger logger = Logger.getLogger(ErrorCentral.class); \r
private ErrorHelper errorHelper = null;\r
- \r
- @Inject Responses pzresp;\r
- @Inject ConfigurationReader configurator;\r
+ \r
+ @Inject ConfigurationReader configurator; \r
\r
private List<ErrorInterface> configurationErrors = new ArrayList<ErrorInterface>();\r
\r
- public ErrorCentral() {}\r
- \r
- @PostConstruct \r
- public void postConstruct() {\r
- errorHelper = new ErrorHelper(configurator);\r
- pzresp.setErrorHelper(errorHelper); \r
+ public ErrorCentral() {\r
+ logger.info("Instantiating ErrorCentral "+this);\r
+ errorHelper = new ErrorHelper(configurator); \r
}\r
- \r
+ \r
public void addConfigurationError (ErrorInterface configError) {\r
configError.setErrorHelper(errorHelper);\r
configurationErrors.add(configError);\r
}\r
\r
public boolean hasCommandErrors () {\r
- return pzresp.hasApplicationError();\r
+ return Pz2Bean.get().getPzresp().hasApplicationError();\r
}\r
\r
public ErrorInterface getCommandError () {\r
- return pzresp.getCommandError();\r
+ return Pz2Bean.get().getPzresp().getCommandError();\r
}\r
\r
/**\r
public List<ErrorInterface> getConfigurationErrors() { \r
return configurationErrors;\r
}\r
+ \r
+ public ErrorHelper getHelper () {\r
+ return errorHelper;\r
+ }\r
\r
\r
}\r
package com.indexdata.mkjsf.pazpar2;\r
\r
import java.io.Serializable;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.Target;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.HashMap;\r
\r
import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
+import javax.enterprise.inject.Produces;\r
+import javax.faces.context.FacesContext;\r
import javax.inject.Inject;\r
import javax.inject.Named;\r
+import javax.inject.Qualifier;\r
\r
import org.apache.log4j.Logger;\r
\r
protected SearchClient searchClient = null; \r
\r
@Inject ConfigurationReader configurator;\r
- @Inject StateManager stateMgr;\r
- @Inject Pazpar2Commands pzreq;\r
- @Inject Responses pzresp;\r
- @Inject ErrorCentral errors; \r
+ \r
+ private StateManager stateMgr = null;\r
+ private Pazpar2Commands pzreq = null;\r
+ private Responses pzresp = null;\r
+ private ErrorCentral errors = null; \r
\r
protected ResultsPager pager = null; \r
\r
logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]"); \r
}\r
\r
+ public static Pz2Bean get() {\r
+ FacesContext context = FacesContext.getCurrentInstance();\r
+ return (Pz2Bean) context.getApplication().evaluateExpressionGet(context, "#{pz2}", Object.class); \r
+ }\r
+ \r
@PostConstruct\r
- public void postConstruct() { \r
- logger.debug("Pz2Bean post-construct: Configurator is " + configurator);\r
+ public void postConstruct() {\r
+ logger.info("Pz2Bean PostConstruct of " + this);\r
+ stateMgr = new StateManager();\r
+ pzreq = new Pazpar2Commands();\r
+ pzresp = new Responses(); \r
+ errors = new ErrorCentral(); \r
+ pzresp.setErrorHelper(errors.getHelper());\r
+ \r
+ logger.debug("Pz2Bean PostConstruct: Configurator is " + configurator);\r
logger.debug(Utils.objectId(this) + " will instantiate a Pz2Client next.");\r
pz2Client = new Pz2Client();\r
configureClient(pz2Client,configurator);\r
e.printStackTrace();\r
} \r
stateMgr.addStateListener(this); \r
- } \r
+ }\r
+ \r
+ @Qualifier\r
+ @Target({java.lang.annotation.ElementType.TYPE,\r
+ java.lang.annotation.ElementType.METHOD,\r
+ java.lang.annotation.ElementType.PARAMETER,\r
+ java.lang.annotation.ElementType.FIELD})\r
+ @Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\r
+ public @interface Preferred{}\r
+ \r
+ @Produces @Preferred @SessionScoped @Named("pzresp") public Responses getPzresp () {\r
+ logger.info("Producing pzresp");\r
+ return pzresp;\r
+ }\r
+ \r
+ @Produces @Preferred @SessionScoped @Named("pzreq") public Pazpar2Commands getPzreq () {\r
+ logger.info("Producing pzreq");\r
+ return pzreq;\r
+ }\r
+ \r
+ @Produces @Preferred @SessionScoped @Named("errors") public ErrorCentral getErrors() {\r
+ logger.info("Producing errors");\r
+ return errors;\r
+ }\r
+ \r
+ @Produces @Preferred @SessionScoped @Named("stateMgr") public StateManager getStateMgr() {\r
+ logger.info("Produces stateMgr");\r
+ return stateMgr;\r
+ }\r
+\r
\r
public void configureClient(SearchClient client, ConfigurationReader configReader) {\r
logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
}\r
\r
public void doSearch() {\r
+ try {\r
if (errors.hasConfigurationErrors()) {\r
logger.error("Ignoring search request due to configuration errors.");\r
} else if (searchClient == null){\r
searchClient.setSearchCommand(pzreq.getCommand("search"));\r
doCommand("search");\r
}\r
+ } catch (NullPointerException npe) {\r
+ npe.printStackTrace(); \r
+ }\r
}\r
\r
public String doRecord() {\r
* @return An XML response parsed to form a response data object\r
*/\r
protected ResponseDataObject doCommand(String commandName) {\r
- if (pzreq.getCommand(commandName).spOnly() && isPazpar2Service()) {\r
- logger.warn("Skipping " + commandName + " - SP-only command, un-supported by Pazpar2");\r
+ Pazpar2Command command = pzreq.getCommand(commandName);\r
+ if (command.spOnly() && isPazpar2Service()) {\r
+ logger.warn("Skipping " + commandName + " - SP-only command, not supported by Pazpar2");\r
return new ResponseDataObject();\r
} else {\r
- ResponseDataObject responseObject = null; \r
- logger.info("Request "+commandName + ": "+ pzreq.getCommand("search").toString());\r
- Pazpar2Command command = pzreq.getCommand(commandName);\r
+ logger.info("Request "+commandName + ". Search command is: "+ pzreq.getCommand("search").toString()); \r
long start = System.currentTimeMillis();\r
- HttpResponseWrapper commandResponse = searchClient.executeCommand(command);\r
+ ResponseDataObject responseObject = command.run(); \r
long end = System.currentTimeMillis();\r
logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
- responseLogger.debug("Response was: " + commandResponse.getResponseString());\r
- if (commandResponse.getContentType().contains("xml")) {\r
- responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);\r
- if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
- logger.debug("Storing " + responseObject.getType() + " in pzresp. ");\r
- pzresp.put(commandName, responseObject);\r
- } else {\r
- if (commandName.equals("record")) {\r
- logger.debug("Command was 'record' but response not '<record>' - assuming raw record response.");\r
- ResponseDataObject recordResponse = new RecordResponse(); \r
- recordResponse.setType("record");\r
- recordResponse.setXml(responseObject.getXml()); \r
- recordResponse.setAttribute("activeclients", "0");\r
- pzresp.put("record", recordResponse); \r
- } \r
- }\r
- } else if (commandResponse.isBinary()) {\r
- responseObject = new RecordResponse(); \r
- responseObject.setType(commandName);\r
- logger.info("Binary response");\r
- responseObject.setAttribute("activeclients", "0");\r
- responseObject.setXml("<record>binary response</record>");\r
- responseObject.setBinary(commandResponse.getBytes());\r
- pzresp.put("record", responseObject);\r
- } else {\r
- logger.error("Response was not found to be XML or binary. The response was not handled.");\r
- }\r
return responseObject;\r
}\r
}\r
pzreq.getSearch().removeParametersInState();\r
pzresp.getSp().resetAuthAndBeyond(true); \r
searchClient.setServiceUrl(url);\r
+ // pzreq.setService(this);\r
} \r
}\r
\r
}\r
}\r
\r
+ public SearchClient getSearchClient() {\r
+ return searchClient;\r
+ }\r
+ \r
}\r
public boolean isPazpar2Service (); \r
public boolean isServiceProxyService(); \r
public boolean serviceIsToBeDecided ();\r
+ public SearchClient getSearchClient();\r
}\r
config = configReader.getConfiguration(this); \r
serviceUrl = config.get("SERVICE_PROXY_URL");\r
this.initDocPaths = config.getMultiProperty(SP_INIT_DOC_PATHS,",");\r
- checkAuth = new AuthCommand(null);\r
+ checkAuth = new AuthCommand();\r
checkAuth.setParameterInState(new CommandParameter("action","=","check"));\r
- ipAuth = new AuthCommand(null);\r
+ ipAuth = new AuthCommand();\r
ipAuth.setParameterInState(new CommandParameter("action","=","ipauth"));\r
} catch (ConfigurationException c) {\r
// TODO: \r
import java.io.IOException;\r
import java.io.Serializable;\r
import java.io.UnsupportedEncodingException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
\r
import javax.enterprise.context.SessionScoped;\r
import javax.inject.Inject;\r
\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
-import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.InitDocUpload;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
-import com.indexdata.mkjsf.pazpar2.data.Responses;\r
import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
@Inject ConfigurationReader configurator; \r
@Inject Pz2Bean pz2;\r
- @Inject Pazpar2Commands pzreq;\r
- @Inject Responses pzresp;\r
\r
public ServiceProxyExtensions() {\r
this.initDocUpload = new InitDocUpload(this);\r
//stateMgr.addStateListener(this);\r
}\r
\r
- public void authenticate() {\r
- String command = "auth";\r
- if (pzresp.getSp().getAuth().unsupportedCommand()) {\r
+ public void authenticate() { \r
+ if (pz2.getPzresp().getSp().getAuth().unsupportedCommand()) {\r
logger.warn("Running seemingly unsupported command [auth] against SP.");\r
}\r
pz2.resetSearchAndRecordCommands();\r
- pzresp.getSp().resetAuthAndBeyond(true);\r
- AuthCommand auth = pzreq.getSp().getAuth(); \r
+ pz2.getPzresp().getSp().resetAuthAndBeyond(true);\r
+ AuthCommand auth = pz2.getPzreq().getSp().getAuth(); \r
ClientCommandResponse commandResponse = pz2.getSpClient().send(auth); \r
String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth"); \r
commandResponse.setResponseToParse(renamedResponse);\r
SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(commandResponse); \r
if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
- pzresp.put(auth.getCommandName(), responseObject);\r
+ pz2.getPzresp().put(auth.getCommandName(), responseObject);\r
}\r
if (responseObject.unsupportedCommand()) {\r
logger.error("auth command does not seem to be supported by this Service Proxy");\r
}\r
\r
public void login(String un, String pw, String navigateTo) { \r
- pzreq.getSp().getAuth().setUsername(un);\r
- pzreq.getSp().getAuth().setPassword(pw);\r
+ pz2.getPzreq().getSp().getAuth().setUsername(un);\r
+ pz2.getPzreq().getSp().getAuth().setPassword(pw);\r
login("");\r
} \r
\r
@Override \r
public String login(String navigateTo) {\r
- AuthCommand auth = pzreq.getSp().getAuth(); \r
+ AuthCommand auth = pz2.getPzreq().getSp().getAuth(); \r
auth.setParameterInState(new CommandParameter("action","=","login"));\r
authenticate();\r
return navigateTo;\r
}\r
\r
public void ipAuthenticate () { \r
- AuthCommand auth = pzreq.getSp().getAuth(); \r
+ AuthCommand auth = pz2.getPzreq().getSp().getAuth(); \r
auth.setParameterInState(new CommandParameter("action","=","ipAuth"));\r
authenticate();\r
}\r
logger.info("Paths: " + pz2.getSpClient().getInitDocPaths());\r
logger.info("Path: " + initDocPath); \r
pz2.resetSearchAndRecordCommands();\r
- pzresp.getSp().resetAuthAndBeyond(true);\r
+ pz2.getPzresp().getSp().resetAuthAndBeyond(true);\r
ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDocPath + getInitFileName()); \r
return response;\r
}\r
@Override\r
public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { \r
pz2.resetSearchAndRecordCommands();\r
- pzresp.getSp().resetAuthAndBeyond(true);\r
+ pz2.getPzresp().getSp().resetAuthAndBeyond(true);\r
HttpResponseWrapper response = pz2.getSpClient().postInitDoc(initDoc,includeDebug); \r
return response;\r
}\r
public void submitInitDoc () throws IOException {\r
ClientCommandResponse response = (ClientCommandResponse) initDocUpload.submit();\r
ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(response);\r
- logger.info("Putting init response to : " + Utils.objectId(pzresp));\r
- pzresp.put("init", responseObject);\r
+ logger.info("Putting init response to : " + Utils.objectId(pz2.getPzresp()));\r
+ pz2.getPzresp().put("init", responseObject);\r
}\r
\r
public void setIncludeInitDocDebug(boolean bool) {\r
public CategoriesResponse getCategories () { \r
String command="categories";\r
if (pz2.isServiceProxyService()) {\r
- if (pzresp.getSp().getCategories().unsupportedCommand()) {\r
+ if (pz2.getPzresp().getSp().getCategories().unsupportedCommand()) {\r
logger.info("Skipping seemingly unsupported command: " + command); \r
return new CategoriesResponse();\r
} else {\r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class BytargetCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 9070458716105294392L;\r
\r
- public BytargetCommand(StateManager stateMgr) {\r
- super("bytarget",stateMgr);\r
+ public BytargetCommand() {\r
+ super("bytarget");\r
}\r
\r
public BytargetCommand copy () {\r
- BytargetCommand newCommand = new BytargetCommand(stateMgr);\r
+ BytargetCommand newCommand = new BytargetCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class InitCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = -4915976465898889987L;\r
-\r
- public InitCommand(StateManager stateMgr) {\r
- super("init",stateMgr);\r
+ \r
+ public InitCommand() {\r
+ super("init");\r
}\r
\r
public void setClear(String clear) { \r
}\r
\r
public InitCommand copy () {\r
- InitCommand newCommand = new InitCommand(stateMgr);\r
+ InitCommand newCommand = new InitCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
+import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
\r
public abstract class Pazpar2Command implements Serializable {\r
\r
private static Logger logger = Logger.getLogger(Pazpar2Command.class);\r
private static final long serialVersionUID = -6825491856480675917L; \r
protected String name = "";\r
- protected Map<String,CommandParameter> parameters = new HashMap<String,CommandParameter>();\r
+ protected Map<String,CommandParameter> parameters = new HashMap<String,CommandParameter>(); \r
\r
- protected StateManager stateMgr;\r
+ public Pazpar2Command () {\r
\r
- public Pazpar2Command (String name, StateManager stateMgr) {\r
+ }\r
+ \r
+ public void setCommandName(String name) {\r
this.name = name;\r
- this.stateMgr = stateMgr;\r
+ }\r
+ \r
+ public Pazpar2Command (String name) {\r
+ this.name = name; \r
}\r
\r
public abstract Pazpar2Command copy ();\r
- \r
+ \r
public String getCommandName() {\r
return name;\r
}\r
+ \r
+ public ResponseDataObject run() {\r
+ logger.info("Running " + getCommandName() + " using " + Pz2Bean.get().getSearchClient()); \r
+ HttpResponseWrapper httpResponse = Pz2Bean.get().getSearchClient().executeCommand(this);\r
+ logger.info("Parsing response for " + getCommandName());\r
+ ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse) httpResponse);\r
+ logger.info("Storing response for " + getCommandName());\r
+ Pz2Bean.get().getPzresp().put(getCommandName(), responseObject);\r
+ return responseObject;\r
+ }\r
\r
public void setParameter (CommandParameter parameter) {\r
Pazpar2Command copy = this.copy();\r
} \r
\r
private void checkInState(Pazpar2Command command) {\r
- if (stateMgr != null) {\r
- stateMgr.checkIn(command);\r
- } else {\r
- logger.info("Command '" + command.getCommandName() + "' not affecting state (history) as no state manager was defined for this command.");\r
- }\r
+ Pz2Bean.get().getStateMgr().checkIn(command);\r
+ // if (stateMgr() != null) {\r
+ // stateMgr().checkIn(command);\r
+ // } else {\r
+ // logger.info("Command '" + command.getCommandName() + "' not affecting state (history) as no state manager was defined for this command.");\r
+ // }\r
}\r
\r
public abstract ServiceProxyCommand getSp();\r
\r
import java.io.Serializable;\r
\r
-import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
-import javax.inject.Inject;\r
import javax.inject.Named;\r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommands;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
-@Named("pzreq") @SessionScoped\r
+@SessionScoped @Named\r
public class Pazpar2Commands implements Serializable {\r
\r
private static final long serialVersionUID = -5172466320351302413L;\r
public static final String SHOW = "show";\r
public static final String RECORD = "record";\r
public static final String TERMLIST = "termlist";\r
- public static final String BYTARGET = "bytarget";\r
- \r
- private ServiceProxyCommands sp = null;\r
- \r
- @Inject\r
- protected StateManager stateMgr; \r
+ public static final String BYTARGET = "bytarget"; \r
+ private ServiceProxyCommands sp = null; \r
\r
public Pazpar2Commands() {\r
- logger.info("Initializing Pazpar2Commands [" + Utils.objectId(this) + "]");\r
+ logger.info("Initializing Pazpar2Commands [" + Utils.objectId(this) + "]"); \r
}\r
- \r
- @PostConstruct\r
- public void postConstruct() {\r
- logger.info("in post-construct stateMgr is " + stateMgr);\r
- }\r
- \r
+ \r
+ // public void setService(Pz2Bean service) {\r
+ // this.pz2 = service;\r
+ // logger.info("Post construct Pazpar2Command: Service is " + pz2); \r
+ // }\r
+ \r
public InitCommand getInit() {\r
- return (InitCommand) (stateMgr.getCommand(INIT));\r
+ return (InitCommand) (Pz2Bean.get().getStateMgr().getCommand(INIT)); \r
}\r
- \r
+ \r
public PingCommand getPing() {\r
- return (PingCommand) (stateMgr.getCommand(PING));\r
+ return (PingCommand) (Pz2Bean.get().getStateMgr().getCommand(PING));\r
}\r
\r
public SettingsCommand getSettings() {\r
- return (SettingsCommand) (stateMgr.getCommand(SETTINGS));\r
+ return (SettingsCommand) (Pz2Bean.get().getStateMgr().getCommand(SETTINGS));\r
}\r
\r
public SearchCommand getSearch() {\r
- return (SearchCommand) (stateMgr.getCommand(SEARCH));\r
+ return (SearchCommand) (Pz2Bean.get().getStateMgr().getCommand(SEARCH));\r
}\r
\r
public StatCommand getStat() {\r
- return (StatCommand) (stateMgr.getCommand(STAT));\r
+ return (StatCommand) (Pz2Bean.get().getStateMgr().getCommand(STAT));\r
}\r
\r
public ShowCommand getShow() {\r
- return (ShowCommand) (stateMgr.getCommand(SHOW));\r
+ return (ShowCommand) (Pz2Bean.get().getStateMgr().getCommand(SHOW));\r
}\r
\r
public RecordCommand getRecord() {\r
- return (RecordCommand) (stateMgr.getCommand(RECORD));\r
+ return (RecordCommand) (Pz2Bean.get().getStateMgr().getCommand(RECORD));\r
}\r
\r
public TermlistCommand getTermlist() {\r
- return (TermlistCommand) (stateMgr.getCommand(TERMLIST));\r
+ return (TermlistCommand) (Pz2Bean.get().getStateMgr().getCommand(TERMLIST));\r
}\r
\r
public BytargetCommand getBytarget() {\r
- return (BytargetCommand) (stateMgr.getCommand(BYTARGET));\r
+ return (BytargetCommand) (Pz2Bean.get().getStateMgr().getCommand(BYTARGET));\r
}\r
\r
public Pazpar2Command getCommand(String name) { \r
- return stateMgr.getCommand(name);\r
+ return Pz2Bean.get().getStateMgr().getCommand(name);\r
}\r
\r
public ServiceProxyCommands getSp() {\r
if (sp == null) {\r
- sp = new ServiceProxyCommands(stateMgr);\r
+ sp = new ServiceProxyCommands(Pz2Bean.get().getStateMgr());\r
}\r
return sp;\r
}\r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class PingCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 8876721711326535847L;\r
\r
- public PingCommand(StateManager stateMgr) {\r
- super("ping",stateMgr); \r
+ public PingCommand() {\r
+ super("ping"); \r
}\r
\r
public PingCommand copy () {\r
- PingCommand newCommand = new PingCommand(stateMgr);\r
+ PingCommand newCommand = new PingCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
+import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.RecordCommandSp;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
+import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
\r
public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 2817539422114569506L;\r
+ private static Logger logger = Logger.getLogger(RecordCommand.class);\r
\r
- public RecordCommand(StateManager stateMgr) {\r
- super("record",stateMgr);\r
+ public RecordCommand() {\r
+ super("record");\r
+ }\r
+ \r
+ @Override\r
+ public ResponseDataObject run() {\r
+ HttpResponseWrapper commandResponse = Pz2Bean.get().getSearchClient().executeCommand(this);\r
+ ResponseDataObject responseObject = null;\r
+ if (commandResponse.getContentType().contains("xml")) {\r
+ responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);\r
+ if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
+ logger.debug("Storing " + responseObject.getType() + " in pzresp. ");\r
+ } else { \r
+ logger.debug("Command was 'record' but response not '<record>' - assuming raw record response.");\r
+ ResponseDataObject recordResponse = new RecordResponse(); \r
+ recordResponse.setType("record");\r
+ recordResponse.setXml(responseObject.getXml()); \r
+ recordResponse.setAttribute("activeclients", "0"); \r
+ }\r
+ } else if (commandResponse.isBinary()) {\r
+ responseObject = new RecordResponse(); \r
+ responseObject.setType(getCommandName());\r
+ logger.info("Binary response");\r
+ responseObject.setAttribute("activeclients", "0");\r
+ responseObject.setXml("<record>binary response</record>");\r
+ responseObject.setBinary(commandResponse.getBytes());\r
+ \r
+ } else {\r
+ logger.error("Response was not found to be XML or binary. The response was not handled.");\r
+ }\r
+ Pz2Bean.get().getPzresp().put(getCommandName(), responseObject);\r
+ return responseObject;\r
}\r
\r
public void setId(String recId) {\r
\r
@Override\r
public RecordCommand copy () {\r
- RecordCommand newCommand = new RecordCommand(stateMgr);\r
+ RecordCommand newCommand = new RecordCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import javax.enterprise.context.SessionScoped;\r
+import javax.inject.Named;\r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
+import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
\r
-@SessionScoped\r
+@SessionScoped @Named\r
public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = -1888520867838597236L;\r
private static Logger logger = Logger.getLogger(SearchCommand.class);\r
private SingleTargetFilter singleTargetFilter = null;\r
+ \r
+ public SearchCommand() {\r
+ super("search");\r
+ }\r
\r
- public SearchCommand(StateManager stateMgr) {\r
- super("search",stateMgr);\r
+ public ResponseDataObject run() {\r
+ logger.info("Running " + getCommandName());\r
+ logger.info("Using client " + Pz2Bean.get().getSearchClient());\r
+ logger.info("Storing responses to " + Pz2Bean.get().getPzresp());\r
+ Pz2Bean.get().getSearchClient().setSearchCommand(this);\r
+ logger.info("Executing command " + getCommandName());\r
+ HttpResponseWrapper httpResponse = Pz2Bean.get().getSearchClient().executeCommand(this);\r
+ ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse) httpResponse);\r
+ Pz2Bean.get().getPzresp().put(getCommandName(), responseObject);\r
+ return responseObject;\r
}\r
+\r
\r
public void setQuery(String query) { \r
setParameter(new CommandParameter("query","=",query));\r
}\r
\r
public SearchCommand copy () {\r
- SearchCommand newCommand = new SearchCommand(stateMgr);\r
+ SearchCommand newCommand = new SearchCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
}\r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class SettingsCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 2291179325470387102L;\r
\r
- public SettingsCommand(StateManager stateMgr) {\r
- super("settings",stateMgr);\r
+ public SettingsCommand() {\r
+ super("settings");\r
// TODO Auto-generated constructor stub\r
}\r
\r
public SettingsCommand copy () {\r
- SettingsCommand newCommand = new SettingsCommand(stateMgr);\r
+ SettingsCommand newCommand = new SettingsCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class ShowCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = -8242768313266051307L;\r
\r
- public ShowCommand(StateManager stateMgr) {\r
- super("show",stateMgr);\r
+ public ShowCommand() {\r
+ super("show");\r
setParameterInState(new CommandParameter("start","=","0"));\r
}\r
\r
}\r
\r
public ShowCommand copy () {\r
- ShowCommand newCommand = new ShowCommand(stateMgr);\r
+ ShowCommand newCommand = new ShowCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class StatCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 3980630346114157336L;\r
\r
- public StatCommand(StateManager stateMgr) {\r
- super("stat",stateMgr);\r
+ public StatCommand() {\r
+ super("stat");\r
}\r
\r
public StatCommand copy () {\r
- StatCommand newCommand = new StatCommand(stateMgr);\r
+ StatCommand newCommand = new StatCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
package com.indexdata.mkjsf.pazpar2.commands;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class TermlistCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = -7067878552863021727L;\r
\r
- public TermlistCommand(StateManager stateMgr) {\r
- super("termlist",stateMgr);\r
+ public TermlistCommand() {\r
+ super("termlist");\r
}\r
\r
public void setName(String names) {\r
}\r
\r
public TermlistCommand copy () {\r
- TermlistCommand newCommand = new TermlistCommand(stateMgr);\r
+ TermlistCommand newCommand = new TermlistCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
\r
import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 5487611235664162578L;\r
\r
- public AuthCommand(StateManager stateMgr) {\r
- super("auth", stateMgr);\r
+ public AuthCommand() {\r
+ super("auth");\r
}\r
\r
public void setAction (String action) {\r
}\r
\r
public AuthCommand copy () {\r
- AuthCommand newCommand = new AuthCommand(stateMgr);\r
+ AuthCommand newCommand = new AuthCommand();\r
for (String parameterName : parameters.keySet()) {\r
newCommand.setParameterInState(parameters.get(parameterName).copy()); \r
} \r
package com.indexdata.mkjsf.pazpar2.commands.sp;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
\r
public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCommand {\r
\r
private static final long serialVersionUID = 5023993689780291641L;\r
\r
- public CategoriesCommand(StateManager stateMgr) {\r
- super("categories", stateMgr);\r
+ public CategoriesCommand() {\r
+ super("categories");\r
}\r
\r
@Override\r
public Pazpar2Command copy() {\r
- CategoriesCommand newCommand = new CategoriesCommand(stateMgr);\r
+ CategoriesCommand newCommand = new CategoriesCommand();\r
return newCommand;\r
}\r
\r
import java.util.regex.Pattern;\r
\r
import com.indexdata.mkjsf.errors.ErrorHelper;\r
-import com.indexdata.mkjsf.errors.ErrorInterface;\r
import com.indexdata.mkjsf.errors.ErrorHelper.ErrorCode;\r
+import com.indexdata.mkjsf.errors.ErrorInterface;\r
import com.indexdata.utils.XmlUtils;\r
\r
/**\r
}\r
\r
public List<String> getSuggestions() { \r
- if (errorHelper!=null) {\r
+ if (errorHelper!=null) { \r
return errorHelper.getSuggestions(this);\r
} else {\r
List<String> nohelper = new ArrayList<String>();\r
import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
-@Named("pzresp") @SessionScoped\r
+@SessionScoped @Named\r
public class Responses implements Serializable {\r
\r
private static final long serialVersionUID = -7543231258346154642L;\r
public class Pazpar2State {\r
\r
String key = null;\r
- Map<String,Pazpar2Command> commands = new HashMap<String,Pazpar2Command>();;\r
+ Map<String,Pazpar2Command> commands = new HashMap<String,Pazpar2Command>(); \r
\r
- public Pazpar2State (StateManager stateManager) {\r
- commands.put(Pazpar2Commands.INIT, new InitCommand(stateManager));\r
- commands.put(Pazpar2Commands.PING, new PingCommand(stateManager));\r
- commands.put(Pazpar2Commands.SETTINGS, new SettingsCommand(stateManager));\r
- commands.put(Pazpar2Commands.SEARCH, new SearchCommand(stateManager));\r
- commands.put(Pazpar2Commands.STAT, new StatCommand(stateManager));\r
- commands.put(Pazpar2Commands.SHOW, new ShowCommand(stateManager));\r
- commands.put(Pazpar2Commands.RECORD, new RecordCommand(stateManager));\r
- commands.put(Pazpar2Commands.TERMLIST, new TermlistCommand(stateManager));\r
- commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand(stateManager)); \r
+ public Pazpar2State () {\r
+ \r
+ commands.put(Pazpar2Commands.INIT, new InitCommand());\r
+ commands.put(Pazpar2Commands.PING, new PingCommand());\r
+ commands.put(Pazpar2Commands.SETTINGS, new SettingsCommand());\r
+ commands.put(Pazpar2Commands.SEARCH, new SearchCommand());\r
+ commands.put(Pazpar2Commands.STAT, new StatCommand());\r
+ commands.put(Pazpar2Commands.SHOW, new ShowCommand());\r
+ commands.put(Pazpar2Commands.RECORD, new RecordCommand());\r
+ commands.put(Pazpar2Commands.TERMLIST, new TermlistCommand());\r
+ commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand()); \r
\r
- commands.put(ServiceProxyCommands.AUTH, new AuthCommand(stateManager));\r
- commands.put(ServiceProxyCommands.CATEGORIES, new CategoriesCommand(stateManager));\r
+ commands.put(ServiceProxyCommands.AUTH, new AuthCommand());\r
+ commands.put(ServiceProxyCommands.CATEGORIES, new CategoriesCommand());\r
+ \r
// key = "#1";\r
}\r
\r
this.commands.put(commandName, previousState.commands.get(commandName).copy());\r
}\r
this.commands.put(newCommand.getCommandName(),newCommand);\r
- this.key = getKey(); \r
+ this.key = getKey(); \r
}\r
\r
/**\r
import java.util.List;\r
import java.util.Map;\r
\r
-import javax.enterprise.context.SessionScoped;\r
-\r
import org.apache.log4j.Logger;\r
\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
-@SessionScoped\r
public class StateManager implements Serializable {\r
\r
private static final long serialVersionUID = 8152558351351730035L;\r
/* SP extras */ "auth","categories"));\r
Map<String,Boolean> pendingStateChanges = new HashMap<String,Boolean>();\r
private static Logger logger = Logger.getLogger(StateManager.class);\r
- private List<StateListener> listeners = new ArrayList<StateListener>();\r
+ private List<StateListener> listeners = new ArrayList<StateListener>(); \r
\r
public StateManager () {\r
logger.info("Initializing a Pazpar2 state manager [" + Utils.objectId(this) + "]");\r
- Pazpar2State initialState = new Pazpar2State(this);\r
+ Pazpar2State initialState = new Pazpar2State();\r
states.put(initialState.getKey(), initialState);\r
currentKey = initialState.getKey();\r
for (String command : allCommands) {\r
pendingStateChanges.put(command, new Boolean(false));\r
- }\r
+ } \r
}\r
\r
public void addStateListener(StateListener listener) {\r