import org.apache.log4j.Logger;\r
\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
-import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
\r
@SessionScoped @Named\r
public class ErrorCentral implements Serializable {\r
}\r
\r
public boolean hasCommandErrors () {\r
- return Pz2Bean.get().getPzresp().hasApplicationError();\r
+ return Pz2Service.get().getPzresp().hasApplicationError();\r
}\r
\r
public ErrorInterface getCommandError () {\r
- return Pz2Bean.get().getPzresp().getCommandError();\r
+ return Pz2Service.get().getPzresp().getCommandError();\r
}\r
\r
/**\r
+++ /dev/null
-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
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.StringTokenizer;\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
-import com.indexdata.mkjsf.config.Configurable;\r
-import com.indexdata.mkjsf.config.Configuration;\r
-import com.indexdata.mkjsf.config.ConfigurationReader;\r
-import com.indexdata.mkjsf.controls.ResultsPager;\r
-import com.indexdata.mkjsf.errors.ConfigurationError;\r
-import com.indexdata.mkjsf.errors.ConfigurationException;\r
-import com.indexdata.mkjsf.errors.ErrorCentral;\r
-import com.indexdata.mkjsf.errors.ErrorHelper;\r
-import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
-import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
-import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
-import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
-import com.indexdata.mkjsf.pazpar2.data.Responses;\r
-import com.indexdata.mkjsf.pazpar2.state.StateListener;\r
-import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
-import com.indexdata.mkjsf.utils.Utils;\r
-\r
-@Named("pz2") @SessionScoped\r
-public class Pz2Bean implements Pz2Interface, StateListener, Configurable, Serializable {\r
-\r
- private static final String MODULE_NAME = "service";\r
- private static String SERVICE_TYPE_TBD = "TBD", SERVICE_TYPE_PZ2 = "PZ2", SERVICE_TYPE_SP = "SP";\r
- private static final List<String> serviceTypes = \r
- Arrays.asList(SERVICE_TYPE_PZ2,SERVICE_TYPE_SP,SERVICE_TYPE_TBD);\r
- private String serviceType = SERVICE_TYPE_TBD;\r
- private List<String> serviceProxyUrls = new ArrayList<String>();\r
- public static final String SERVICE_PROXY_URL_LIST = "SERVICE_PROXY_URL_LIST";\r
- private List<String> pazpar2Urls = new ArrayList<String>();\r
- public static final String PAZPAR2_URL_LIST = "PAZPAR2_URL_LIST";\r
-\r
-\r
- private static final long serialVersionUID = 3440277287081557861L;\r
- private static Logger logger = Logger.getLogger(Pz2Bean.class); \r
- protected Pz2Client pz2Client = null;\r
- protected ServiceProxyClient spClient = null;\r
- protected SearchClient searchClient = null; \r
- \r
- @Inject ConfigurationReader configurator;\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
- protected ErrorHelper errorHelper = null;\r
- \r
- public Pz2Bean () {\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.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
- spClient = new ServiceProxyClient();\r
- configureClient(spClient,configurator);\r
- try {\r
- this.configure(configurator);\r
- } catch (ConfigurationException e) {\r
- logger.error("There was a problem configuring the Pz2Bean (\"pz2\")");\r
- e.printStackTrace();\r
- } \r
- stateMgr.addStateListener(this); \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.trace("Producing pzresp");\r
- return pzresp;\r
- }\r
- \r
- @Produces @Preferred @SessionScoped @Named("pzreq") public Pazpar2Commands getPzreq () {\r
- logger.trace("Producing pzreq");\r
- return pzreq;\r
- }\r
- \r
- @Produces @Preferred @SessionScoped @Named("errors") public ErrorCentral getErrors() {\r
- logger.trace("Producing errors");\r
- return errors;\r
- }\r
- \r
- @Produces @Preferred @SessionScoped @Named("stateMgr") public StateManager getStateMgr() {\r
- logger.trace("Producing stateMgr");\r
- return stateMgr;\r
- }\r
- \r
- public void configureClient(SearchClient client, ConfigurationReader configReader) {\r
- logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
- try {\r
- client.configure(configReader); \r
- } catch (ConfigurationException e) {\r
- logger.debug("Pz2Bean adding configuration error");\r
- errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage())); \r
- } \r
- logger.info(configReader.document());\r
- pzresp.getSp().resetAuthAndBeyond(true); \r
- }\r
- \r
- public void resetSearchAndRecordCommands () {\r
- pzreq.getRecord().removeParametersInState();\r
- pzreq.getSearch().removeParametersInState(); \r
- }\r
- \r
- /**\r
- * Refreshes 'show', 'stat', 'termlist', and 'bytarget' data object from pazpar2\r
- * \r
- * @return Number of activeclients at the time of the 'show' command.\r
- */\r
- public String update () {\r
- logger.debug("Updating show,stat,termlist,bytarget from pazpar2");\r
- if (errors.hasConfigurationErrors()) {\r
- logger.error("Ignoring show,stat,termlist,bytarget commands due to configuration errors.");\r
- return "";\r
- } else if (pzresp.getSearch().hasApplicationError()) {\r
- logger.error("Ignoring show,stat,termlist,bytarget commands due to problem with most recent search.");\r
- return "";\r
- } else if (!hasQuery()) {\r
- logger.debug("Ignoring show,stat,termlist,bytarget commands because there is not yet a query.");\r
- return "";\r
- } else {\r
- return update("show,stat,termlist,bytarget");\r
- }\r
- }\r
- \r
- /**\r
- * Refreshes the data objects listed in 'commands' from pazpar2\r
- * \r
- * @param commands\r
- * @return Number of activeclients at the time of the 'show' command,\r
- * or 'new' if search was just initiated.\r
- */\r
- public String update (String commands) {\r
- logger.debug("Request to update: " + commands);\r
- try {\r
- if (commands.equals("search")) {\r
- pzreq.getSearch().run();\r
- return "new";\r
- } else if (commands.equals("record")) {\r
- pzreq.getRecord().run();\r
- return pzresp.getRecord().getActiveClients();\r
- } else if (pzresp.getSearch().isNew()) {\r
- // For returning notification of 'search started' quickly to UI\r
- logger.info("New search. Marking it old, then returning 'new' to trigger another round-trip.");\r
- pzresp.getSearch().setIsNew(false);\r
- return "new";\r
- } else {\r
- handleQueryStateChanges(commands);\r
- if (pzresp.getSearch().hasApplicationError()) {\r
- logger.error("The command(s) " + commands + " cancelled because the latest search command had an error.");\r
- return "0";\r
- } else if (errors.hasConfigurationErrors()) {\r
- logger.error("The command(s) " + commands + " cancelled due to configuration errors.");\r
- return "0";\r
- } else {\r
- logger.debug("Processing request for " + commands); \r
- List<CommandThread> threadList = new ArrayList<CommandThread>();\r
- StringTokenizer tokens = new StringTokenizer(commands,",");\r
- while (tokens.hasMoreElements()) { \r
- threadList.add(new CommandThread(pzreq.getCommand(tokens.nextToken()),searchClient,Pz2Bean.get().getPzresp())); \r
- }\r
- for (CommandThread thread : threadList) {\r
- thread.start();\r
- }\r
- for (CommandThread thread : threadList) {\r
- try {\r
- thread.join();\r
- } catch (InterruptedException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return pzresp.getActiveClients();\r
- }\r
- } \r
- } catch (ClassCastException cce) {\r
- cce.printStackTrace(); \r
- return "";\r
- } catch (NullPointerException npe) {\r
- npe.printStackTrace();\r
- return "";\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return "";\r
- }\r
- \r
- }\r
- \r
- public String toggleRecord (String recId) {\r
- if (hasRecord(recId)) {\r
- pzreq.getRecord().removeParameters(); \r
- pzresp.put("record", new RecordResponse());\r
- return "";\r
- } else {\r
- pzreq.getRecord().setId(recId);\r
- doCommand("record");\r
- return pzresp.getRecord().getActiveClients();\r
- }\r
- }\r
- \r
- @Override\r
- public boolean hasRecord (String recId) {\r
- return pzreq.getCommand("record").hasParameters() && pzresp.getRecord().getRecId().equals(recId);\r
- }\r
- \r
- public String getCurrentStateKey () { \r
- return stateMgr.getCurrentState().getKey();\r
- }\r
- \r
- public void setCurrentStateKey(String key) { \r
- stateMgr.setCurrentStateKey(key);\r
- }\r
- \r
- protected boolean hasQuery() { \r
- return pzreq.getCommand("search").hasParameterValue("query"); \r
- }\r
- \r
- \r
- @Override\r
- public ResultsPager getPager () {\r
- if (pager == null) {\r
- pager = new ResultsPager(pzresp); \r
- } \r
- return pager; \r
- }\r
- \r
- @Override\r
- public ResultsPager setPager (int pageRange) {\r
- pager = new ResultsPager(pzresp,pageRange,pzreq);\r
- return pager;\r
- }\r
- \r
- /**\r
- * This methods main purpose is to support browser history.\r
- * \r
- * When the browsers back or forward buttons are pressed, a \r
- * re-search /might/ be required - namely if the query changes.\r
- * So, as the UI requests updates of the page (show,facets,\r
- * etc) this method checks if a search must be executed\r
- * before those updates are performed.\r
- * \r
- * @see {@link com.indexdata.mkjsf.pazpar2.state.StateManager#setCurrentStateKey} \r
- * @param commands\r
- */\r
- protected void handleQueryStateChanges (String commands) {\r
- if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
- logger.info("Triggered search: Found pending search change [" + pzreq.getCommand("search").toString() + "], doing search before updating " + commands); \r
- pzreq.getSearch().run();\r
- } \r
- if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { \r
- logger.debug("Found pending record ID change. Doing record before updating " + commands);\r
- stateMgr.hasPendingStateChange("record",false);\r
- pzreq.getRecord().run();\r
- }\r
- }\r
- \r
- /**\r
- * Executes the command and parses the response to create data objects.\r
- * If the parsed response is of a known type it will be cached in 'pzresp'\r
- * \r
- * @param commandName The command to be executed\r
- * @return An XML response parsed to form a response data object\r
- */\r
- protected ResponseDataObject doCommand(String commandName) {\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
- logger.info("Request "+commandName + ". Search command is: "+ pzreq.getCommand("search").toString()); \r
- long start = System.currentTimeMillis();\r
- ResponseDataObject responseObject = command.run(); \r
- long end = System.currentTimeMillis();\r
- logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
- return responseObject;\r
- }\r
- }\r
- \r
- @Override\r
- public void stateUpdated(String commandName) {\r
- logger.debug("State change reported for [" + commandName + "]");\r
- if (commandName.equals("show")) {\r
- logger.debug("Updating show");\r
- update(commandName);\r
- } \r
- }\r
- \r
- public void setServiceProxyUrl(String url) {\r
- searchClient = spClient;\r
- setServiceType(SERVICE_TYPE_SP);\r
- setServiceUrl(url);\r
- }\r
- \r
- public String getServiceProxyUrl () {\r
- if (isServiceProxyService()) {\r
- return spClient.getServiceUrl();\r
- } else {\r
- return "";\r
- }\r
- }\r
- \r
- public void setPazpar2Url(String url) {\r
- searchClient = pz2Client;\r
- setServiceType(SERVICE_TYPE_PZ2);\r
- setServiceUrl(url);\r
- }\r
- \r
- public String getPazpar2Url() {\r
- if (isPazpar2Service()) {\r
- return pz2Client.getServiceUrl();\r
- } else {\r
- return "";\r
- }\r
- }\r
-\r
- \r
- @Override\r
- public void setServiceUrl(String url) {\r
- if (url!=null && searchClient != null && !url.equals(searchClient.getServiceUrl())) {\r
- pzreq.getRecord().removeParametersInState();\r
- pzreq.getSearch().removeParametersInState();\r
- pzresp.getSp().resetAuthAndBeyond(true); \r
- searchClient.setServiceUrl(url);\r
- } \r
- }\r
- \r
- public String getServiceUrl() {\r
- return (searchClient!=null ? searchClient.getServiceUrl() : "");\r
- }\r
- \r
- public void setServiceId () {\r
- pzreq.getRecord().removeParametersInState();\r
- pzreq.getSearch().removeParametersInState();\r
- pzresp.resetSearchAndBeyond();\r
- pz2Client.setServiceId(pzreq.getInit().getService());\r
- }\r
- \r
- public String getServiceId () {\r
- return pzreq.getInit().getService();\r
- }\r
- \r
- public boolean getServiceUrlIsDefined() {\r
- return (searchClient != null && searchClient.hasServiceUrl());\r
- }\r
- \r
- public List<String> getServiceProxyUrls() {\r
- List<String> urls = new ArrayList<String>();\r
- urls.add("");\r
- urls.addAll(serviceProxyUrls);\r
- return urls;\r
- }\r
- \r
- public List<String> getPazpar2Urls () {\r
- List<String> urls = new ArrayList<String>();\r
- urls.add("");\r
- urls.addAll(pazpar2Urls);\r
- return urls;\r
- }\r
- \r
- public String getServiceType () {\r
- return serviceType;\r
- }\r
- \r
- public boolean isPazpar2Service () {\r
- return serviceType.equals(SERVICE_TYPE_PZ2);\r
- }\r
- \r
- public boolean isServiceProxyService() {\r
- return serviceType.equals(SERVICE_TYPE_SP);\r
- }\r
- \r
- public boolean serviceIsToBeDecided () {\r
- return serviceType.equals(SERVICE_TYPE_TBD);\r
- }\r
- \r
- public ServiceProxyClient getSpClient () {\r
- return spClient;\r
- } \r
- \r
- @Override\r
- public boolean getAuthenticationRequired () {\r
- return spClient.isAuthenticatingClient();\r
- }\r
-\r
- @Override\r
- public String getCheckHistory () {\r
- return ":pz2watch:stateForm:windowlocationhash";\r
- }\r
- \r
- @Override\r
- public String getWatchActiveclients () {\r
- return ":pz2watch:activeclientsForm:activeclientsField";\r
- }\r
- \r
- @Override\r
- public String getWatchActiveclientsRecord () {\r
- return ":pz2watch:activeclientsForm:activeclientsFieldRecord";\r
- }\r
-\r
- @Override\r
- public void configure(ConfigurationReader reader)\r
- throws ConfigurationException {\r
- Configuration config = reader.getConfiguration(this);\r
- if (config == null) {\r
- serviceType = SERVICE_TYPE_TBD;\r
- } else {\r
- String service = config.get("TYPE");\r
- if (service == null || service.length()==0) {\r
- serviceType = SERVICE_TYPE_TBD;\r
- } else if (serviceTypes.contains(service.toUpperCase())) { \r
- setServiceType(service.toUpperCase());\r
- } else {\r
- logger.error("Unknown serviceType type in configuration [" + service + "], can be one of " + serviceTypes);\r
- serviceType = SERVICE_TYPE_TBD;\r
- }\r
- serviceProxyUrls = config.getMultiProperty(SERVICE_PROXY_URL_LIST,",");\r
- pazpar2Urls = config.getMultiProperty(PAZPAR2_URL_LIST, ",");\r
- }\r
- logger.info(reader.document());\r
- logger.info("Service Type is configured to " + serviceType);\r
- \r
- }\r
-\r
- @Override\r
- public Map<String, String> getDefaults() {\r
- return new HashMap<String,String>();\r
- }\r
-\r
- @Override\r
- public String getModuleName() {\r
- return MODULE_NAME;\r
- }\r
-\r
- @Override\r
- public List<String> documentConfiguration() {\r
- return new ArrayList<String>();\r
- }\r
-\r
- @Override\r
- public void setServiceTypePZ2() {\r
- setServiceType(SERVICE_TYPE_PZ2); \r
- }\r
-\r
- @Override\r
- public void setServiceTypeSP() {\r
- setServiceType(SERVICE_TYPE_SP); \r
- }\r
-\r
- @Override\r
- public void setServiceTypeTBD() {\r
- setServiceType(SERVICE_TYPE_TBD); \r
- }\r
- \r
- private void setServiceType(String type) {\r
- if (!serviceType.equals(type) &&\r
- !serviceType.equals(SERVICE_TYPE_TBD)) {\r
- resetSearchAndRecordCommands();\r
- pzresp.getSp().resetAuthAndBeyond(true);\r
- }\r
- serviceType = type;\r
- if (serviceType.equals(SERVICE_TYPE_PZ2)) {\r
- searchClient = pz2Client;\r
- logger.info("Setting a Pazpar2 client to serve requests.");\r
- } else if (serviceType.equals(SERVICE_TYPE_SP)) {\r
- searchClient = spClient;\r
- logger.info("Setting a Service Proxy client to serve requests.");\r
- } else {\r
- logger.info("Clearing search client. No client defined to serve requests at this point.");\r
- searchClient = null;\r
- }\r
- }\r
- \r
- public SearchClient getSearchClient() {\r
- return searchClient;\r
- }\r
- \r
-}\r
--- /dev/null
+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
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.StringTokenizer;\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
+import com.indexdata.mkjsf.config.Configurable;\r
+import com.indexdata.mkjsf.config.Configuration;\r
+import com.indexdata.mkjsf.config.ConfigurationReader;\r
+import com.indexdata.mkjsf.controls.ResultsPager;\r
+import com.indexdata.mkjsf.errors.ConfigurationError;\r
+import com.indexdata.mkjsf.errors.ConfigurationException;\r
+import com.indexdata.mkjsf.errors.ErrorCentral;\r
+import com.indexdata.mkjsf.errors.ErrorHelper;\r
+import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
+import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
+import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
+import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
+import com.indexdata.mkjsf.pazpar2.data.Responses;\r
+import com.indexdata.mkjsf.pazpar2.state.StateListener;\r
+import com.indexdata.mkjsf.pazpar2.state.StateManager;\r
+import com.indexdata.mkjsf.utils.Utils;\r
+\r
+@Named("pz2") @SessionScoped\r
+public class Pz2Service implements Pz2Interface, StateListener, Configurable, Serializable {\r
+\r
+ private static final String MODULE_NAME = "service";\r
+ private static String SERVICE_TYPE_TBD = "TBD", SERVICE_TYPE_PZ2 = "PZ2", SERVICE_TYPE_SP = "SP";\r
+ private static final List<String> serviceTypes = \r
+ Arrays.asList(SERVICE_TYPE_PZ2,SERVICE_TYPE_SP,SERVICE_TYPE_TBD);\r
+ private String serviceType = SERVICE_TYPE_TBD;\r
+ private List<String> serviceProxyUrls = new ArrayList<String>();\r
+ public static final String SERVICE_PROXY_URL_LIST = "SERVICE_PROXY_URL_LIST";\r
+ private List<String> pazpar2Urls = new ArrayList<String>();\r
+ public static final String PAZPAR2_URL_LIST = "PAZPAR2_URL_LIST";\r
+\r
+\r
+ private static final long serialVersionUID = 3440277287081557861L;\r
+ private static Logger logger = Logger.getLogger(Pz2Service.class); \r
+ protected Pz2Client pz2Client = null;\r
+ protected ServiceProxyClient spClient = null;\r
+ protected SearchClient searchClient = null; \r
+ \r
+ @Inject ConfigurationReader configurator;\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
+ protected ErrorHelper errorHelper = null;\r
+ \r
+ public Pz2Service () {\r
+ logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]"); \r
+ }\r
+ \r
+ public static Pz2Service get() {\r
+ FacesContext context = FacesContext.getCurrentInstance();\r
+ return (Pz2Service) context.getApplication().evaluateExpressionGet(context, "#{pz2}", Object.class); \r
+ }\r
+ \r
+ @PostConstruct\r
+ public void postConstruct() {\r
+ logger.info("Pz2Service 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("Pz2Service PostConstruct: Configurator is " + configurator);\r
+ logger.debug(Utils.objectId(this) + " will instantiate a Pz2Client next.");\r
+ pz2Client = new Pz2Client();\r
+ configureClient(pz2Client,configurator);\r
+ spClient = new ServiceProxyClient();\r
+ configureClient(spClient,configurator);\r
+ try {\r
+ this.configure(configurator);\r
+ } catch (ConfigurationException e) {\r
+ logger.error("There was a problem configuring the Pz2Service (\"pz2\")");\r
+ e.printStackTrace();\r
+ } \r
+ stateMgr.addStateListener(this); \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.trace("Producing pzresp");\r
+ return pzresp;\r
+ }\r
+ \r
+ @Produces @Preferred @SessionScoped @Named("pzreq") public Pazpar2Commands getPzreq () {\r
+ logger.trace("Producing pzreq");\r
+ return pzreq;\r
+ }\r
+ \r
+ @Produces @Preferred @SessionScoped @Named("errors") public ErrorCentral getErrors() {\r
+ logger.trace("Producing errors");\r
+ return errors;\r
+ }\r
+ \r
+ @Produces @Preferred @SessionScoped @Named("stateMgr") public StateManager getStateMgr() {\r
+ logger.trace("Producing stateMgr");\r
+ return stateMgr;\r
+ }\r
+ \r
+ public void configureClient(SearchClient client, ConfigurationReader configReader) {\r
+ logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
+ try {\r
+ client.configure(configReader); \r
+ } catch (ConfigurationException e) {\r
+ logger.debug("Pz2Service adding configuration error");\r
+ errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage())); \r
+ } \r
+ logger.info(configReader.document());\r
+ pzresp.getSp().resetAuthAndBeyond(true); \r
+ }\r
+ \r
+ public void resetSearchAndRecordCommands () {\r
+ pzreq.getRecord().removeParametersInState();\r
+ pzreq.getSearch().removeParametersInState(); \r
+ }\r
+ \r
+ /**\r
+ * Refreshes 'show', 'stat', 'termlist', and 'bytarget' data object from pazpar2\r
+ * \r
+ * @return Number of activeclients at the time of the 'show' command.\r
+ */\r
+ public String update () {\r
+ logger.debug("Updating show,stat,termlist,bytarget from pazpar2");\r
+ if (errors.hasConfigurationErrors()) {\r
+ logger.error("Ignoring show,stat,termlist,bytarget commands due to configuration errors.");\r
+ return "";\r
+ } else if (pzresp.getSearch().hasApplicationError()) {\r
+ logger.error("Ignoring show,stat,termlist,bytarget commands due to problem with most recent search.");\r
+ return "";\r
+ } else if (!hasQuery()) {\r
+ logger.debug("Ignoring show,stat,termlist,bytarget commands because there is not yet a query.");\r
+ return "";\r
+ } else {\r
+ return update("show,stat,termlist,bytarget");\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Refreshes the data objects listed in 'commands' from pazpar2\r
+ * \r
+ * @param commands\r
+ * @return Number of activeclients at the time of the 'show' command,\r
+ * or 'new' if search was just initiated.\r
+ */\r
+ public String update (String commands) {\r
+ logger.debug("Request to update: " + commands);\r
+ try {\r
+ if (commands.equals("search")) {\r
+ pzreq.getSearch().run();\r
+ return "new";\r
+ } else if (commands.equals("record")) {\r
+ pzreq.getRecord().run();\r
+ return pzresp.getRecord().getActiveClients();\r
+ } else if (pzresp.getSearch().isNew()) {\r
+ // For returning notification of 'search started' quickly to UI\r
+ logger.info("New search. Marking it old, then returning 'new' to trigger another round-trip.");\r
+ pzresp.getSearch().setIsNew(false);\r
+ return "new";\r
+ } else {\r
+ handleQueryStateChanges(commands);\r
+ if (pzresp.getSearch().hasApplicationError()) {\r
+ logger.error("The command(s) " + commands + " cancelled because the latest search command had an error.");\r
+ return "0";\r
+ } else if (errors.hasConfigurationErrors()) {\r
+ logger.error("The command(s) " + commands + " cancelled due to configuration errors.");\r
+ return "0";\r
+ } else {\r
+ logger.debug("Processing request for " + commands); \r
+ List<CommandThread> threadList = new ArrayList<CommandThread>();\r
+ StringTokenizer tokens = new StringTokenizer(commands,",");\r
+ while (tokens.hasMoreElements()) { \r
+ threadList.add(new CommandThread(pzreq.getCommand(tokens.nextToken()),searchClient,Pz2Service.get().getPzresp())); \r
+ }\r
+ for (CommandThread thread : threadList) {\r
+ thread.start();\r
+ }\r
+ for (CommandThread thread : threadList) {\r
+ try {\r
+ thread.join();\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return pzresp.getActiveClients();\r
+ }\r
+ } \r
+ } catch (ClassCastException cce) {\r
+ cce.printStackTrace(); \r
+ return "";\r
+ } catch (NullPointerException npe) {\r
+ npe.printStackTrace();\r
+ return "";\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return "";\r
+ }\r
+ \r
+ }\r
+ \r
+ public String toggleRecord (String recId) {\r
+ if (hasRecord(recId)) {\r
+ pzreq.getRecord().removeParameters(); \r
+ pzresp.put("record", new RecordResponse());\r
+ return "";\r
+ } else {\r
+ pzreq.getRecord().setId(recId);\r
+ doCommand("record");\r
+ return pzresp.getRecord().getActiveClients();\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public boolean hasRecord (String recId) {\r
+ return pzreq.getCommand("record").hasParameters() && pzresp.getRecord().getRecId().equals(recId);\r
+ }\r
+ \r
+ public String getCurrentStateKey () { \r
+ return stateMgr.getCurrentState().getKey();\r
+ }\r
+ \r
+ public void setCurrentStateKey(String key) { \r
+ stateMgr.setCurrentStateKey(key);\r
+ }\r
+ \r
+ protected boolean hasQuery() { \r
+ return pzreq.getCommand("search").hasParameterValue("query"); \r
+ }\r
+ \r
+ \r
+ @Override\r
+ public ResultsPager getPager () {\r
+ if (pager == null) {\r
+ pager = new ResultsPager(pzresp); \r
+ } \r
+ return pager; \r
+ }\r
+ \r
+ @Override\r
+ public ResultsPager setPager (int pageRange) {\r
+ pager = new ResultsPager(pzresp,pageRange,pzreq);\r
+ return pager;\r
+ }\r
+ \r
+ /**\r
+ * This methods main purpose is to support browser history.\r
+ * \r
+ * When the browsers back or forward buttons are pressed, a \r
+ * re-search /might/ be required - namely if the query changes.\r
+ * So, as the UI requests updates of the page (show,facets,\r
+ * etc) this method checks if a search must be executed\r
+ * before those updates are performed.\r
+ * \r
+ * @see {@link com.indexdata.mkjsf.pazpar2.state.StateManager#setCurrentStateKey} \r
+ * @param commands\r
+ */\r
+ protected void handleQueryStateChanges (String commands) {\r
+ if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
+ logger.info("Triggered search: Found pending search change [" + pzreq.getCommand("search").toString() + "], doing search before updating " + commands); \r
+ pzreq.getSearch().run();\r
+ } \r
+ if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { \r
+ logger.debug("Found pending record ID change. Doing record before updating " + commands);\r
+ stateMgr.hasPendingStateChange("record",false);\r
+ pzreq.getRecord().run();\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Executes the command and parses the response to create data objects.\r
+ * If the parsed response is of a known type it will be cached in 'pzresp'\r
+ * \r
+ * @param commandName The command to be executed\r
+ * @return An XML response parsed to form a response data object\r
+ */\r
+ protected ResponseDataObject doCommand(String commandName) {\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
+ logger.info("Request "+commandName + ". Search command is: "+ pzreq.getCommand("search").toString()); \r
+ long start = System.currentTimeMillis();\r
+ ResponseDataObject responseObject = command.run(); \r
+ long end = System.currentTimeMillis();\r
+ logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
+ return responseObject;\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void stateUpdated(String commandName) {\r
+ logger.debug("State change reported for [" + commandName + "]");\r
+ if (commandName.equals("show")) {\r
+ logger.debug("Updating show");\r
+ update(commandName);\r
+ } \r
+ }\r
+ \r
+ public void setServiceProxyUrl(String url) {\r
+ searchClient = spClient;\r
+ setServiceType(SERVICE_TYPE_SP);\r
+ setServiceUrl(url);\r
+ }\r
+ \r
+ public String getServiceProxyUrl () {\r
+ if (isServiceProxyService()) {\r
+ return spClient.getServiceUrl();\r
+ } else {\r
+ return "";\r
+ }\r
+ }\r
+ \r
+ public void setPazpar2Url(String url) {\r
+ searchClient = pz2Client;\r
+ setServiceType(SERVICE_TYPE_PZ2);\r
+ setServiceUrl(url);\r
+ }\r
+ \r
+ public String getPazpar2Url() {\r
+ if (isPazpar2Service()) {\r
+ return pz2Client.getServiceUrl();\r
+ } else {\r
+ return "";\r
+ }\r
+ }\r
+\r
+ \r
+ @Override\r
+ public void setServiceUrl(String url) {\r
+ if (url!=null && searchClient != null && !url.equals(searchClient.getServiceUrl())) {\r
+ pzreq.getRecord().removeParametersInState();\r
+ pzreq.getSearch().removeParametersInState();\r
+ pzresp.getSp().resetAuthAndBeyond(true); \r
+ searchClient.setServiceUrl(url);\r
+ } \r
+ }\r
+ \r
+ public String getServiceUrl() {\r
+ return (searchClient!=null ? searchClient.getServiceUrl() : "");\r
+ }\r
+ \r
+ public void setServiceId () {\r
+ pzreq.getRecord().removeParametersInState();\r
+ pzreq.getSearch().removeParametersInState();\r
+ pzresp.resetSearchAndBeyond();\r
+ pz2Client.setServiceId(pzreq.getInit().getService());\r
+ }\r
+ \r
+ public String getServiceId () {\r
+ return pzreq.getInit().getService();\r
+ }\r
+ \r
+ public boolean getServiceUrlIsDefined() {\r
+ return (searchClient != null && searchClient.hasServiceUrl());\r
+ }\r
+ \r
+ public List<String> getServiceProxyUrls() {\r
+ List<String> urls = new ArrayList<String>();\r
+ urls.add("");\r
+ urls.addAll(serviceProxyUrls);\r
+ return urls;\r
+ }\r
+ \r
+ public List<String> getPazpar2Urls () {\r
+ List<String> urls = new ArrayList<String>();\r
+ urls.add("");\r
+ urls.addAll(pazpar2Urls);\r
+ return urls;\r
+ }\r
+ \r
+ public String getServiceType () {\r
+ return serviceType;\r
+ }\r
+ \r
+ public boolean isPazpar2Service () {\r
+ return serviceType.equals(SERVICE_TYPE_PZ2);\r
+ }\r
+ \r
+ public boolean isServiceProxyService() {\r
+ return serviceType.equals(SERVICE_TYPE_SP);\r
+ }\r
+ \r
+ public boolean serviceIsToBeDecided () {\r
+ return serviceType.equals(SERVICE_TYPE_TBD);\r
+ }\r
+ \r
+ public ServiceProxyClient getSpClient () {\r
+ return spClient;\r
+ } \r
+ \r
+ @Override\r
+ public boolean getAuthenticationRequired () {\r
+ return spClient.isAuthenticatingClient();\r
+ }\r
+\r
+ @Override\r
+ public String getCheckHistory () {\r
+ return ":pz2watch:stateForm:windowlocationhash";\r
+ }\r
+ \r
+ @Override\r
+ public String getWatchActiveclients () {\r
+ return ":pz2watch:activeclientsForm:activeclientsField";\r
+ }\r
+ \r
+ @Override\r
+ public String getWatchActiveclientsRecord () {\r
+ return ":pz2watch:activeclientsForm:activeclientsFieldRecord";\r
+ }\r
+\r
+ @Override\r
+ public void configure(ConfigurationReader reader)\r
+ throws ConfigurationException {\r
+ Configuration config = reader.getConfiguration(this);\r
+ if (config == null) {\r
+ serviceType = SERVICE_TYPE_TBD;\r
+ } else {\r
+ String service = config.get("TYPE");\r
+ if (service == null || service.length()==0) {\r
+ serviceType = SERVICE_TYPE_TBD;\r
+ } else if (serviceTypes.contains(service.toUpperCase())) { \r
+ setServiceType(service.toUpperCase());\r
+ } else {\r
+ logger.error("Unknown serviceType type in configuration [" + service + "], can be one of " + serviceTypes);\r
+ serviceType = SERVICE_TYPE_TBD;\r
+ }\r
+ serviceProxyUrls = config.getMultiProperty(SERVICE_PROXY_URL_LIST,",");\r
+ pazpar2Urls = config.getMultiProperty(PAZPAR2_URL_LIST, ",");\r
+ }\r
+ logger.info(reader.document());\r
+ logger.info("Service Type is configured to " + serviceType);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public Map<String, String> getDefaults() {\r
+ return new HashMap<String,String>();\r
+ }\r
+\r
+ @Override\r
+ public String getModuleName() {\r
+ return MODULE_NAME;\r
+ }\r
+\r
+ @Override\r
+ public List<String> documentConfiguration() {\r
+ return new ArrayList<String>();\r
+ }\r
+\r
+ @Override\r
+ public void setServiceTypePZ2() {\r
+ setServiceType(SERVICE_TYPE_PZ2); \r
+ }\r
+\r
+ @Override\r
+ public void setServiceTypeSP() {\r
+ setServiceType(SERVICE_TYPE_SP); \r
+ }\r
+\r
+ @Override\r
+ public void setServiceTypeTBD() {\r
+ setServiceType(SERVICE_TYPE_TBD); \r
+ }\r
+ \r
+ private void setServiceType(String type) {\r
+ if (!serviceType.equals(type) &&\r
+ !serviceType.equals(SERVICE_TYPE_TBD)) {\r
+ resetSearchAndRecordCommands();\r
+ pzresp.getSp().resetAuthAndBeyond(true);\r
+ }\r
+ serviceType = type;\r
+ if (serviceType.equals(SERVICE_TYPE_PZ2)) {\r
+ searchClient = pz2Client;\r
+ logger.info("Setting a Pazpar2 client to serve requests.");\r
+ } else if (serviceType.equals(SERVICE_TYPE_SP)) {\r
+ searchClient = spClient;\r
+ logger.info("Setting a Service Proxy client to serve requests.");\r
+ } else {\r
+ logger.info("Clearing search client. No client defined to serve requests at this point.");\r
+ searchClient = null;\r
+ }\r
+ }\r
+ \r
+ public SearchClient getSearchClient() {\r
+ return searchClient;\r
+ }\r
+ \r
+}\r
}\r
\r
public String getInitDocPath () {\r
- return Pz2Bean.get().getSpClient().getConfiguration().get("INIT_DOC_PATH");\r
+ return Pz2Service.get().getSpClient().getConfiguration().get("INIT_DOC_PATH");\r
}\r
\r
@Override\r
\r
@Override\r
public ClientCommandResponse postInit() throws UnsupportedEncodingException, IOException { \r
- String initDocPath = Pz2Bean.get().getSpClient().getInitDocPaths().get(0);\r
- logger.info("Paths: " + Pz2Bean.get().getSpClient().getInitDocPaths());\r
+ String initDocPath = Pz2Service.get().getSpClient().getInitDocPaths().get(0);\r
+ logger.info("Paths: " + Pz2Service.get().getSpClient().getInitDocPaths());\r
logger.info("Path: " + initDocPath); \r
- Pz2Bean.get().resetSearchAndRecordCommands();\r
- Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
- ClientCommandResponse response = Pz2Bean.get().getSpClient().postInitDoc(initDocPath + getInitFileName()); \r
+ Pz2Service.get().resetSearchAndRecordCommands();\r
+ Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
+ ClientCommandResponse response = Pz2Service.get().getSpClient().postInitDoc(initDocPath + getInitFileName()); \r
return response;\r
}\r
\r
@Override\r
public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { \r
- Pz2Bean.get().resetSearchAndRecordCommands();\r
- Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
- HttpResponseWrapper response = Pz2Bean.get().getSpClient().postInitDoc(initDoc,includeDebug); \r
+ Pz2Service.get().resetSearchAndRecordCommands();\r
+ Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
+ HttpResponseWrapper response = Pz2Service.get().getSpClient().postInitDoc(initDoc,includeDebug); \r
return response;\r
}\r
\r
public void submitInitDoc () throws IOException {\r
ClientCommandResponse response = (ClientCommandResponse) initDocUpload.submit();\r
ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(response); \r
- Pz2Bean.get().getPzresp().put("init", responseObject);\r
+ Pz2Service.get().getPzresp().put("init", responseObject);\r
}\r
\r
public void setIncludeInitDocDebug(boolean bool) {\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.Pz2Service;\r
import com.indexdata.mkjsf.pazpar2.SearchClient;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
}\r
\r
public ResponseDataObject run() { \r
- return run(Pz2Bean.get().getSearchClient(),\r
- Pz2Bean.get().getPzresp());\r
+ return run(Pz2Service.get().getSearchClient(),\r
+ Pz2Service.get().getPzresp());\r
}\r
\r
public ResponseDataObject runWith(String... parameters) {\r
} \r
\r
private void checkInState(Pazpar2Command command) {\r
- Pz2Bean.get().getStateMgr().checkIn(command);\r
+ Pz2Service.get().getStateMgr().checkIn(command);\r
}\r
\r
public String navigateTo (String target) {\r
\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommands;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
logger.info("Initializing Pazpar2Commands [" + Utils.objectId(this) + "]"); \r
}\r
\r
- // public void setService(Pz2Bean service) {\r
+ // public void setService(Pz2Service service) {\r
// this.pz2 = service;\r
// logger.info("Post construct Pazpar2Command: Service is " + pz2); \r
// }\r
\r
public InitCommand getInit() {\r
- return (InitCommand) (Pz2Bean.get().getStateMgr().getCommand(INIT)); \r
+ return (InitCommand) (Pz2Service.get().getStateMgr().getCommand(INIT)); \r
}\r
\r
public PingCommand getPing() {\r
- return (PingCommand) (Pz2Bean.get().getStateMgr().getCommand(PING));\r
+ return (PingCommand) (Pz2Service.get().getStateMgr().getCommand(PING));\r
}\r
\r
public SettingsCommand getSettings() {\r
- return (SettingsCommand) (Pz2Bean.get().getStateMgr().getCommand(SETTINGS));\r
+ return (SettingsCommand) (Pz2Service.get().getStateMgr().getCommand(SETTINGS));\r
}\r
\r
public SearchCommand getSearch() {\r
- return (SearchCommand) (Pz2Bean.get().getStateMgr().getCommand(SEARCH));\r
+ return (SearchCommand) (Pz2Service.get().getStateMgr().getCommand(SEARCH));\r
}\r
\r
public StatCommand getStat() {\r
- return (StatCommand) (Pz2Bean.get().getStateMgr().getCommand(STAT));\r
+ return (StatCommand) (Pz2Service.get().getStateMgr().getCommand(STAT));\r
}\r
\r
public ShowCommand getShow() {\r
- return (ShowCommand) (Pz2Bean.get().getStateMgr().getCommand(SHOW));\r
+ return (ShowCommand) (Pz2Service.get().getStateMgr().getCommand(SHOW));\r
}\r
\r
public RecordCommand getRecord() {\r
- return (RecordCommand) (Pz2Bean.get().getStateMgr().getCommand(RECORD));\r
+ return (RecordCommand) (Pz2Service.get().getStateMgr().getCommand(RECORD));\r
}\r
\r
public TermlistCommand getTermlist() {\r
- return (TermlistCommand) (Pz2Bean.get().getStateMgr().getCommand(TERMLIST));\r
+ return (TermlistCommand) (Pz2Service.get().getStateMgr().getCommand(TERMLIST));\r
}\r
\r
public BytargetCommand getBytarget() {\r
- return (BytargetCommand) (Pz2Bean.get().getStateMgr().getCommand(BYTARGET));\r
+ return (BytargetCommand) (Pz2Service.get().getStateMgr().getCommand(BYTARGET));\r
}\r
\r
public Pazpar2Command getCommand(String name) { \r
- return Pz2Bean.get().getStateMgr().getCommand(name);\r
+ return Pz2Service.get().getStateMgr().getCommand(name);\r
}\r
\r
public ServiceProxyCommands getSp() {\r
if (sp == null) {\r
- sp = new ServiceProxyCommands(Pz2Bean.get().getStateMgr());\r
+ sp = new ServiceProxyCommands(Pz2Service.get().getStateMgr());\r
}\r
return sp;\r
}\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.Pz2Service;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.RecordCommandSp;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
public ResponseDataObject run() {\r
ResponseDataObject responseObject = null;\r
if (hasParameterValue("id")) {\r
- HttpResponseWrapper commandResponse = Pz2Bean.get().getSearchClient().executeCommand(this);\r
+ HttpResponseWrapper commandResponse = Pz2Service.get().getSearchClient().executeCommand(this);\r
\r
if (commandResponse.getContentType().contains("xml")) {\r
responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);\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
+ Pz2Service.get().getPzresp().put(getCommandName(), responseObject);\r
} else {\r
logger.debug("No record id parameter on this command. Ignoring request but clearing any previous record result.");\r
- Pz2Bean.get().getPzresp().put(getCommandName(), new RecordResponse());\r
+ Pz2Service.get().getPzresp().put(getCommandName(), new RecordResponse());\r
}\r
return responseObject;\r
}\r
\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
\r
\r
public ResponseDataObject run() {\r
logger.info("Running " + getCommandName());\r
- Pz2Bean.get().getStateMgr().hasPendingStateChange("search",false);\r
- Pz2Bean.get().getPzresp().resetSearchAndBeyond();\r
- Pz2Bean.get().getPzreq().getRecord().removeParametersInState(); \r
- Pz2Bean.get().getPzreq().getShow().setParameterInState(new CommandParameter("start","=",0)); \r
- Pz2Bean.get().getSearchClient().setSearchCommand(this);\r
+ Pz2Service.get().getStateMgr().hasPendingStateChange("search",false);\r
+ Pz2Service.get().getPzresp().resetSearchAndBeyond();\r
+ Pz2Service.get().getPzreq().getRecord().removeParametersInState(); \r
+ Pz2Service.get().getPzreq().getShow().setParameterInState(new CommandParameter("start","=",0)); \r
+ Pz2Service.get().getSearchClient().setSearchCommand(this);\r
return super.run();\r
}\r
\r
import org.apache.log4j.Logger;\r
\r
import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;\r
-import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
}\r
\r
public SpResponseDataObject run() {\r
- Pz2Bean.get().resetSearchAndRecordCommands();\r
- Pz2Bean.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
- ClientCommandResponse response = (ClientCommandResponse) Pz2Bean.get().getSearchClient().executeCommand(this); \r
+ Pz2Service.get().resetSearchAndRecordCommands();\r
+ Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);\r
+ ClientCommandResponse response = (ClientCommandResponse) Pz2Service.get().getSearchClient().executeCommand(this); \r
String renamedResponse = renameResponseElement(response.getResponseString(), "auth"); \r
response.setResponseToParse(renamedResponse);\r
SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(response); \r
if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
- Pz2Bean.get().getPzresp().put(getCommandName(), responseObject);\r
+ Pz2Service.get().getPzresp().put(getCommandName(), responseObject);\r
}\r
if (responseObject.unsupportedCommand()) {\r
logger.error("auth command does not seem to be supported by this Service Proxy");\r
\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.mkjsf.pazpar2.Pz2Bean;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
\r
\r
@Override\r
public CategoriesResponse run () {\r
- if (Pz2Bean.get().getPzresp().getSp().getCategories().unsupportedCommand()) {\r
+ if (Pz2Service.get().getPzresp().getSp().getCategories().unsupportedCommand()) {\r
logger.info("Skipping seemingly unsupported categories command"); \r
return new CategoriesResponse();\r
} else {\r
- if (Pz2Bean.get().isServiceProxyService()) {\r
+ if (Pz2Service.get().isServiceProxyService()) {\r
try {\r
CategoriesResponse response = (CategoriesResponse) super.run();\r
if (response.unsupportedCommand()) {\r
* @See The state field in pz2watch.xhtml<br/> \r
* The state listeners windowlocationhashListener() and StateListener()\r
* in listeners.js<br/>\r
- * The method {@link com.indexdata.mkjsf.pazpar2.Pz2Bean#handleQueryStateChanges}<br/>\r
+ * The method {@link com.indexdata.mkjsf.pazpar2.Pz2Service#handleQueryStateChanges}<br/>\r
* The class {@link com.indexdata.mkjsf.pazpar2.state.Pazpar2State}<br/> \r
* ... for a complete picture of browser history handling.\r
* \r