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.errors.MissingConfigurationContextException;\r
import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Commands;\r
import com.indexdata.mkjsf.pazpar2.data.RecordResponse;\r
import com.indexdata.mkjsf.pazpar2.data.Responses;\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
+ private static Logger logger = Logger.getLogger(Pz2Service.class); \r
protected Pz2Client pz2Client = null;\r
protected ServiceProxyClient spClient = null;\r
protected SearchClient searchClient = null; \r
FacesContext context = FacesContext.getCurrentInstance();\r
return (Pz2Service) context.getApplication().evaluateExpressionGet(context, "#{pz2}", Object.class); \r
}\r
- \r
+ \r
@PostConstruct\r
- public void postConstruct() {\r
+ public void postConstruct() throws MissingConfigurationContextException { \r
logger.info("Pz2Service PostConstruct of " + this);\r
stateMgr = new StateManager();\r
pzreq = new Pazpar2Commands();\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
+ 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
+ stateMgr.addStateListener(this);\r
try {\r
+ configureClient(pz2Client,configurator); \r
+ configureClient(spClient,configurator);\r
this.configure(configurator);\r
+ } catch (MissingConfigurationContextException mcc) {\r
+ logger.info("No configuration context available at this point");\r
+ logger.debug("Configuration invoked from a Servlet filter before application start?");\r
+ throw mcc;\r
} catch (ConfigurationException e) {\r
- logger.error("There was a problem configuring the Pz2Service (\"pz2\")");\r
+ logger.warn("There was a problem configuring the Pz2Service and/or clients (\"pz2\")");\r
e.printStackTrace();\r
- } \r
- stateMgr.addStateListener(this); \r
+ } \r
}\r
\r
@Qualifier\r
return stateMgr;\r
}\r
\r
- public void configureClient(SearchClient client, ConfigurationReader configReader) {\r
+ public void configureClient(SearchClient client, ConfigurationReader configReader) throws MissingConfigurationContextException {\r
logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
try {\r
- client.configure(configReader); \r
+ client.configure(configReader);\r
+ } catch (MissingConfigurationContextException mcce) {\r
+ logger.info("No Faces context is available to the configurator at this time of invocation");\r
+ throw mcce;\r
} catch (ConfigurationException e) {\r
logger.debug("Pz2Service adding configuration error");\r
errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage())); \r
- } \r
+ }\r
logger.info(configReader.document());\r
pzresp.getSp().resetAuthAndBeyond(true); \r
}\r
}\r
\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
+ @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
\r
/**\r
* Will retrieve -- or alternatively remove -- the record with the given \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
- /*\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
- \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
+ \r
public void setServiceProxyUrl(String url) {\r
searchClient = spClient;\r
setServiceType(SERVICE_TYPE_SP);\r