</h:dataTable>\r
<h:panelGrid style="${pz2.hasCommandErrors() ? 'display: block;' : 'display: none;'}">\r
<h:column>\r
- <h:outputText id="messages" value="#{pz2.commandError.message}" style="color: red;"/>\r
+ <h:outputText id="messages" value="#{data.commandError.message}" style="color: red;"/>\r
</h:column>\r
- <h:dataTable value="#{pz2.commandError.suggestions}" var="suggestion" cellspacing="0" cellpadding="0"> \r
+ <h:dataTable value="#{data.commandError.suggestions}" var="suggestion" cellspacing="0" cellpadding="0"> \r
<h:column>\r
#{suggestion} \r
</h:column> \r
\r
<composite:implementation>\r
\r
- <h:panelGrid columns="1" width="100%" rendered="#{pz2.hasRecords()}"><h:panelGroup>\r
+ <h:panelGrid columns="1" width="100%" rendered="#{data.hasRecords()}"><h:panelGroup>\r
<h:outputText id="instantiatePager" value="#{pz2.setPager(cc.attrs.visiblePageRange)}" style="display: none;" />\r
\r
<h:commandLink value="#{cc.attrs.prevLabel}" \r
import java.util.ArrayList;\r
import java.util.List;\r
\r
-import com.indexdata.pz2utils4jsf.controls.PageLink;\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session;\r
import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Responses;\r
\r
public class ResultsPager implements Serializable {\r
\r
private static final long serialVersionUID = 8854795222615583071L;\r
- private Pz2Session pz2session = null;\r
+ private Pazpar2Responses data = null;\r
private int pageRangeLength = 13;\r
private Pazpar2Commands req;\r
\r
- public ResultsPager(Pz2Session session) {\r
- this.pz2session = session; \r
+ public ResultsPager(Pazpar2Responses data) {\r
+ this.data = data; \r
}\r
\r
- public ResultsPager(Pz2Session session, int pageRange, Pazpar2Commands req) {\r
- this.pz2session = session;\r
+ public ResultsPager(Pazpar2Responses data, int pageRange, Pazpar2Commands req) {\r
+ this.data = data;\r
this.pageRangeLength = pageRange;\r
this.req = req;\r
}\r
\r
private boolean hasHits () {\r
- return (getShow().getMerged()>0);\r
+ return (data.getShow().getMerged()>0);\r
}\r
\r
public int getCurrentPageNum () {\r
- if (hasHits() && getShow().getNum()>0) { \r
- return (getShow().getStart()/getShow().getNum())+1;\r
+ if (hasHits() && data.getShow().getNum()>0) { \r
+ return (data.getShow().getStart()/data.getShow().getNum())+1;\r
} else {\r
return 0;\r
}\r
}\r
\r
public int getPageSize() {\r
- return getShow().getNum();\r
+ return data.getShow().getNum();\r
}\r
\r
public int getFirstDisplayedPageNum () {\r
\r
public int getLastPageNum () {\r
if (hasHits()) {\r
- return (int) Math.ceil(new Double(getShow().getMerged())/new Double(getShow().getNum()));\r
+ return (int) Math.ceil(new Double(data.getShow().getMerged())/new Double(data.getShow().getNum()));\r
} else {\r
return 0;\r
}\r
}\r
\r
public int getCurrentPage() {\r
- return (getShow().getStart()/getPageSize()+1);\r
+ return (data.getShow().getStart()/getPageSize()+1);\r
}\r
\r
public void goToPage(int page) { \r
public boolean hasPageAfterLastDisplayed() {\r
return getLastDisplayedPageNum() < getLastPageNum();\r
}\r
-\r
- \r
- private ShowResponse getShow() {\r
- return pz2session.getShow();\r
- }\r
\r
}\r
+++ /dev/null
-package com.indexdata.pz2utils4jsf.pazpar2;\r
-\r
-import java.lang.annotation.ElementType;\r
-import java.lang.annotation.Retention;\r
-import java.lang.annotation.RetentionPolicy;\r
-import java.lang.annotation.Target;\r
-\r
-import javax.inject.Qualifier;\r
-\r
-@Qualifier\r
-@Retention(RetentionPolicy.RUNTIME)\r
-@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})\r
-public @interface ForStraightPz2 {\r
-\r
-}\r
package com.indexdata.pz2utils4jsf.pazpar2;\r
\r
import java.io.Serializable;\r
+import java.util.ArrayList;\r
import java.util.List;\r
+import java.util.StringTokenizer;\r
\r
import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
\r
import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationError;\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseParser;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Responses;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.StatResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse;\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateListener;\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
@Named("pz2") @SessionScoped @Alternative\r
-public class Pz2Bean implements Pz2Interface, Serializable {\r
+public class Pz2Bean implements Pz2Interface, StateListener, Serializable {\r
\r
private static final long serialVersionUID = 3440277287081557861L;\r
private static Logger logger = Logger.getLogger(Pz2Bean.class);\r
\r
- @Inject ConfigurationReader configurator;\r
+ protected SearchClient searchClient = null;\r
\r
- @Inject @ForStraightPz2 Pz2Session pz2; \r
+ @Inject ConfigurationReader configurator;\r
+ @Inject StateManager stateMgr;\r
+ @Inject Pazpar2Commands req;\r
+ @Inject Pazpar2Responses data;\r
\r
- protected SearchClient searchClient; \r
- \r
+ protected ResultsPager pager = null; \r
+\r
+ protected List<ErrorInterface> configurationErrors = null;\r
+ protected ErrorHelper errorHelper = null;\r
+ \r
public Pz2Bean () {\r
- logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]");\r
+ logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]"); \r
}\r
\r
@PostConstruct\r
- public void instantiatePz2SessionObject() { \r
+ public void postConstruct() { \r
logger.debug("in start of Pz2Bean post-construct configurator is " + configurator);\r
logger.debug(Utils.objectId(this) + " will instantiate a Pz2Client next.");\r
searchClient = new Pz2Client();\r
logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
- + Utils.objectId(configurator) + "] on session [" \r
- + Utils.objectId(pz2) + "]" ); \r
- pz2.configureClient(searchClient,configurator); \r
+ + Utils.objectId(configurator) + "]" ); \r
+ configureClient(searchClient,configurator);\r
+ stateMgr.addStateListener(this);\r
} \r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch(java.lang.String)\r
- */\r
- public void doSearch(String query) { \r
- pz2.doSearch(query);\r
+ public void configureClient(SearchClient searchClient, ConfigurationReader configReader) {\r
+ configurationErrors = new ArrayList<ErrorInterface>();\r
+ errorHelper = new ErrorHelper(configReader); \r
+ logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
+ try {\r
+ searchClient.configure(configReader); \r
+ // At the time of writing this search client is injected using Weld. \r
+ // However, the client is used for asynchronously sending off requests\r
+ // to the server AND propagation of context to threads is currently \r
+ // not supported. Trying to do so throws a WELD-001303 error. \r
+ // To avoid that, a context free client is cloned from the context \r
+ // dependent one. \r
+ // If propagation to threads gets supported, the cloning can go.\r
+ //\r
+ // Commented as I'm trying with regular instantiation instead\r
+ // this.searchClient = searchClient.cloneMe(); \r
+ } catch (ConfigurationException e) {\r
+ configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); \r
+ } \r
+ logger.info(configReader.document());\r
+ data.reset(); \r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch()\r
- */\r
- public void doSearch() {\r
- logger.info(Utils.objectId(this) + " doing search for "+pz2.getCommandReadOnly("search").getParameterValue("query"));\r
- pz2.doSearch();\r
+ \r
+ public void doSearch(String query) {\r
+ req.getSearch().setParameter(new CommandParameter("query","=",query)); \r
+ doSearch();\r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#update()\r
- */\r
- public String update() {\r
- return pz2.update();\r
+ public void doSearch() { \r
+ stateMgr.hasPendingStateChange("search",false);\r
+ data.reset();\r
+ req.getRecord().removeParameters();\r
+ req.getShow().setParameter(new CommandParameter("start","=",0)); \r
+ logger.debug(Utils.objectId(this) + " is searching using "+req.getCommandReadOnly("search").getUrlEncodedParameterValue("query"));\r
+ doCommand("search"); \r
}\r
-\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#update(java.lang.String)\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(String commands) {\r
- return pz2.update(commands);\r
+ public String update () {\r
+ logger.debug("Updating show,stat,termlist,bytarget from pazpar2");\r
+ return update("show,stat,termlist,bytarget");\r
}\r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#toggleRecord(java.lang.String)\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
*/\r
- public String toggleRecord(String recid) {\r
- return pz2.toggleRecord(recid);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getShow()\r
- */\r
- public ShowResponse getShow() {\r
- return pz2.getShow();\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getStat()\r
- */\r
- public StatResponse getStat() {\r
- return pz2.getStat();\r
- }\r
+ public String update (String commands) {\r
+ if (! hasConfigurationErrors()) {\r
+ if (hasQuery()) {\r
+ handleQueryStateChanges(commands);\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(req.getCommandReadOnly(tokens.nextToken()),searchClient)); \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
+ for (CommandThread thread : threadList) {\r
+ String commandName = thread.getCommand().getName();\r
+ String response = thread.getResponse();\r
+ logger.debug("Response was: " + response);\r
+ Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(response);\r
+ data.put(commandName, responseObject); \r
+ }\r
+ if (commands.equals("record")) {\r
+ logger.debug("Record: Active clients: "+data.getRecord().getActiveClients());\r
+ return data.getRecord().getActiveClients();\r
+ } else {\r
+ return data.getActiveClients();\r
+ } \r
+ } else {\r
+ logger.debug("Skipped requests for " + commands + " as there's not yet a query."); \r
+ data.reset();\r
+ return "0";\r
+ }\r
+ } else {\r
+ logger.error("Did not attempt to execute query since there are configuration errors.");\r
+ return "0";\r
+ }\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#hasRecord(java.lang.String)\r
- */\r
- public boolean hasRecord(String recId) { \r
- return pz2.hasRecord(recId);\r
}\r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getRecord()\r
- */\r
- public RecordResponse getRecord() {\r
- return pz2.getRecord();\r
+ \r
+ public String toggleRecord (String recId) {\r
+ if (hasRecord(recId)) {\r
+ req.getRecord().removeParameters(); \r
+ data.put("record", new RecordResponse());\r
+ return "";\r
+ } else {\r
+ req.getRecord().setRecordId(recId);\r
+ return doCommand("record");\r
+ }\r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getTermLists()\r
- */\r
- public TermListsResponse getTermLists() {\r
- return pz2.getTermLists();\r
+ @Override\r
+ public boolean hasRecord (String recId) {\r
+ return req.getCommandReadOnly("record").hasParameters() && data.getRecord().getRecId().equals(recId);\r
}\r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getFacetTerms(java.lang.String, int)\r
- */\r
- public List<TermResponse> getFacetTerms(String facet, int count) {\r
- return pz2.getFacetTerms(facet, count);\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
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getFacetTerms(java.lang.String)\r
- */\r
- public List<TermResponse> getFacetTerms(String facet) { \r
- return pz2.getFacetTerms(facet);\r
- } \r
- \r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getByTarget()\r
- */\r
- public ByTarget getByTarget() { \r
- return pz2.getByTarget();\r
+ public boolean hasConfigurationErrors () {\r
+ return (configurationErrors.size()>0); \r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#hasRecords()\r
- */\r
- public boolean hasRecords() {\r
- return pz2.hasRecords();\r
+ public boolean hasCommandErrors () {\r
+ return data.hasApplicationError();\r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setPager(int)\r
+ /**\r
+ * Returns true if application error found in any response data objects \r
*/\r
- public ResultsPager setPager(int pageRange) {\r
- return pz2.setPager(pageRange);\r
+ public boolean hasErrors () {\r
+ return hasConfigurationErrors() || hasCommandErrors();\r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getPager()\r
- */\r
- public ResultsPager getPager() {\r
- return pz2.getPager();\r
+ public List<ErrorInterface> getConfigurationErrors() { \r
+ return configurationErrors;\r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getCurrentStateKey()\r
- */\r
- public String getCurrentStateKey() {\r
- return pz2.getCurrentStateKey();\r
+ \r
+ protected boolean hasQuery() { \r
+ return req.getSearch().getParameter("query") != null && req.getSearch().getParameter("query").getValueWithExpressions().length()>0;\r
}\r
\r
- /* (non-Javadoc)\r
- * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setCurrentStateKey(java.lang.String)\r
- */\r
- public void setCurrentStateKey(String key) {\r
- pz2.setCurrentStateKey(key); \r
+ \r
+ public ResultsPager getPager () {\r
+ if (pager == null) {\r
+ pager = new ResultsPager(data); \r
+ } \r
+ return pager; \r
}\r
\r
- public boolean hasErrors() {\r
- return pz2.hasErrors();\r
+ public ResultsPager setPager (int pageRange) {\r
+ pager = new ResultsPager(data,pageRange,req);\r
+ return pager;\r
}\r
- \r
- public ErrorInterface getCommandError() {\r
- return pz2.getCommandError();\r
+ \r
+ protected ErrorHelper getTroubleshooter() {\r
+ return errorHelper;\r
}\r
\r
- public List<ErrorInterface> getConfigurationErrors () {\r
- return pz2.getConfigurationErrors();\r
+ protected void handleQueryStateChanges (String commands) {\r
+ if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
+ logger.debug("Found pending search change. Doing search before updating " + commands); \r
+ doSearch();\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
+ if (req.getCommandReadOnly("record").hasParameters()) {\r
+ update("record");\r
+ } else {\r
+ req.getRecord().removeParameters(); \r
+ data.put("record", new RecordResponse());\r
+ }\r
+ }\r
}\r
-\r
- @Override\r
- public boolean hasCommandErrors() {\r
- return pz2.hasCommandErrors();\r
+ \r
+ protected String doCommand(String commandName) { \r
+ logger.debug(req.getCommandReadOnly(commandName).getEncodedQueryString() + ": Results for "+ req.getCommandReadOnly("search").getEncodedQueryString());\r
+ return update(commandName);\r
}\r
-\r
+ \r
@Override\r
- public boolean hasConfigurationErrors() {\r
- return pz2.hasConfigurationErrors();\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
}\r
import java.util.List;\r
import java.util.Map;\r
\r
-import javax.enterprise.context.SessionScoped;\r
-import javax.inject.Named;\r
-\r
import org.apache.log4j.Logger;\r
\r
import com.indexdata.masterkey.config.MissingMandatoryParameterException;\r
import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
-@Named @SessionScoped \r
public class Pz2Client implements SearchClient {\r
\r
private static final long serialVersionUID = 5414266730169982028L;\r
\r
import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.StatResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse;\r
\r
public interface Pz2Interface extends Serializable {\r
\r
* @return\r
*/\r
public String toggleRecord(String recid);\r
- \r
- /**\r
- * Returns the 'show' data as retrieved from pazpar2 by the most \r
- * recent update request\r
- * \r
- * @return pazpar2 'show' response object\r
- */\r
- public ShowResponse getShow();\r
- \r
- /**\r
- * Returns the 'stat' data as retrieved from pazpar2 by the most \r
- * recent update request\r
- * \r
- * @return pazpar2 'stat' response object\r
- */\r
- public StatResponse getStat();\r
- \r
+ \r
/**\r
* Resolves whether the backend has a record with the given recid in memory \r
* \r
* @return true if the bean currently holds the record with recid\r
*/ \r
public boolean hasRecord (String recId);\r
- \r
- /**\r
- * Resolves whether the back-end has any records in memory (in 'show') for \r
- * display in UI\r
- * \r
- * @return true if there are records to display\r
- */\r
- public boolean hasRecords ();\r
- \r
- /**\r
- * Returns a pazpar2 record as retrieved by the most recent 'record'\r
- * request \r
- * @return record data object\r
- */\r
- public RecordResponse getRecord();\r
- \r
- /**\r
- * Returns a set of term lists (targets and facets) as retrieved by the \r
- * most recent 'termlist' command \r
- * @return set of termlists\r
- */\r
- public TermListsResponse getTermLists ();\r
- \r
- /**\r
- * Returns up to 'count' terms from the facet given by the 'facet' parameter\r
- * @param facet name of the facet\r
- * @param count maximum number of facet terms to return\r
- * @return facet term list limited to 'count' terms\r
- */\r
- public List<TermResponse> getFacetTerms (String facet, int count);\r
- \r
- /**\r
- * Returns all the terms of a given facet - or as many as pazpar2 returns\r
- * @param facet name of the facet\r
- * @return facet term list\r
- */\r
- public List<TermResponse> getFacetTerms (String facet);\r
- \r
- /**\r
- * Returns a ByTarget data object as retrieved by the most recent 'bytarget' \r
- * request to pazpar2\r
- * \r
- * @return ByTarget response data object\r
- */\r
- public ByTarget getByTarget();\r
+ \r
\r
/**\r
* Initiates a pager object, a component holding the data to draw a sequence\r
*/\r
public boolean hasConfigurationErrors();\r
\r
- /**\r
- * Returns one (of possibly multiple) errors encountered during execution of commands\r
- * Will prefer to show the search errors - if any - as the search command is usually \r
- * executed first. \r
- * \r
- * @return\r
- */\r
- public ErrorInterface getCommandError();\r
\r
/**\r
* Returns all errors encountered during configuration of the application, in particular\r
\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.pz2utils4jsf.config.Configuration;\r
import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.SearchCommand;\r
-import com.indexdata.pz2utils4jsf.pazpar2.sp.ForServiceProxy;\r
import com.indexdata.pz2utils4jsf.pazpar2.sp.ServiceProxyClient;\r
import com.indexdata.pz2utils4jsf.pazpar2.sp.ServiceProxyInterface;\r
-import com.indexdata.pz2utils4jsf.pazpar2.sp.ServiceProxySession;\r
import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.ServiceProxyUser;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
\r
private static final long serialVersionUID = 4221824985678758225L;\r
private static Logger logger = Logger.getLogger(Pz2ProxyBean.class); \r
+ private String initDocFileName = "";\r
+ private String initDocResponse = "";\r
+ private String serviceProxyUrl = ""; \r
\r
@Inject ConfigurationReader configurator;\r
- @Inject ServiceProxyUser user; \r
- @Inject @ForServiceProxy ServiceProxySession pz2;\r
+ @Inject ServiceProxyUser user; \r
\r
public Pz2ProxyBean() {\r
}\r
\r
@PostConstruct\r
- public void instantiateServiceProxyClient() {\r
- logger.debug(Utils.objectId(this) + " will instantiate a ServiceProxyClient next."); \r
- searchClient = new ServiceProxyClient();\r
- logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
- + Utils.objectId(configurator) + "] on session [" \r
- + Utils.objectId(pz2) + "]" ); \r
- pz2.configureClient(searchClient,configurator);\r
+ public void postConstruct() {\r
+ if (searchClient == null) {\r
+ logger.debug(Utils.objectId(this) + " will instantiate a ServiceProxyClient next."); \r
+ searchClient = new ServiceProxyClient();\r
+ logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+ + Utils.objectId(configurator) + "]" ); \r
+ configureClient(searchClient,configurator);\r
+ } else {\r
+ logger.info("Pz2ProxyBean:postConstruct: searchClient already instantiated " +\r
+ "during construction of parent object Pz2Bean.");\r
+ }\r
}\r
\r
@Override\r
public String login(String navigateTo) {\r
logger.info("doing login");\r
- session().setUser(user);\r
- session().resetDataObjects();\r
- session().removeCommand("record");\r
- ((SearchCommand)session().getCommand("search")).setQuery(null);\r
- return session().login(navigateTo);\r
- }\r
-\r
- @Override\r
- public void setInitFileName(String fileName) {\r
- logger.info("Setting init file name: " + fileName);\r
- session().setInitFileName(fileName); \r
+ ((ServiceProxyClient)searchClient).authenticate(user);\r
+ data.reset();\r
+ req.getRecord().removeParameters();\r
+ req.getSearch().setQuery(null);\r
+ \r
+ return navigateTo;\r
}\r
\r
@Override\r
- public String getInitFileName() {\r
- return session().getInitFileName();\r
- }\r
- \r
- public void setAceFilter (String filterExpression) {\r
- session().setAceFilter(filterExpression);\r
+ public void setServiceProxyUrl(String url) {\r
+ logger.info("Setting Service Proxy url: " + url);\r
+ serviceProxyUrl = url;\r
+ req.getSearch().setQuery(null);\r
+ data.reset();\r
}\r
\r
- public String getAceFilter () {\r
- return session().getAceFilter();\r
+ public String getServiceProxyUrl() {\r
+ return serviceProxyUrl;\r
}\r
-\r
- @Override\r
- public String postInit() throws UnsupportedEncodingException, IOException {\r
- logger.info("Posting init: " + System.currentTimeMillis());\r
- session().postInit();\r
- return "";\r
+ \r
+ public String getInitDocPath () {\r
+ return searchClient.getConfiguration().get("INIT_DOC_PATH");\r
}\r
\r
- public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException {\r
- logger.info("Posting init: " + System.currentTimeMillis());\r
- session().postInit(initDoc);\r
- return "";\r
+ @Override\r
+ public void setInitFileName(String fileName) {\r
+ this.initDocFileName = fileName;\r
\r
}\r
\r
@Override\r
- public void setServiceProxyUrl(String url) {\r
- logger.info("Setting Service Proxy url: " + url);\r
- session().setServiceProxyUrl(url); \r
- ((SearchCommand)session().getCommand("search")).setQuery(null);\r
- session().resetDataObjects();\r
+ public String getInitFileName() {\r
+ return initDocFileName;\r
}\r
\r
@Override\r
- public String getServiceProxyUrl() {\r
- return session().getServiceProxyUrl(); \r
+ public String postInit() throws UnsupportedEncodingException, IOException { \r
+ String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths()[0];\r
+ logger.info("Paths: " + ((ServiceProxyClient)searchClient).getInitDocPaths());\r
+ logger.info("Path: " + initDocPath);\r
+ data.reset();\r
+ byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDocPath + getInitFileName());\r
+ initDocResponse = new String(response,"UTF-8");\r
+ return initDocResponse;\r
}\r
\r
- public ServiceProxySession session() {\r
- return (ServiceProxySession)pz2;\r
+ @Override\r
+ public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException { \r
+ data.reset();\r
+ byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc);\r
+ initDocResponse = new String(response,"UTF-8");\r
+ return initDocResponse;\r
}\r
\r
+\r
@Override\r
public String getInitResponse() {\r
- return session().getInitResponse();\r
+ return initDocResponse;\r
}\r
\r
- public Configuration getClientConfiguration() {\r
- return session().client().getConfiguration();\r
+ public void setAceFilter(String filterExpression) {\r
+ //setCommandParameter("record",new CommandParameter("acefilter","=",filterExpression));\r
}\r
\r
- public String getInitDocPath () {\r
- return session().client().getConfiguration().get("INIT_DOC_PATH");\r
+ public String getAceFilter () {\r
+ return null;\r
+ // return getCommandParameterValue("record","acefilter","");\r
}\r
\r
+\r
}\r
+++ /dev/null
-package com.indexdata.pz2utils4jsf.pazpar2;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.StringTokenizer;\r
-import java.util.concurrent.ConcurrentHashMap;\r
-\r
-import javax.annotation.PostConstruct;\r
-import javax.inject.Inject;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
-import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
-import com.indexdata.pz2utils4jsf.errors.ConfigurationError;\r
-import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
-import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
-import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.CommandError;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseParser;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.SearchResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.StatResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.state.StateListener;\r
-import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
-import com.indexdata.pz2utils4jsf.utils.Utils;\r
-\r
-@ForStraightPz2\r
-public class Pz2Session implements Pz2Interface, StateListener {\r
- \r
- private static final long serialVersionUID = 3947514708343320514L;\r
- private static Logger logger = Logger.getLogger(Pz2Session.class);\r
- \r
- protected Map<String,Pazpar2ResponseData> dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
- \r
- @Inject StateManager stateMgr;\r
- @Inject Pazpar2Commands req;\r
- \r
- protected ErrorHelper errorHelper = null;\r
- \r
- protected List<ErrorInterface> configurationErrors = null;\r
- protected SearchClient searchClient = null; \r
- protected ResultsPager pager = null; \r
- \r
- public Pz2Session () {\r
- logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); \r
- }\r
- \r
- @PostConstruct\r
- public void listenToStateManager() {\r
- logger.debug("in post-construct of Pz2Session stateMgr is " + stateMgr);\r
- logger.debug("in post-construct req is " + req);\r
- stateMgr.addStateListener(this);\r
- }\r
- \r
- public void configureClient(SearchClient searchClient, ConfigurationReader configReader) {\r
- configurationErrors = new ArrayList<ErrorInterface>();\r
- errorHelper = new ErrorHelper(configReader); \r
- logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
- try {\r
- searchClient.configure(configReader); \r
- // At the time of writing this search client is injected using Weld. \r
- // However, the client is used for asynchronously sending off requests\r
- // to the server AND propagation of context to threads is currently \r
- // not supported. Trying to do so throws a WELD-001303 error. \r
- // To avoid that, a context free client is cloned from the context \r
- // dependent one. \r
- // If propagation to threads gets supported, the cloning can go. \r
- this.searchClient = searchClient.cloneMe(); \r
- } catch (ConfigurationException e) {\r
- configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); \r
- } \r
- logger.info(configReader.document());\r
- resetDataObjects();\r
- }\r
- \r
- public void doSearch(String query) {\r
- setCommandParameter("search",new CommandParameter("query","=",query)); \r
- doSearch();\r
- }\r
-\r
- public void doSearch() { \r
- stateMgr.hasPendingStateChange("search",false);\r
- resetDataObjects();\r
- removeCommand("record");\r
- setCommandParameter("show",new CommandParameter("start","=",0)); \r
- logger.debug(Utils.objectId(this) + " is searching using "+req.getCommandReadOnly("search").getUrlEncodedParameterValue("query"));\r
- doCommand("search"); \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
- return update("show,stat,termlist,bytarget");\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
- */\r
- public String update (String commands) {\r
- if (! hasConfigurationErrors()) {\r
- if (hasQuery()) {\r
- handleQueryStateChanges(commands);\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(req.getCommandReadOnly(tokens.nextToken()),searchClient)); \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
- for (CommandThread thread : threadList) {\r
- String commandName = thread.getCommand().getName();\r
- String response = thread.getResponse();\r
- logger.debug("Response was: " + response);\r
- Pazpar2ResponseData responseObject = Pazpar2ResponseParser.getParser().getDataObject(response);\r
- dataObjects.put(commandName, responseObject); \r
- }\r
- if (commands.equals("record")) {\r
- logger.debug("Record: Active clients: "+getRecord().getActiveClients());\r
- return getRecord().getActiveClients();\r
- } else {\r
- return getActiveClients();\r
- } \r
- } else {\r
- logger.debug("Skipped requests for " + commands + " as there's not yet a query."); \r
- resetDataObjects();\r
- return "0";\r
- }\r
- } else {\r
- logger.error("Did not attempt to execute query since there are configuration errors.");\r
- return "0";\r
- }\r
- \r
- }\r
- \r
- \r
- public String toggleRecord (String recId) {\r
- if (hasRecord(recId)) {\r
- removeCommand("record"); \r
- dataObjects.put("record", new RecordResponse());\r
- return "";\r
- } else {\r
- req.getRecord().setRecordId(recId);\r
- return doCommand("record");\r
- }\r
- }\r
- \r
- @Override\r
- public boolean hasRecord (String recId) {\r
- return req.getCommandReadOnly("record").hasParameters() && getRecord().getRecId().equals(recId);\r
- }\r
- \r
- public ShowResponse getShow () {\r
- return ((ShowResponse) dataObjects.get("show"));\r
- }\r
- \r
- public StatResponse getStat () {\r
- return ((StatResponse) dataObjects.get("stat"));\r
- }\r
- \r
- public RecordResponse getRecord() {\r
- return ((RecordResponse) dataObjects.get("record"));\r
- }\r
- \r
- public TermListsResponse getTermLists () {\r
- return ((TermListsResponse) dataObjects.get("termlist"));\r
- }\r
- \r
- public List<TermResponse> getFacetTerms (String facet, int count) {\r
- return (getTermLists().getTermList(facet).getTerms(count));\r
- }\r
- \r
- public List<TermResponse> getFacetTerms (String facet) {\r
- return (getTermLists().getTermList(facet).getTerms());\r
- }\r
- \r
- public ByTarget getByTarget() {\r
- return ((ByTarget) dataObjects.get("bytarget"));\r
- }\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
- public boolean hasConfigurationErrors () {\r
- return (configurationErrors.size()>0); \r
- }\r
- \r
- public boolean hasCommandErrors () {\r
- if (dataObjects.get("search").hasApplicationError()) {\r
- logger.info("Error detected in search");\r
- return true;\r
- }\r
- for (String name : dataObjects.keySet()) {\r
- if (dataObjects.get(name).hasApplicationError()) {\r
- logger.info("Error detected in " + name);\r
- return true;\r
- }\r
- } \r
- return false; \r
- }\r
- \r
- /**\r
- * Returns true if application error found in any response data objects \r
- */\r
- public boolean hasErrors () {\r
- return hasConfigurationErrors() || hasCommandErrors();\r
- }\r
-\r
- public List<ErrorInterface> getConfigurationErrors() { \r
- return configurationErrors;\r
- }\r
- \r
- /**\r
- * Returns a search command error, if any, otherwise the first\r
- * error found for an arbitrary command, if any, otherwise\r
- * an empty dummy error. \r
- */ \r
- public ErrorInterface getCommandError() {\r
- CommandError error = new CommandError(); \r
- if (dataObjects.get("search").hasApplicationError()) {\r
- error = dataObjects.get("search").getApplicationError(); \r
- } else {\r
- for (String name : dataObjects.keySet()) { \r
- if (dataObjects.get(name).hasApplicationError()) { \r
- error = dataObjects.get(name).getApplicationError(); \r
- break;\r
- } \r
- }\r
- }\r
- error.setErrorHelper(errorHelper);\r
- return error; \r
- }\r
- \r
- protected boolean hasQuery() { \r
- return req.getSearch().getParameter("query") != null && req.getSearch().getParameter("query").getValueWithExpressions().length()>0;\r
- }\r
- \r
- public boolean hasRecords () {\r
- return getStat().getRecords() > 0 \r
- && getShow().getHits() != null \r
- && getShow().getHits().size()>0;\r
- }\r
- \r
- public ResultsPager getPager () {\r
- if (pager == null) {\r
- pager = new ResultsPager(this); \r
- } \r
- return pager; \r
- }\r
- \r
- public ResultsPager setPager (int pageRange) {\r
- pager = new ResultsPager(this,pageRange,req);\r
- return pager;\r
- }\r
- \r
- protected ErrorHelper getTroubleshooter() {\r
- return errorHelper;\r
- }\r
- \r
- protected void handleQueryStateChanges (String commands) {\r
- if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
- logger.debug("Found pending search change. Doing search before updating " + commands); \r
- doSearch();\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
- if (req.getCommandReadOnly("record").hasParameters()) {\r
- update("record");\r
- } else {\r
- removeCommand("record"); \r
- dataObjects.put("record", new RecordResponse());\r
- }\r
- }\r
- }\r
-\r
- protected String getActiveClients() { \r
- if (getShow()!=null) {\r
- logger.debug("Active clients: "+getShow().getActiveClients());\r
- return getShow().getActiveClients();\r
- } else {\r
- return "";\r
- }\r
- }\r
-\r
- /**\r
- * Returns a Pazpar2 command 'detached' from the current Pazpar2 state.\r
- * \r
- * 'Detached' is meant to imply that this is a copy of a command in the \r
- * current state, detached so as to NOT change the current state if \r
- * modified. It can be viewed and executed, however. \r
- * \r
- * In order to modify the command with effect for subsequent searches,\r
- * it must be checked back into the StateManager, which will\r
- * then create a new current Pazpar2 state as needed.\r
- * \r
- * @param name\r
- * @return\r
- */\r
- protected Pazpar2Command getCommand(String name) {\r
- return req.getCommand(name);\r
- }\r
- \r
- /** \r
- * Returns an interface to a Pazpar2Command with only String getters.\r
- * \r
- * Since the command cannot be modified (unless it is cast) we can avoid \r
- * cloning it before returning it from the current state. \r
- * It can be used for log statements, checks and for performing the \r
- * actual pazpar2 request. \r
- * \r
- * @param name\r
- * @return\r
- */\r
- protected CommandReadOnly getCommandReadOnly(String name) {\r
- return req.getCommandReadOnly(name);\r
- }\r
-\r
- \r
- protected void setCommandParameter(String commandName, CommandParameter parameter) {\r
- logger.debug("Setting parameter for " + commandName + ": " + parameter);\r
- Pazpar2Command command = req.getCommand(commandName);\r
- command.setParameter(parameter);\r
- stateMgr.checkIn(command); \r
- }\r
- \r
- \r
- protected void removeCommandParameter(String commandName, String parameterName) {\r
- Pazpar2Command command = req.getCommand(commandName);\r
- command.removeParameter(parameterName);\r
- stateMgr.checkIn(command); \r
- }\r
- \r
- protected void removeCommand (String commandName) {\r
- Pazpar2Command command = req.getCommand(commandName);\r
- command.removeParameters();\r
- stateMgr.checkIn(command);\r
- }\r
- \r
- protected String getCommandParameterValue (String commandName, String parameterName, String defaultValue) { \r
- CommandReadOnly command = req.getCommandReadOnly(commandName);\r
- if (command != null) {\r
- String parameter = command.getParameterValue(parameterName);\r
- if (parameter != null) {\r
- return parameter;\r
- }\r
- }\r
- return defaultValue; \r
- }\r
- \r
- protected int getCommandParameterValue (String commandName, String parameterName, int defaultValue) {\r
- CommandReadOnly command = req.getCommandReadOnly(commandName);\r
- if (command != null) {\r
- String parameter = command.getParameterValue(parameterName);\r
- if (parameter != null) {\r
- return Integer.parseInt(parameter);\r
- }\r
- }\r
- return defaultValue; \r
- }\r
-\r
- protected String doCommand(String commandName) { \r
- logger.debug(req.getCommandReadOnly(commandName).getEncodedQueryString() + ": Results for "+ req.getCommandReadOnly("search").getEncodedQueryString());\r
- return update(commandName);\r
- }\r
- \r
- protected void resetDataObjects() {\r
- logger.debug("Resetting show,stat,termlist,bytarget,search response objects.");\r
- dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
- dataObjects.put("show", new ShowResponse());\r
- dataObjects.put("stat", new StatResponse());\r
- dataObjects.put("termlist", new TermListsResponse());\r
- dataObjects.put("bytarget", new ByTarget());\r
- dataObjects.put("record", new RecordResponse());\r
- dataObjects.put("search", new SearchResponse());\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
public Pazpar2Command (String name, StateManager stateMgr) {\r
this.name = name;\r
- this.stateMgr = stateMgr;\r
+ if (stateMgr == null) {\r
+ // Set one-off dummy state mgr\r
+ this.stateMgr = new StateManager();\r
+ } else {\r
+ this.stateMgr = stateMgr;\r
+ }\r
}\r
\r
public Pazpar2Command copy () {\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.data;\r
+\r
+import java.io.Serializable;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.concurrent.ConcurrentHashMap;\r
+\r
+import javax.enterprise.context.SessionScoped;\r
+import javax.inject.Named;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
+\r
+@Named("data") @SessionScoped\r
+public class Pazpar2Responses implements Serializable {\r
+ \r
+ private static final long serialVersionUID = -7543231258346154642L;\r
+ protected Map<String,Pazpar2ResponseData> dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
+ private static Logger logger = Logger.getLogger(Pazpar2Responses.class);\r
+\r
+ public Pazpar2Responses() { \r
+ }\r
+ \r
+ public void put(String name, Pazpar2ResponseData responseData) {\r
+ dataObjects.put(name, responseData);\r
+ }\r
+ \r
+ public boolean hasApplicationError () {\r
+ if (getSearch().hasApplicationError()) {\r
+ logger.info("Error detected in search");\r
+ return true;\r
+ }\r
+ for (String name : dataObjects.keySet()) {\r
+ if (dataObjects.get(name).hasApplicationError()) {\r
+ logger.info("Error detected in " + name);\r
+ return true;\r
+ }\r
+ } \r
+ return false;\r
+ }\r
+ \r
+ /**\r
+ * Returns a search command error, if any, otherwise the first\r
+ * error found for an arbitrary command, if any, otherwise\r
+ * an empty dummy error. \r
+ */ \r
+ public ErrorInterface getCommandError() {\r
+ CommandError error = new CommandError(); \r
+ if (dataObjects.get("search").hasApplicationError()) {\r
+ error = dataObjects.get("search").getApplicationError(); \r
+ } else {\r
+ for (String name : dataObjects.keySet()) { \r
+ if (dataObjects.get(name).hasApplicationError()) { \r
+ error = dataObjects.get(name).getApplicationError(); \r
+ break;\r
+ } \r
+ }\r
+ }\r
+ // TODO error.setErrorHelper(errorHelper);\r
+ return error; \r
+ }\r
+ \r
+ public void reset() {\r
+ logger.debug("Resetting show,stat,termlist,bytarget,search response objects.");\r
+ dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
+ dataObjects.put("show", new ShowResponse());\r
+ dataObjects.put("stat", new StatResponse());\r
+ dataObjects.put("termlist", new TermListsResponse());\r
+ dataObjects.put("bytarget", new ByTarget());\r
+ dataObjects.put("record", new RecordResponse());\r
+ dataObjects.put("search", new SearchResponse());\r
+ }\r
+\r
+ public ShowResponse getShow () {\r
+ return ((ShowResponse) dataObjects.get("show"));\r
+ }\r
+ \r
+ public StatResponse getStat () {\r
+ return ((StatResponse) dataObjects.get("stat"));\r
+ }\r
+ \r
+ public RecordResponse getRecord() {\r
+ return ((RecordResponse) dataObjects.get("record"));\r
+ }\r
+ \r
+ public SearchResponse getSearch() {\r
+ return ((SearchResponse) dataObjects.get("search"));\r
+ }\r
+ \r
+ public TermListsResponse getTermLists () {\r
+ return ((TermListsResponse) dataObjects.get("termlist"));\r
+ }\r
+ \r
+ public List<TermResponse> getFacetTerms (String facet, int count) {\r
+ return (getTermLists().getTermList(facet).getTerms(count));\r
+ }\r
+ \r
+ public List<TermResponse> getFacetTerms (String facet) {\r
+ return (getTermLists().getTermList(facet).getTerms());\r
+ }\r
+ \r
+ public ByTarget getByTarget() {\r
+ return ((ByTarget) dataObjects.get("bytarget"));\r
+ }\r
+\r
+ public boolean hasRecords () {\r
+ return getStat().getRecords() > 0 \r
+ && getShow().getHits() != null \r
+ && getShow().getHits().size()>0;\r
+ }\r
+ \r
+ public String getActiveClients() { \r
+ if (getShow()!=null) {\r
+ logger.debug("Active clients: "+getShow().getActiveClients());\r
+ return getShow().getActiveClients();\r
+ } else {\r
+ return "";\r
+ }\r
+ }\r
+\r
+\r
+}\r
+++ /dev/null
-package com.indexdata.pz2utils4jsf.pazpar2.sp;\r
-\r
-import java.lang.annotation.ElementType;\r
-import java.lang.annotation.Retention;\r
-import java.lang.annotation.RetentionPolicy;\r
-import java.lang.annotation.Target;\r
-\r
-import javax.inject.Qualifier;\r
-\r
-@Qualifier\r
-@Retention(RetentionPolicy.RUNTIME)\r
-@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})\r
-public @interface ForServiceProxy {\r
-\r
-}\r
import java.util.List;\r
import java.util.Map;\r
\r
-import javax.enterprise.context.SessionScoped;\r
-import javax.inject.Named;\r
-\r
import org.apache.http.HttpEntity;\r
import org.apache.http.HttpResponse;\r
import org.apache.http.StatusLine;\r
import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.AuthenticationEntity;\r
import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.ServiceProxyUser;\r
-import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
-@Named @SessionScoped \r
+\r
public class ServiceProxyClient implements SearchClient {\r
\r
private static final long serialVersionUID = -4031644009579840277L;\r
try { \r
logger.info("Authenticating [" + user.getProperty("name") + "]");\r
this.user = (ServiceProxyUser) user;\r
- Pazpar2Command auth = new Pazpar2Command("auth",new StateManager());\r
+ Pazpar2Command auth = new Pazpar2Command("auth",null);\r
auth.setParameters(new CommandParameter("action","=","login"), \r
new CommandParameter("username","=",user.getProperty("name")), \r
new CommandParameter("password","=",user.getProperty("password")));\r
\r
public boolean checkAuthentication () {\r
try {\r
- Pazpar2Command check = new Pazpar2Command("auth",new StateManager());\r
+ Pazpar2Command check = new Pazpar2Command("auth",null);\r
check.setParameter(new CommandParameter("action","=","check"));\r
byte[] response = send(check);\r
logger.info(new String(response,"UTF-8"));\r
+++ /dev/null
-package com.indexdata.pz2utils4jsf.pazpar2.sp;\r
-\r
-import java.io.IOException;\r
-import java.io.UnsupportedEncodingException;\r
-\r
-import javax.enterprise.context.SessionScoped;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session;\r
-import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\r
-import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.ServiceProxyUser;\r
-import com.indexdata.pz2utils4jsf.utils.Utils;\r
-\r
-@ForServiceProxy @SessionScoped\r
-public class ServiceProxySession extends Pz2Session implements ServiceProxyInterface {\r
-\r
- private ServiceProxyUser user; \r
- private static final long serialVersionUID = -5770410029361522854L;\r
- private static Logger logger = Logger.getLogger(ServiceProxySession.class);\r
- private String initDocFileName = "";\r
- private String initDocResponse = ""; \r
- \r
- public ServiceProxySession() {\r
- logger.info("Instantiating SP pz2 session object [" + Utils.objectId(this) + "]");\r
- }\r
- \r
- public void setUser(ServiceProxyUser user) {\r
- this.user = user;\r
- }\r
-\r
- @Override\r
- public String login(String navigateTo) {\r
- if (client().authenticate(user)) {\r
- return navigateTo;\r
- } else {\r
- return null;\r
- } \r
- }\r
-\r
- @Override\r
- public void setInitFileName(String fileName) {\r
- this.initDocFileName = fileName;\r
- \r
- }\r
-\r
- @Override\r
- public String getInitFileName() {\r
- return initDocFileName;\r
- }\r
-\r
- @Override\r
- public String postInit() throws UnsupportedEncodingException, IOException { \r
- String initDocPath = client().getInitDocPaths()[0];\r
- logger.info("Paths: " + client().getInitDocPaths());\r
- logger.info("Path: " + initDocPath);\r
- this.resetDataObjects();\r
- byte[] response = client().postInitDoc(initDocPath + getInitFileName());\r
- initDocResponse = new String(response,"UTF-8");\r
- return initDocResponse;\r
- }\r
- \r
- @Override\r
- public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException { \r
- this.resetDataObjects();\r
- byte[] response = client().postInitDoc(initDoc);\r
- initDocResponse = new String(response,"UTF-8");\r
- return initDocResponse;\r
- }\r
-\r
-\r
- @Override\r
- public void setServiceProxyUrl(String url) {\r
- client().setServiceProxyUrl(url);\r
- \r
- }\r
-\r
- @Override\r
- public String getServiceProxyUrl() {\r
- return client().getServiceProxyUrl();\r
- }\r
- \r
- public ServiceProxyClient client () {\r
- return (ServiceProxyClient)searchClient;\r
- }\r
-\r
- @Override\r
- public String getInitResponse() {\r
- return initDocResponse;\r
- }\r
- \r
- public void setAceFilter(String filterExpression) {\r
- setCommandParameter("record",new CommandParameter("acefilter","=",filterExpression));\r
- }\r
- \r
- public String getAceFilter () {\r
- return getCommandParameterValue("record","acefilter","");\r
- }\r
- \r
-}\r