@PostConstruct public void postConstruct() throws MissingConfigurationContextException { logger.info("Pz2Service PostConstruct of " + this); stateMgr = new StateManager(); pzreq = new Pazpar2Commands(); pzresp = new Responses(); errors = new ErrorCentral(); pzresp.setErrorHelper(errors.getHelper()); logger.debug("Pz2Service PostConstruct: Configurator is " + configurator); logger.debug(Utils.objectId(this) + " will instantiate a Pz2Client next."); pz2Client = new Pz2Client(); spClient = new ServiceProxyClient(); stateMgr.addStateListener(this); try { configureClient(pz2Client, configurator); configureClient(spClient, configurator); this.configure(configurator); } catch (MissingConfigurationContextException mcc) { logger.info("No configuration context available at this point"); logger.debug("Configuration invoked from a Servlet filter before application start?"); throw mcc; } catch (ConfigurationException e) { logger.warn("There was a problem configuring the Pz2Service and/or clients (\"pz2\")"); e.printStackTrace(); } }
/** * Configures the selected search client using the selected configuration reader. * * <p>The configuration reader is select deploy-time - by configuration in the application's * beans.xml. * * @param client search client to use * @param configReader the selected configuration mechanism * @throws MissingConfigurationContextException if this object is injected before there is a Faces * context for example in a Servlet filter. */ public void configureClient(SearchClient client, ConfigurationReader configReader) throws MissingConfigurationContextException { logger.debug(Utils.objectId(this) + " will configure search client for the session"); try { client.configure(configReader); } catch (MissingConfigurationContextException mcce) { logger.info("No Faces context is available to the configurator at this time of invocation"); throw mcce; } catch (ConfigurationException e) { logger.debug("Pz2Service adding configuration error"); errors.addConfigurationError( new ConfigurationError("Search Client", "Configuration", e.getMessage())); } logger.info(configReader.document()); pzresp.getSp().resetAuthAndBeyond(true); }
/** * Updates display data objects by simultaneously issuing the following Pazpar2 commands: 'show', * 'stat', 'termlist' and 'bytarget'. * * <p>If there are outstanding changes to the search command, a search will be issued before the * updates are performed. Outstanding changes could come from the UI changing a search parameter * and not executing search before starting the update cycle - OR - it could come from the user * clicking the browsers back/forward buttons. * * <p>This method is invoked from the composite 'pz2watch', which uses Ajax to keep invoking this * method until it returns '0' (for zero active clients). * * <p>UI components that display data from show, stat, termlist or bytarget, should be re-rendered * after each update. Example of invocation in UI: * * <pre> * <pz2utils:pz2watch id="pz2watch" * renderWhileActiveclients="myshowui mystatui mytermsui" /< * * <h:form> * <h:inputText id="query" value="#{pzreq.search.query}" size="50"/> * <h:commandButton id="button" value="Search"> * <f:ajax execute="query" render="${pz2.watchActiveclients}"/> * </h:commandButton> * </h:form> * </pre> * * The expression pz2.watchActiveClients will invoke the method repeatedly, and the UI sections * myshowui, mystatui, and mytermsui will be rendered on each poll. * * @return a count of the remaining active clients from the most recent search. */ public String update() { logger.debug("Updating show,stat,termlist,bytarget from pazpar2"); if (errors.hasConfigurationErrors()) { logger.error("Ignoring show,stat,termlist,bytarget commands due to configuration errors."); return ""; } else if (pzresp.getSearch().hasApplicationError()) { logger.error( "Ignoring show,stat,termlist,bytarget commands due to problem with most recent search."); return ""; } else if (!hasQuery()) { logger.debug( "Ignoring show,stat,termlist,bytarget commands because there is not yet a query."); return ""; } else { return update("show,stat,termlist,bytarget"); } }
/** * Simultaneously refreshes the data objects listed in 'commands' from pazpar2, potentially * running a search or a record command first if any of these two commands have outstanding * parameter changes. * * @param commands, a comma-separated list of Pazpar2 commands to execute * @return Number of activeclients at the time of the 'show' command, or 'new' if search was just * initiated. */ public String update(String commands) { logger.debug("Request to update: " + commands); try { if (commands.equals("search")) { pzreq.getSearch().run(); pzresp.getSearch().setIsNew(false); return "new"; } else if (commands.equals("record")) { 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."); pzresp.getSearch().setIsNew(false); return "new"; } else { handleQueryStateChanges(commands); if (pzresp.getSearch().hasApplicationError()) { logger.error( "The command(s) " + commands + " cancelled because the latest search command had an error."); return "0"; } else if (errors.hasConfigurationErrors()) { logger.error("The command(s) " + commands + " cancelled due to configuration errors."); return "0"; } else { logger.debug("Processing request for " + commands); List<CommandThread> threadList = new ArrayList<CommandThread>(); StringTokenizer tokens = new StringTokenizer(commands, ","); while (tokens.hasMoreElements()) { threadList.add( new CommandThread( pzreq.getCommand(tokens.nextToken()), searchClient, Pz2Service.get().getPzresp())); } for (CommandThread thread : threadList) { thread.start(); } for (CommandThread thread : threadList) { try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } return pzresp.getActiveClients(); } } } catch (ClassCastException cce) { cce.printStackTrace(); return ""; } catch (NullPointerException npe) { npe.printStackTrace(); return ""; } catch (Exception e) { e.printStackTrace(); return ""; } }