X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fpz2utils4jsf%2Fpazpar2%2FPz2Session.java;h=d5066780bdd6ace1a820bd9bd24b6d7f5dfd2a8f;hb=6ecfe8692fcb0f9840b28325f413fc698093fa88;hp=58b296fffa1bdd9e1fb06b79243a98369c9c7d42;hpb=5ce9f5404929b726668d3332c5bdba4dbd1d1d1f;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index 58b296f..d506678 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -11,8 +11,9 @@ import javax.inject.Named; import org.apache.log4j.Logger; -import com.indexdata.pz2utils4jsf.config.Pz2Configurator; +import com.indexdata.pz2utils4jsf.config.ConfigurationReader; import com.indexdata.pz2utils4jsf.controls.ResultsPager; +import com.indexdata.pz2utils4jsf.errors.ConfigurationError; import com.indexdata.pz2utils4jsf.errors.ConfigurationException; import com.indexdata.pz2utils4jsf.errors.ErrorHelper; import com.indexdata.pz2utils4jsf.errors.ErrorInterface; @@ -35,40 +36,41 @@ public class Pz2Session implements Pz2Interface { private static final long serialVersionUID = 3947514708343320514L; private static Logger logger = Logger.getLogger(Pz2Session.class); - private Map dataObjects = new ConcurrentHashMap(); - private QueryStates queryStates = new QueryStates(); - private ErrorHelper errorHelper = null; + protected Map dataObjects = new ConcurrentHashMap(); + protected QueryStates queryStates = new QueryStates(); + protected ErrorHelper errorHelper = null; - private List configurationErrors = null; - private SearchClient searchClient = null; - private TargetFilter targetFilter = null; - private ResultsPager pager = null; + protected List configurationErrors = null; + protected SearchClient searchClient = null; + protected TargetFilter targetFilter = null; + protected ResultsPager pager = null; public Pz2Session () { logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); } - public void init(SearchClient searchClient, Pz2Configurator configurator) { + public void init(SearchClient searchClient, ConfigurationReader configReader) { configurationErrors = new ArrayList(); - errorHelper = new ErrorHelper(configurator); + errorHelper = new ErrorHelper(configReader); logger.debug(Utils.objectId(this) + " will configure search client for the session"); try { - searchClient.configure(configurator); - - // The cloning is a hack: + searchClient.configure(configReader); // At the time of writing this search client is injected using Weld. // However, the client is used for asynchronously sending off requests - // to the server AND propagation of context to threads is not supported. - // Trying so will throw a WELD-001303 error. To avoid that, a context - // free client is spawned from the context dependent one. - this.searchClient = searchClient.cloneMe(); + // to the server AND propagation of context to threads is currently + // not supported. Trying to do so throws a WELD-001303 error. + // To avoid that, a context free client is cloned from the context + // dependent one. + // If propagation to threads gets supported, the cloning can go. + this.searchClient = searchClient.cloneMe(); } catch (ConfigurationException e) { - logger.info("Found " + configurationErrors.size() + " configuration errors"); - } + configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); + } + logger.info(configReader.document()); resetDataObjects(); } - + public void doSearch(String query) { setCommandParameter("search",new CommandParameter("query","=",query)); doSearch(); @@ -334,11 +336,11 @@ public class Pz2Session implements Pz2Interface { } - private boolean hasTargetFilter(TargetFilter targetFilter) { + protected boolean hasTargetFilter(TargetFilter targetFilter) { return hasTargetFilter() && targetFilter.equals(this.targetFilter); } - private boolean hasQuery() { + protected boolean hasQuery() { return !(getCommand("search").getParameter("query") == null); } @@ -364,7 +366,7 @@ public class Pz2Session implements Pz2Interface { return errorHelper; } - private void handleQueryStateChanges (String commands) { + protected void handleQueryStateChanges (String commands) { if (queryStates.hasPendingStateChange("search")) { logger.debug("Found pending search change. Doing search before updating " + commands); doSearch(); @@ -381,7 +383,7 @@ public class Pz2Session implements Pz2Interface { } } - private String getActiveClients() { + protected String getActiveClients() { if (getShow()!=null) { logger.debug("Active clients: "+getShow().getActiveClients()); return getShow().getActiveClients(); @@ -390,25 +392,25 @@ public class Pz2Session implements Pz2Interface { } } - private Pazpar2Command getCommand(String name) { + protected Pazpar2Command getCommand(String name) { return queryStates.getCurrentState().getCommand(name); } - private void setCommandParameter(String commandName, CommandParameter parameter) { + protected void setCommandParameter(String commandName, CommandParameter parameter) { logger.debug("Setting parameter for " + commandName + ": " + parameter); queryStates.getCurrentState().setCommandParameter(commandName, parameter, queryStates); } - private void removeCommandParameter(String commandName, String parameterName) { + protected void removeCommandParameter(String commandName, String parameterName) { queryStates.getCurrentState().removeCommandParameter(commandName,parameterName,queryStates); } - private void removeCommand (String commandName) { + protected void removeCommand (String commandName) { queryStates.getCurrentState().removeCommand(commandName, queryStates); } - private String getCommandParameterValue (String commandName, String parameterName, String defaultValue) { + protected String getCommandParameterValue (String commandName, String parameterName, String defaultValue) { Pazpar2Command command = getCommand(commandName); if (command != null) { CommandParameter parameter = command.getParameter(parameterName); @@ -419,7 +421,7 @@ public class Pz2Session implements Pz2Interface { return defaultValue; } - private String getCommandParameterValueSimple (String commandName, String parameterName, String defaultValue) { + protected String getCommandParameterValueSimple (String commandName, String parameterName, String defaultValue) { Pazpar2Command command = getCommand(commandName); if (command != null) { CommandParameter parameter = command.getParameter(parameterName); @@ -431,7 +433,7 @@ public class Pz2Session implements Pz2Interface { } - private int getCommandParameterValue (String commandName, String parameterName, int defaultValue) { + protected int getCommandParameterValue (String commandName, String parameterName, int defaultValue) { Pazpar2Command command = getCommand(commandName); if (command != null) { CommandParameter parameter = command.getParameter(parameterName); @@ -442,13 +444,13 @@ public class Pz2Session implements Pz2Interface { return defaultValue; } - private String doCommand(String commandName) { + protected String doCommand(String commandName) { Pazpar2Command command = getCommand(commandName); logger.debug(command.getEncodedQueryString() + ": Results for "+ getCommand("search").getEncodedQueryString()); - return update(commandName); + return update(commandName); } - private void resetDataObjects() { + protected void resetDataObjects() { logger.debug("Resetting show,stat,termlist,bytarget,search response objects."); dataObjects = new ConcurrentHashMap(); dataObjects.put("show", new ShowResponse());