com.indexdata.mkjsf.pazpar2
Class Pz2Service

java.lang.Object
  extended by com.indexdata.mkjsf.pazpar2.Pz2Service
All Implemented Interfaces:
Configurable, StateListener, Serializable

@Named(value="pz2")
@SessionScoped
public class Pz2Service
extends Object
implements StateListener, Configurable, Serializable

Pz2Service is the main controller of the search logic, used for selecting the service type (which can be done by configuration and/or run-time), selecting which search client to use, and performing high-level control of request cycles and state management.

Command and response beans are also obtained through Pz2Service - although it is transparent to the UI that they are retrieved through this object.

Pz2Service is exposed to the UI as pz2. However, if the service is pre-configured, the Faces pages might never need to reference pz2 explicitly. Indirectly they will, though, if the polling mechanism in the tag <pz2utils:pz2watch> is used.

See Also:
Serialized Form

Nested Class Summary
static interface Pz2Service.Preferred
           
 
Field Summary
protected  ErrorHelper errorHelper
           
protected  ResultsPager pager
           
static String PAZPAR2_URL_LIST
           
protected  Pz2Client pz2Client
           
protected  SearchClient searchClient
           
static String SERVICE_PROXY_URL_LIST
           
protected  ServiceProxyClient spClient
           
 
Constructor Summary
Pz2Service()
           
 
Method Summary
 void configure(ConfigurationReader reader)
          Configures the Configurable using the configuration obtained by the provided configuration reader
 void configureClient(SearchClient client, ConfigurationReader configReader)
          Configures the selected search client using the selected configuration reader.
 List<String> documentConfiguration()
          The components documentation of how it was configured.
static Pz2Service get()
           
 boolean getAuthenticationRequired()
           
 String getCheckHistory()
           
 String getCurrentStateKey()
          Returns the current hash key, used for internal session state tracking and potentially for browser history entries A UI author would not normally be concerned with retrieving this.
 Map<String,String> getDefaults()
          Returns the default parameters that the configurable has defined for itself Should be invoked by the configuration reader before it possibly overrides some parameters obtained from the external configuration source
 ErrorCentral getErrors()
           
 String getModuleName()
          Returns the name of the module, can be used by a configuration reader that distinguishes between sets of configuration properties by component name, a name space of sorts.
 ResultsPager getPager()
          Returns a component for drawing a pager to navigate by.
 String getPazpar2Url()
          Returns the Pazpar2 URL currently defined for servicing requests
 List<String> getPazpar2Urls()
           
 Pazpar2Commands getPzreq()
           
 Responses getPzresp()
           
 SearchClient getSearchClient()
           
 String getServiceId()
           
 String getServiceProxyUrl()
          Returns the Service Proxy URL currently defined for servicing requests
 List<String> getServiceProxyUrls()
           
 String getServiceType()
           
 String getServiceUrl()
          Gets the currently selected URL used for executing requests.
 boolean getServiceUrlIsDefined()
           
 ServiceProxyClient getSpClient()
           
 StateManager getStateMgr()
           
 String getWatchActiveclients()
           
 String getWatchActiveclientsRecord()
           
protected  void handleQueryStateChanges(String commands)
          This methods main purpose is to support browser history.
protected  boolean hasQuery()
           
 boolean hasRecord(String recId)
          Resolves whether the back-end has a record with the given recid in memory
 boolean isPazpar2Service()
           
 boolean isServiceProxyService()
           
 void postConstruct()
           
 void resetSearchAndRecordCommands()
           
 boolean serviceIsToBeDecided()
           
 void setCurrentStateKey(String key)
          Sets the current state key, i.e.
 ResultsPager setPager(int pageRange)
          Initiates a pager object, a component holding the data to draw a sequence of page numbers to navigate by and mechanisms to navigate with
 void setPazpar2Url(String url)
          Sets the URL of the Pazpar2 to use for requests
 void setServiceId()
           
 void setServiceProxyUrl(String url)
          Sets the URL of the Service Proxy to use for requests
 void setServiceTypePZ2()
           
 void setServiceTypeSP()
           
 void setServiceTypeTBD()
           
 void setServiceUrl(String url)
          Sets the URL to be used by the currently selected search client when running requests.
 void stateUpdated(String commandName)
          Used by the state manager to notify Pz2Service about state changes
 String toggleRecord(String recId)
          Will retrieve -- or alternatively remove -- the record with the given recid from memory.
 String update()
          Updates display data objects by simultaneously issuing the following Pazpar2 commands: 'show', 'stat', 'termlist' and 'bytarget'.
 String update(String commands)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE_PROXY_URL_LIST

public static final String SERVICE_PROXY_URL_LIST
See Also:
Constant Field Values

PAZPAR2_URL_LIST

public static final String PAZPAR2_URL_LIST
See Also:
Constant Field Values

pz2Client

protected Pz2Client pz2Client

spClient

protected ServiceProxyClient spClient

searchClient

protected SearchClient searchClient

pager

protected ResultsPager pager

errorHelper

protected ErrorHelper errorHelper
Constructor Detail

Pz2Service

public Pz2Service()
Method Detail

get

public static Pz2Service get()

postConstruct

@PostConstruct
public void postConstruct()
                   throws MissingConfigurationContextException
Throws:
MissingConfigurationContextException

getPzresp

@Produces
@SessionScoped
@Named(value="pzresp")
public Responses getPzresp()

getPzreq

@Produces
@SessionScoped
@Named(value="pzreq")
public Pazpar2Commands getPzreq()

getErrors

@Produces
@SessionScoped
@Named(value="errors")
public ErrorCentral getErrors()

getStateMgr

@Produces
@SessionScoped
@Named(value="stateMgr")
public StateManager getStateMgr()

configureClient

public void configureClient(SearchClient client,
                            ConfigurationReader configReader)
                     throws MissingConfigurationContextException
Configures the selected search client using the selected configuration reader. The configuration reader is select deploy-time - by configuration in the application's beans.xml.

Parameters:
client - search client to use
configReader - the selected configuration mechanism
Throws:
MissingConfigurationContextException - if this object is injected before there is a Faces context for example in a Servlet filter.

resetSearchAndRecordCommands

public void resetSearchAndRecordCommands()

update

public String update()
Updates display data objects by simultaneously issuing the following Pazpar2 commands: 'show', 'stat', 'termlist' and 'bytarget'.

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.

This method is invoked from the composite 'pz2watch', which uses Ajax to keep invoking this method until it returns '0' (for zero active clients).

UI components that display data from show, stat, termlist or bytarget, should be re-rendered after each update.

Example of invocation in UI:
    <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>
 
The expression pz2.watchActiveClients will invoke the method repeatedly, and the UI sections myshowui, mystatui, and mytermsui will be rendered on each poll.

Returns:
a count of the remaining active clients from the most recent search.

update

public String update(String commands)
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.

Parameters:
commands, - a comma-separated list of Pazpar2 commands to execute
Returns:
Number of activeclients at the time of the 'show' command, or 'new' if search was just initiated.

handleQueryStateChanges

protected void handleQueryStateChanges(String commands)
This methods main purpose is to support browser history. When the browsers back or forward buttons are pressed, a re-search /might/ be required - namely if the query changes. So, as the UI requests updates of the page (show,facets, etc) this method checks if a search must be executed before those updates are performed. It will consequently also run a search if the UI updates a search parameter without actually explicitly executing the search before setting of the polling.

Parameters:
commands -
See Also:
com.indexdata.mkjsf.pazpar2.state.StateManager#setCurrentStateKey}

stateUpdated

public void stateUpdated(String commandName)
Used by the state manager to notify Pz2Service about state changes

Specified by:
stateUpdated in interface StateListener

toggleRecord

public String toggleRecord(String recId)
Will retrieve -- or alternatively remove -- the record with the given recid from memory. A pazpar2 'record' command will then be issued. The part of the UI showing record data should thus be re-rendered.

Parameters:
recid -
Returns:

hasRecord

public boolean hasRecord(String recId)
Resolves whether the back-end has a record with the given recid in memory

Returns:
true if the bean currently holds the record with recid

getCurrentStateKey

public String getCurrentStateKey()
Returns the current hash key, used for internal session state tracking and potentially for browser history entries A UI author would not normally be concerned with retrieving this. It's used by the framework internally

Returns:
string that can be used for browsers window.location.hash

setCurrentStateKey

public void setCurrentStateKey(String key)
Sets the current state key, i.e. when user clicks back or forward in browser history. Would normally be automatically handled by the frameworks components.

Parameters:
key - corresponding to browsers hash string

hasQuery

protected boolean hasQuery()

getPager

public ResultsPager getPager()
Returns a component for drawing a pager to navigate by.

Returns:
ResultsPager pager component

setPager

public ResultsPager setPager(int pageRange)
Initiates a pager object, a component holding the data to draw a sequence of page numbers to navigate by and mechanisms to navigate with

Parameters:
pageRange - number of pages to display in the pager
Returns:
ResultsPager the initiated pager component

setServiceProxyUrl

public void setServiceProxyUrl(String url)
Sets the URL of the Service Proxy to use for requests

Parameters:
url -

getServiceProxyUrl

public String getServiceProxyUrl()
Returns the Service Proxy URL currently defined for servicing requests


setPazpar2Url

public void setPazpar2Url(String url)
Sets the URL of the Pazpar2 to use for requests

Parameters:
url -

getPazpar2Url

public String getPazpar2Url()
Returns the Pazpar2 URL currently defined for servicing requests


setServiceUrl

public void setServiceUrl(String url)
Sets the URL to be used by the currently selected search client when running requests.

Parameters:
url -

getServiceUrl

public String getServiceUrl()
Gets the currently selected URL used for executing requests.

Returns:

setServiceId

public void setServiceId()

getServiceId

public String getServiceId()

getServiceUrlIsDefined

public boolean getServiceUrlIsDefined()

getServiceProxyUrls

public List<String> getServiceProxyUrls()

getPazpar2Urls

public List<String> getPazpar2Urls()

getServiceType

public String getServiceType()

isPazpar2Service

public boolean isPazpar2Service()

isServiceProxyService

public boolean isServiceProxyService()

serviceIsToBeDecided

public boolean serviceIsToBeDecided()

getSpClient

public ServiceProxyClient getSpClient()

getAuthenticationRequired

public boolean getAuthenticationRequired()

getCheckHistory

public String getCheckHistory()

getWatchActiveclients

public String getWatchActiveclients()

getWatchActiveclientsRecord

public String getWatchActiveclientsRecord()

configure

public void configure(ConfigurationReader reader)
               throws ConfigurationException
Description copied from interface: Configurable
Configures the Configurable using the configuration obtained by the provided configuration reader

Specified by:
configure in interface Configurable
Parameters:
reader - used for reading the configuration
Throws:
ConfigurationException

getDefaults

public Map<String,String> getDefaults()
Description copied from interface: Configurable
Returns the default parameters that the configurable has defined for itself Should be invoked by the configuration reader before it possibly overrides some parameters obtained from the external configuration source

Specified by:
getDefaults in interface Configurable
Returns:

getModuleName

public String getModuleName()
Description copied from interface: Configurable
Returns the name of the module, can be used by a configuration reader that distinguishes between sets of configuration properties by component name, a name space of sorts.

Specified by:
getModuleName in interface Configurable
Returns:
name of the part that is to be configured

documentConfiguration

public List<String> documentConfiguration()
Description copied from interface: Configurable
The components documentation of how it was configured.

Specified by:
documentConfiguration in interface Configurable
Returns:
a list of Strings describing configuration details

setServiceTypePZ2

public void setServiceTypePZ2()

setServiceTypeSP

public void setServiceTypeSP()

setServiceTypeTBD

public void setServiceTypeTBD()

getSearchClient

public SearchClient getSearchClient()


Copyright © 2013. All Rights Reserved.