<dependency>\r
<groupId>org.glassfish</groupId>\r
<artifactId>javax.faces</artifactId>\r
- <version>2.1.16</version>\r
+ <version>2.1.21</version>\r
</dependency>\r
<dependency>\r
<groupId>javax.servlet.jsp.jstl</groupId>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
+ version="2.1">
+
+</faces-config>
\ No newline at end of file
+++ /dev/null
-package com.indexdata.pz2utils4jsf.pazpar2;\r
-\r
-import java.io.Serializable;\r
-import java.io.UnsupportedEncodingException;\r
-import java.net.URLEncoder;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter;\r
-\r
-public class CommandParameter implements Serializable {\r
-\r
- private static Logger logger = Logger.getLogger(CommandParameter.class);\r
- \r
- private static final long serialVersionUID = 625502285668766749L;\r
- String name = null;\r
- String operator = null;\r
- String value = null;\r
- Map<String,Expression> expressions = new HashMap<String,Expression>();\r
- \r
- public CommandParameter (String name) {\r
- logger.debug("Instantiating command parameter (1) " + name);\r
- this.name = name;\r
- }\r
- \r
- public CommandParameter (String name, String operator, String value, Expression... expressions) {\r
- logger.debug("Instantiating command parameter (2) " + name + " with " + expressions);\r
- this.name = name;\r
- this.operator = operator;\r
- this.value = value;\r
- for (Expression expr : expressions) {\r
- this.expressions.put(expr.toString(), expr);\r
- }\r
- }\r
-\r
- public CommandParameter (String name, String operator, String value) {\r
- logger.debug("Instantiating command parameter (3) " + name + " ("+this+") with " + name + " and " + value);\r
- this.name = name;\r
- this.operator = operator;\r
- this.value = value; \r
- }\r
- \r
- public CommandParameter (String name, String operator, int value) {\r
- logger.debug("Instantiating command parameter (4) " + name + " ("+this+") with " + name + " and " + value);\r
- this.name = name;\r
- this.operator = operator;\r
- this.value = value+""; \r
- }\r
-\r
- \r
- public String getName () {\r
- return name;\r
- }\r
- \r
- public Map<String,Expression> getExpressions () {\r
- return expressions;\r
- }\r
- \r
- public void addExpression(Expression expression) {\r
- logger.debug("Adding expression [" + expression + "] to " + this.getName() + " ("+this+")");\r
- this.expressions.put(expression.toString(),expression);\r
- }\r
- \r
- public void removeExpression(Expression expression) {\r
- this.expressions.remove(expression.toString());\r
- }\r
- \r
- \r
- public boolean hasOperator() {\r
- return operator != null;\r
- }\r
- \r
- public String getEncodedQueryString () {\r
- try {\r
- return name + operator + URLEncoder.encode(getValueWithExpressions(),"UTF-8");\r
- } catch (UnsupportedEncodingException e) {\r
- e.printStackTrace();\r
- return null;\r
- }\r
- }\r
- \r
- public String getSimpleValue() { \r
- return value; \r
- }\r
- \r
- public String getValueWithExpressions () {\r
- StringBuilder completeValue = new StringBuilder((value==null ? "" : value)); \r
- for (String key : expressions.keySet()) { \r
- completeValue.append(" and " + expressions.get(key));\r
- }\r
- return completeValue.toString();\r
- \r
- }\r
- \r
- @Override\r
- public boolean equals (Object otherParameter) {\r
- return\r
- ((otherParameter instanceof CommandParameter)\r
- && this.getValueWithExpressions().equals(((CommandParameter) otherParameter).getValueWithExpressions()));\r
- }\r
- \r
- @Override\r
- public int hashCode () {\r
- return getValueWithExpressions().hashCode();\r
- }\r
- \r
- public String toString() {\r
- return getValueWithExpressions();\r
- }\r
- \r
- public CommandParameter copy() {\r
- CommandParameter newParam = new CommandParameter(name);\r
- newParam.value = this.value;\r
- newParam.operator = this.operator;\r
- for (String key : expressions.keySet()) {\r
- newParam.addExpression(expressions.get(key).copy()); \r
- }\r
- return newParam;\r
- }\r
- \r
-}\r
import org.apache.log4j.Logger;\r
\r
import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.CommandError;\r
\r
public class CommandThread extends Thread {\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 ForServiceProxy {\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
+++ /dev/null
-package com.indexdata.pz2utils4jsf.pazpar2;\r
-\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter;\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command;\r
-\r
-public class Pazpar2Command implements Serializable {\r
-\r
- private static Logger logger = Logger.getLogger(Pazpar2Command.class);\r
- private static final long serialVersionUID = -6825491856480675917L;\r
- public static List<String> allCommands = new ArrayList<String>(Arrays.asList("init","ping","settings","search","stat","show","record","termlist","bytarget"));\r
-\r
- private String name = "";\r
- private Map<String,CommandParameter> parameters = new HashMap<String,CommandParameter>();\r
- \r
- public Pazpar2Command (String name) { \r
- this.name = name;\r
- }\r
- \r
- public Pazpar2Command copy () {\r
- Pazpar2Command newCommand = new Pazpar2Command(name);\r
- for (String parameterName : parameters.keySet()) {\r
- newCommand.setParameter(parameters.get(parameterName).copy()); \r
- }\r
- return newCommand;\r
- }\r
- \r
- public String getName() {\r
- return name;\r
- }\r
- \r
- public void setParameter (CommandParameter parameter) {\r
- logger.debug("Setting parameter " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName());\r
- parameters.put(parameter.getName(),parameter);\r
- }\r
- \r
- public CommandParameter getParameter (String name) {\r
- return parameters.get(name);\r
- }\r
- \r
- public void removeParameter (String name) {\r
- parameters.remove(name); \r
- }\r
- \r
- public void removeParameters() {\r
- parameters = new HashMap<String,CommandParameter>();\r
- }\r
- \r
- public boolean hasParameters () {\r
- return (parameters.keySet().size()>0);\r
- }\r
- \r
- public String getEncodedQueryString () {\r
- StringBuilder queryString = new StringBuilder("command="+name);\r
- for (CommandParameter parameter : parameters.values()) {\r
- queryString.append("&"+parameter.getEncodedQueryString()); \r
- }\r
- return queryString.toString();\r
- } \r
- \r
- public String getValueWithExpressions() { \r
- StringBuilder value = new StringBuilder("");\r
- for (CommandParameter parameter : parameters.values()) {\r
- value.append("&" + parameter.getName() + parameter.operator + parameter.getValueWithExpressions()); \r
- }\r
- return value.toString();\r
- }\r
- \r
- @Override\r
- public boolean equals (Object otherCommand) {\r
- return\r
- ((otherCommand instanceof Pazpar2Command)\r
- && this.getValueWithExpressions().equals(((Pazpar2Command) otherCommand).getValueWithExpressions()));\r
- }\r
- \r
- @Override\r
- public int hashCode () {\r
- return getValueWithExpressions().hashCode();\r
- }\r
- \r
- public String toString () {\r
- return parameters.toString();\r
- }\r
- \r
-}\r
import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\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
private static Logger logger = Logger.getLogger(Pz2Bean.class);\r
\r
@Inject ConfigurationReader configurator;\r
- protected Pz2Session pz2; \r
+ \r
+ @Inject @ForStraightPz2 Pz2Session pz2; \r
+ \r
protected SearchClient searchClient; \r
\r
public Pz2Bean () {\r
logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]");\r
+ logger.debug("in Pz2Bean configurator is " + configurator);\r
}\r
\r
@PostConstruct\r
- public void instantiatePz2SessionObject() {\r
+ public void instantiatePz2SessionObject() { \r
+ logger.debug("in start of Pz2Bean post-construct configurator is " + configurator);\r
logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session next.");\r
- pz2 = new Pz2Session();\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
- }\r
- \r
+ pz2.configureClient(searchClient,configurator); \r
+ logger.debug("in end of Pz2Bean post-construct configurator is " + configurator);\r
+\r
+ } \r
\r
/* (non-Javadoc)\r
* @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch(java.lang.String)\r
* @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setQuery(java.lang.String)\r
*/\r
public void setQuery(String query) {\r
- pz2.setQuery(query);\r
+ pz2.req.getSearch().setQuery(query);\r
}\r
-\r
+ \r
/* (non-Javadoc)\r
* @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getQuery()\r
*/\r
public String getRecordId() {\r
return pz2.getRecordId();\r
}\r
+ \r
+ public Pazpar2Command getSearchCommand () {\r
+ return pz2.getCommand("search");\r
+ }\r
\r
}\r
import com.indexdata.pz2utils4jsf.config.Configuration;\r
import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
@Named @SessionScoped \r
@Inject ConfigurationReader configurator;\r
@Inject ServiceProxyUser user;\r
\r
+ @Inject @ForServiceProxy ServiceProxySession pz2;\r
+ \r
public Pz2ProxyBean() {\r
}\r
\r
@PostConstruct\r
public void instantiatePz2SessionObject() {\r
- logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session object next.");\r
- pz2 = new ServiceProxySession();\r
+ logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session object next."); \r
searchClient = new ServiceProxyClient();\r
logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+ Utils.objectId(configurator) + "] on session [" \r
import java.util.StringTokenizer;\r
import java.util.concurrent.ConcurrentHashMap;\r
\r
+import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
-import javax.inject.Named;\r
+import javax.inject.Inject;\r
\r
import org.apache.log4j.Logger;\r
\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.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.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 @SessionScoped \r
-public class Pz2Session implements Pz2Interface {\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
- protected StateManager stateManager = new StateManager();\r
+ \r
+ @Inject StateManager stateMgr;\r
+ @Inject Pazpar2Commands req;\r
+ \r
protected ErrorHelper errorHelper = null;\r
\r
protected List<ErrorInterface> configurationErrors = null;\r
protected ResultsPager pager = null; \r
\r
public Pz2Session () {\r
- logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); \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
}\r
\r
public void doSearch() { \r
- stateManager.hasPendingStateChange("search",false);\r
+ stateMgr.hasPendingStateChange("search",false);\r
resetDataObjects();\r
removeCommand("record");\r
setCommandParameter("show",new CommandParameter("start","=",0)); \r
if (term != null && term.length()>0) { \r
Pazpar2Command command = getCommand("search");\r
command.getParameter("query").addExpression(new Expression(facetKey,"=",term));\r
- stateManager.checkIn(command);\r
+ stateMgr.checkIn(command);\r
doSearch();\r
} \r
}\r
public void removeFacet(String facetKey, String term) {\r
Pazpar2Command command = getCommand("search");\r
command.getParameter("query").removeExpression(new Expression(facetKey,"=",term));\r
- stateManager.checkIn(command);\r
+ stateMgr.checkIn(command);\r
doSearch();\r
}\r
\r
\r
\r
public String getCurrentStateKey () { \r
- return stateManager.getCurrentState().getKey();\r
+ return stateMgr.getCurrentState().getKey();\r
}\r
\r
public void setCurrentStateKey(String key) { \r
- stateManager.setCurrentStateKey(key);\r
+ stateMgr.setCurrentStateKey(key);\r
}\r
\r
public boolean hasConfigurationErrors () {\r
}\r
\r
protected boolean hasQuery() {\r
- return getCommand("search").getParameter("query") != null && getCommand("search").getParameter("query").getValueWithExpressions().length()>0;\r
+ logger.debug("req is " + req);\r
+ return req.getSearch().getParameter("query") != null && req.getSearch().getParameter("query").getValueWithExpressions().length()>0;\r
}\r
\r
public boolean hasRecords () {\r
}\r
\r
protected void handleQueryStateChanges (String commands) {\r
- if (stateManager.hasPendingStateChange("search") && hasQuery()) { \r
+ if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
logger.debug("Found pending search change. Doing search before updating " + commands); \r
doSearch();\r
} \r
- if (stateManager.hasPendingStateChange("record") && ! commands.equals("record")) { \r
+ if (stateMgr.hasPendingStateChange("record") && ! commands.equals("record")) { \r
logger.debug("Found pending record ID change. Doing record before updating " + commands);\r
- stateManager.hasPendingStateChange("record",false);\r
+ stateMgr.hasPendingStateChange("record",false);\r
if (getCommand("record").hasParameters()) {\r
update("record");\r
} else {\r
removeCommand("record"); \r
dataObjects.put("record", new RecordResponse());\r
}\r
- } \r
+ }\r
}\r
\r
protected String getActiveClients() { \r
* @return\r
*/\r
protected Pazpar2Command getCommand(String name) {\r
- return stateManager.checkOut(name);\r
+ return stateMgr.checkOut(name);\r
}\r
\r
protected void setCommandParameter(String commandName, CommandParameter parameter) {\r
logger.debug("Setting parameter for " + commandName + ": " + parameter);\r
Pazpar2Command command = getCommand(commandName);\r
command.setParameter(parameter);\r
- stateManager.checkIn(command); \r
+ stateMgr.checkIn(command); \r
}\r
\r
\r
protected void removeCommandParameter(String commandName, String parameterName) {\r
Pazpar2Command command = getCommand(commandName);\r
command.removeParameter(parameterName);\r
- stateManager.checkIn(command); \r
+ stateMgr.checkIn(command); \r
}\r
\r
protected void removeCommand (String commandName) {\r
Pazpar2Command command = getCommand(commandName);\r
command.removeParameters();\r
- stateManager.checkIn(command);\r
+ stateMgr.checkIn(command);\r
}\r
\r
protected String getCommandParameterValue (String commandName, String parameterName, String defaultValue) { \r
}\r
\r
protected String doCommand(String commandName) { \r
- Pazpar2Command command = getCommand(commandName); \r
+ Pazpar2Command command = req.getCommand(commandName); \r
logger.debug(command.getEncodedQueryString() + ": Results for "+ getCommand("search").getEncodedQueryString());\r
return update(commandName);\r
}\r
public boolean hasFilter () {\r
return getFilter().length()>0;\r
}\r
+\r
+ @Override\r
+ public void stateUpdate(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
import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
import com.indexdata.pz2utils4jsf.config.Configurable;\r
import com.indexdata.pz2utils4jsf.config.Configuration;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
\r
public interface SearchClient extends Configurable, Serializable {\r
\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class BytargetCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = 9070458716105294392L;\r
+\r
+ public BytargetCommand(StateManager stateMgr) {\r
+ super("bytarget",stateMgr);\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import java.io.Serializable;\r
+import java.io.UnsupportedEncodingException;\r
+import java.net.URLEncoder;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.Expression;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\r
+\r
+public class CommandParameter implements Serializable {\r
+\r
+ private static Logger logger = Logger.getLogger(CommandParameter.class);\r
+ \r
+ private static final long serialVersionUID = 625502285668766749L;\r
+ String name = null;\r
+ String operator = null;\r
+ String value = null;\r
+ Map<String,Expression> expressions = new HashMap<String,Expression>();\r
+ \r
+ public CommandParameter (String name) {\r
+ logger.debug("Instantiating command parameter (1) " + name);\r
+ this.name = name;\r
+ }\r
+ \r
+ public CommandParameter (String name, String operator, String value, Expression... expressions) {\r
+ logger.debug("Instantiating command parameter (2) " + name + " with " + expressions);\r
+ this.name = name;\r
+ this.operator = operator;\r
+ this.value = value;\r
+ for (Expression expr : expressions) {\r
+ this.expressions.put(expr.toString(), expr);\r
+ }\r
+ }\r
+\r
+ public CommandParameter (String name, String operator, String value) {\r
+ logger.debug("Instantiating command parameter (3) " + name + " ("+this+") with " + value);\r
+ this.name = name;\r
+ this.operator = operator;\r
+ this.value = value; \r
+ }\r
+ \r
+ public CommandParameter (String name, String operator, int value) {\r
+ logger.debug("Instantiating command parameter (4) " + name + " ("+this+") with " + value);\r
+ this.name = name;\r
+ this.operator = operator;\r
+ this.value = value+""; \r
+ }\r
+\r
+ \r
+ public String getName () {\r
+ return name;\r
+ }\r
+ \r
+ public Map<String,Expression> getExpressions () {\r
+ return expressions;\r
+ }\r
+ \r
+ public void addExpression(Expression expression) {\r
+ logger.debug("Adding expression [" + expression + "] to " + this.getName() + " ("+this+")");\r
+ this.expressions.put(expression.toString(),expression);\r
+ }\r
+ \r
+ public void removeExpression(Expression expression) {\r
+ this.expressions.remove(expression.toString());\r
+ }\r
+ \r
+ \r
+ public boolean hasOperator() {\r
+ return operator != null;\r
+ }\r
+ \r
+ public String getEncodedQueryString () {\r
+ try {\r
+ return name + operator + URLEncoder.encode(getValueWithExpressions(),"UTF-8");\r
+ } catch (UnsupportedEncodingException e) {\r
+ e.printStackTrace();\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ public String getSimpleValue() { \r
+ return value; \r
+ }\r
+ \r
+ public String getValueWithExpressions () {\r
+ StringBuilder completeValue = new StringBuilder((value==null ? "" : value)); \r
+ for (String key : expressions.keySet()) { \r
+ completeValue.append(" and " + expressions.get(key));\r
+ }\r
+ return completeValue.toString();\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public boolean equals (Object otherParameter) {\r
+ return\r
+ ((otherParameter instanceof CommandParameter)\r
+ && this.getValueWithExpressions().equals(((CommandParameter) otherParameter).getValueWithExpressions()));\r
+ }\r
+ \r
+ @Override\r
+ public int hashCode () {\r
+ return getValueWithExpressions().hashCode();\r
+ }\r
+ \r
+ public String toString() {\r
+ return getValueWithExpressions();\r
+ }\r
+ \r
+ public CommandParameter copy() {\r
+ CommandParameter newParam = new CommandParameter(name);\r
+ newParam.value = this.value;\r
+ newParam.operator = this.operator;\r
+ for (String key : expressions.keySet()) {\r
+ newParam.addExpression(expressions.get(key).copy()); \r
+ }\r
+ return newParam;\r
+ }\r
+ \r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class InitCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = -4915976465898889987L;\r
+\r
+ public InitCommand(StateManager stateMgr) {\r
+ super("init",stateMgr);\r
+ }\r
+ \r
+ public void setClear(String clear) { \r
+ }\r
+ \r
+ public void setService(String serviceId) { \r
+ }\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import java.io.Serializable;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class Pazpar2Command implements Serializable {\r
+ \r
+ private static Logger logger = Logger.getLogger(Pazpar2Command.class);\r
+ private static final long serialVersionUID = -6825491856480675917L; \r
+ private String name = "";\r
+ protected Map<String,CommandParameter> parameters = new HashMap<String,CommandParameter>();\r
+ \r
+ StateManager stateMgr;\r
+ \r
+ public Pazpar2Command (String name, StateManager stateMgr) {\r
+ this.name = name;\r
+ this.stateMgr = stateMgr;\r
+ }\r
+ \r
+ public Pazpar2Command copy () {\r
+ Pazpar2Command newCommand = new Pazpar2Command(name,stateMgr);\r
+ for (String parameterName : parameters.keySet()) {\r
+ newCommand.setParameterSilently(parameters.get(parameterName).copy()); \r
+ } \r
+ return newCommand;\r
+ }\r
+ \r
+ public String getName() {\r
+ return name;\r
+ }\r
+ \r
+ public void setParameter (CommandParameter parameter) {\r
+ logger.debug("Setting parameter " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName());\r
+ parameters.put(parameter.getName(),parameter);\r
+ stateMgr.checkIn(this);\r
+ }\r
+ \r
+ public void setParameters (CommandParameter... params) {\r
+ for (CommandParameter param : params) {\r
+ logger.debug("Setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName());\r
+ parameters.put(param.getName(),param);\r
+ }\r
+ stateMgr.checkIn(this);\r
+ }\r
+ \r
+ \r
+ public void setParameterSilently (CommandParameter parameter) {\r
+ logger.debug("Setting parameter silently " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName());\r
+ parameters.put(parameter.getName(),parameter); \r
+ }\r
+ \r
+ \r
+ public CommandParameter getParameter (String name) {\r
+ return parameters.get(name);\r
+ }\r
+ \r
+ public void removeParameter (String name) {\r
+ parameters.remove(name);\r
+ stateMgr.checkIn(this);\r
+ }\r
+ \r
+ public void removeParameters() {\r
+ parameters = new HashMap<String,CommandParameter>();\r
+ stateMgr.checkIn(this);\r
+ }\r
+ \r
+ public boolean hasParameters () {\r
+ return (parameters.keySet().size()>0);\r
+ }\r
+ \r
+ public boolean hasParameterSet(String parameterName) {\r
+ return (parameters.get(parameterName) != null);\r
+ }\r
+ \r
+ public String getEncodedQueryString () {\r
+ StringBuilder queryString = new StringBuilder("command="+name);\r
+ for (CommandParameter parameter : parameters.values()) {\r
+ queryString.append("&"+parameter.getEncodedQueryString()); \r
+ }\r
+ return queryString.toString();\r
+ } \r
+ \r
+ public String getValueWithExpressions() { \r
+ StringBuilder value = new StringBuilder("");\r
+ for (CommandParameter parameter : parameters.values()) {\r
+ value.append("&" + parameter.getName() + parameter.operator + parameter.getValueWithExpressions()); \r
+ }\r
+ return value.toString();\r
+ }\r
+ \r
+ @Override\r
+ public boolean equals (Object otherCommand) {\r
+ return\r
+ ((otherCommand instanceof Pazpar2Command)\r
+ && this.getValueWithExpressions().equals(((Pazpar2Command) otherCommand).getValueWithExpressions()));\r
+ }\r
+ \r
+ @Override\r
+ public int hashCode () {\r
+ return getValueWithExpressions().hashCode();\r
+ }\r
+ \r
+ public String toString () {\r
+ return parameters.toString();\r
+ }\r
+ \r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import java.io.Serializable;\r
+\r
+import javax.annotation.PostConstruct;\r
+import javax.enterprise.context.SessionScoped;\r
+import javax.inject.Inject;\r
+import javax.inject.Named;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+import com.indexdata.pz2utils4jsf.utils.Utils;\r
+\r
+@Named("req") @SessionScoped\r
+public class Pazpar2Commands implements Serializable {\r
+\r
+ private static final long serialVersionUID = -5172466320351302413L;\r
+ private static Logger logger = Logger.getLogger(Pazpar2Commands.class);\r
+\r
+ public static final String INIT = "init";\r
+ public static final String PING = "ping";\r
+ public static final String SETTINGS = "settings";\r
+ public static final String SEARCH = "search";\r
+ public static final String STAT = "stat";\r
+ public static final String SHOW = "show";\r
+ public static final String RECORD = "record";\r
+ public static final String TERMLIST = "termlist";\r
+ public static final String BYTARGET = "bytarget";\r
+ \r
+ @Inject StateManager stateMgr; \r
+ \r
+ public Pazpar2Commands() {\r
+ logger.info("Initializing Pazpar2Commands [" + Utils.objectId(this) + "]");\r
+ }\r
+ \r
+ @PostConstruct\r
+ public void postConstruct() {\r
+ logger.info("in post-construct stateMgr is " + stateMgr);\r
+ }\r
+ \r
+ public InitCommand getInit() {\r
+ return (InitCommand) (stateMgr.checkOut(INIT));\r
+ }\r
+ \r
+ public PingCommand getPing() {\r
+ return (PingCommand) (stateMgr.checkOut(PING));\r
+ }\r
+ \r
+ public SettingsCommand getSettings() {\r
+ return (SettingsCommand) (stateMgr.checkOut(SETTINGS));\r
+ }\r
+\r
+ public SearchCommand getSearch() {\r
+ return (SearchCommand) (stateMgr.checkOut(SEARCH));\r
+ }\r
+\r
+ public StatCommand getStat() {\r
+ return (StatCommand) (stateMgr.checkOut(STAT));\r
+ }\r
+ \r
+ public ShowCommand getShow() {\r
+ return (ShowCommand) (stateMgr.checkOut(SHOW));\r
+ }\r
+ \r
+ public RecordCommand getRecord() {\r
+ return (RecordCommand) (stateMgr.checkOut(RECORD));\r
+ }\r
+ \r
+ public TermlistCommand getTermlist() {\r
+ return (TermlistCommand) (stateMgr.checkOut(TERMLIST));\r
+ }\r
+ \r
+ public BytargetCommand getBytarget() {\r
+ return (BytargetCommand) (stateMgr.checkOut(BYTARGET));\r
+ }\r
+ \r
+ public Pazpar2Command getCommand(String name) {\r
+ return stateMgr.checkOut(name);\r
+ }\r
+ \r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class PingCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = 8876721711326535847L;\r
+\r
+ public PingCommand(StateManager stateMgr) {\r
+ super("ping",stateMgr); \r
+ }\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class RecordCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = 2817539422114569506L;\r
+\r
+ public RecordCommand(StateManager stateMgr) {\r
+ super("record",stateMgr);\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import javax.enterprise.context.SessionScoped;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+@SessionScoped\r
+public class SearchCommand extends Pazpar2Command {\r
+ \r
+ private static final long serialVersionUID = -1888520867838597236L;\r
+ private static Logger logger = Logger.getLogger(SearchCommand.class);\r
+ \r
+ public SearchCommand(StateManager stateMgr) {\r
+ super("search",stateMgr);\r
+ }\r
+ \r
+ public void setSession (String sessionId) {\r
+ setParameter(new CommandParameter("session","=",sessionId));\r
+ }\r
+ \r
+ public void setQuery(String query) {\r
+ logger.info("writing query: " + query);\r
+ setParameter(new CommandParameter("query","=",query));\r
+ }\r
+ \r
+ public String getQuery () {\r
+ logger.info("retrieving query");\r
+ return getParameter("query") == null ? null : getParameter("query").getValueWithExpressions();\r
+ }\r
+ \r
+ public void setFilter(String filterExpression) {\r
+ setParameter(new CommandParameter("filter","=",filterExpression));\r
+ }\r
+ \r
+ public String getFilter() {\r
+ return getParameter("filter") == null ? null : getParameter("filter").getValueWithExpressions();\r
+ }\r
+\r
+ \r
+ public void setLimit (String limit) {\r
+ \r
+ }\r
+ \r
+ public void addFilter(String filterExpression) {\r
+ if (hasParameterSet("filter")) {\r
+ setFilter(filterExpression);\r
+ } else {\r
+ //TODO\r
+ getParameter("filter");\r
+ }\r
+ }\r
+ \r
+ public void removeFilters () {\r
+ \r
+ }\r
+ \r
+ public void removeFilter(String filterExpression) {\r
+ \r
+ }\r
+ \r
+ public SearchCommand copy () {\r
+ SearchCommand newCommand = new SearchCommand(stateMgr);\r
+ for (String parameterName : parameters.keySet()) {\r
+ newCommand.setParameterSilently(parameters.get(parameterName).copy()); \r
+ } \r
+ return newCommand;\r
+ }\r
+\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class SettingsCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = 2291179325470387102L;\r
+\r
+ public SettingsCommand(StateManager stateMgr) {\r
+ super("settings",stateMgr);\r
+ // TODO Auto-generated constructor stub\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class ShowCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = -8242768313266051307L;\r
+\r
+ public ShowCommand(StateManager stateMgr) {\r
+ super("show",stateMgr);\r
+ }\r
+\r
+ public void setSort (String sort) {\r
+ setParameter(new CommandParameter("sort","=",sort));\r
+ }\r
+ \r
+ public String getSort () {\r
+ return getParameter("sort") != null ? getParameter("sort").value : "relevance";\r
+ }\r
+ \r
+ public void setPageSize (String perPageOption) { \r
+ setParameters(new CommandParameter("num","=",perPageOption),\r
+ new CommandParameter("start","=",0));\r
+ }\r
+ \r
+ public String getPageSize () {\r
+ return getParameter("num") != null ? getParameter("num").value : "20";\r
+ }\r
+ \r
+ public ShowCommand copy () {\r
+ ShowCommand newCommand = new ShowCommand(stateMgr);\r
+ for (String parameterName : parameters.keySet()) {\r
+ newCommand.setParameterSilently(parameters.get(parameterName).copy()); \r
+ } \r
+ return newCommand;\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class StatCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = 3980630346114157336L;\r
+\r
+ public StatCommand(StateManager stateMgr) {\r
+ super("stat",stateMgr);\r
+ }\r
+\r
+}\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.commands;\r
+\r
+import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager;\r
+\r
+public class TermlistCommand extends Pazpar2Command {\r
+\r
+ private static final long serialVersionUID = -7067878552863021727L;\r
+\r
+ public TermlistCommand(StateManager stateMgr) {\r
+ super("termlist",stateMgr);\r
+ }\r
+\r
+}\r
import com.indexdata.pz2utils4jsf.config.Configuration;\r
import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
-import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter;\r
import com.indexdata.pz2utils4jsf.pazpar2.CommandResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command;\r
import com.indexdata.pz2utils4jsf.pazpar2.SearchClient;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\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.utils.Utils;\r
try { \r
logger.info("Authenticating [" + user.getProperty("name") + "]");\r
this.user = (ServiceProxyUser) user;\r
- Pazpar2Command auth = new Pazpar2Command("auth");\r
+ Pazpar2Command auth = new Pazpar2Command("auth",null);\r
auth.setParameter(new CommandParameter("action","=","login"));\r
auth.setParameter(new CommandParameter("username","=",user.getProperty("name")));\r
auth.setParameter(new CommandParameter("password","=",user.getProperty("password")));\r
\r
public boolean checkAuthentication () {\r
try {\r
- Pazpar2Command check = new Pazpar2Command("auth");\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
\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter;\r
+import com.indexdata.pz2utils4jsf.pazpar2.ForServiceProxy;\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\r
public class ServiceProxySession extends Pz2Session implements ServiceProxyInterface {\r
\r
private ServiceProxyUser user; \r
package com.indexdata.pz2utils4jsf.pazpar2.state;\r
\r
-import java.util.Arrays;\r
import java.util.HashMap;\r
import java.util.Map;\r
\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command;\r
-\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.BytargetCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.InitCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.PingCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.RecordCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.SearchCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.SettingsCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.ShowCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.StatCommand;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.TermlistCommand;\r
\r
+/**\r
+ * Holds a 'pazpar2 state', understood as a full set of pazpar2 commands and \r
+ * all their parameter settings at a given point in time.\r
+ * \r
+ * @author Niels Erik\r
+ *\r
+ */\r
public class Pazpar2State {\r
\r
String key = null;\r
Map<String,Pazpar2Command> commands = new HashMap<String,Pazpar2Command>();;\r
\r
- public Pazpar2State () { \r
- for (String command : Arrays.asList("init","ping","settings","search","stat","show","record","termlist","bytarget")) {\r
- commands.put(command, new Pazpar2Command(command));\r
- }\r
+ public Pazpar2State (StateManager mgr) {\r
+ commands.put(Pazpar2Commands.INIT, new InitCommand(mgr));\r
+ commands.put(Pazpar2Commands.PING, new PingCommand(mgr));\r
+ commands.put(Pazpar2Commands.SETTINGS, new SettingsCommand(mgr));\r
+ commands.put(Pazpar2Commands.SEARCH, new SearchCommand(mgr));\r
+ commands.put(Pazpar2Commands.STAT, new StatCommand(mgr));\r
+ commands.put(Pazpar2Commands.SHOW, new ShowCommand(mgr));\r
+ commands.put(Pazpar2Commands.RECORD, new RecordCommand(mgr));\r
+ commands.put(Pazpar2Commands.TERMLIST, new TermlistCommand(mgr));\r
+ commands.put(Pazpar2Commands.BYTARGET, new BytargetCommand(mgr)); \r
key = "#initial";\r
}\r
- \r
+ \r
/**\r
* Creates new state by cloning all commands of the provided state and \r
* then overriding one of them with the provided state changing command.\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.pazpar2.state;\r
+\r
+public interface StateListener {\r
+\r
+ public void stateUpdate(String commandName);\r
+ \r
+}\r
package com.indexdata.pz2utils4jsf.pazpar2.state;\r
\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.HashMap;\r
+import java.util.List;\r
import java.util.Map;\r
\r
+import javax.enterprise.context.SessionScoped;\r
+\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
+import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
-public class StateManager {\r
+@SessionScoped\r
+public class StateManager implements Serializable {\r
\r
+ private static final long serialVersionUID = 8152558351351730035L;\r
+\r
Map<String, Pazpar2State> states = new HashMap<String, Pazpar2State>();\r
String currentKey = "";\r
+ private static List<String> allCommands = new ArrayList<String>(Arrays.asList("init","ping","settings","search","stat","show","record","termlist","bytarget"));\r
Map<String,Boolean> pendingStateChanges = new HashMap<String,Boolean>();\r
private static Logger logger = Logger.getLogger(StateManager.class);\r
+ private List<StateListener> listeners = new ArrayList<StateListener>();\r
\r
public StateManager () {\r
- Pazpar2State initialState = new Pazpar2State();\r
+ logger.info("Initializing a Pazpar2 state manager [" + Utils.objectId(this) + "]");\r
+ Pazpar2State initialState = new Pazpar2State(this);\r
states.put(initialState.getKey(), initialState);\r
currentKey = initialState.getKey();\r
- for (String command : Pazpar2Command.allCommands) {\r
+ for (String command : allCommands) {\r
pendingStateChanges.put(command, new Boolean(false));\r
}\r
-\r
+ }\r
+ \r
+ public void addStateListener(StateListener listener) {\r
+ listeners.add(listener);\r
+ }\r
+ \r
+ public void removeStateListener (StateListener listener) {\r
+ listeners.remove(listener);\r
+ }\r
+ \r
+ private void updateListeners (String command) {\r
+ for (StateListener lsnr : listeners) {\r
+ lsnr.stateUpdate(command);\r
+ }\r
}\r
\r
/**\r
*/\r
public void checkIn(Pazpar2Command command) {\r
if (getCurrentState().stateMutating(command)) {\r
+ logger.debug("State changed by: " + command.getName());\r
Pazpar2State state = new Pazpar2State(getCurrentState(),command);\r
states.put(state.getKey(), state);\r
currentKey = state.getKey();\r
* @return Copy this state's instance of the given command\r
*/\r
public Pazpar2Command checkOut (String commandName) {\r
+ logger.info("Getting " + commandName + " from state manager.");\r
return getCurrentState().getCommand(commandName).copy();\r
}\r
\r
public Pazpar2State getCurrentState () {\r
return states.get(currentKey);\r
}\r
- \r
+ \r
/**\r
* Changes the current state key. Invoked from the UI to have the state \r
* manager switch to another state than the current one. \r
}\r
\r
/**\r
- * Sets a pending-state-change flag for the given command. Used by\r
- * the beans to decide whether, say, a search should be executed before\r
- * doing the next show. \r
+ * Sets a pending-state-change flag for the given command and notifies\r
+ * registered listeners. \r
* \r
- * It is up to the client to set and reset this flag since the state\r
- * manager is not otherwise informed about actual request activities \r
- * (only about the definition of commands to be executed)\r
+ * It is up to the listener to reset the flag as needed.\r
* \r
* @param command\r
* @param bool\r
*/\r
public void hasPendingStateChange(String command, boolean bool) {\r
pendingStateChanges.put(command, new Boolean(bool));\r
+ if (bool) {\r
+ logger.debug("Updating listeners with state change from " + command);\r
+ updateListeners(command);\r
+ }\r
}\r
\r
/**\r