From 46a090cd2f2e2069c684084eeded75c9d5ed71f5 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Sat, 13 Apr 2013 15:53:44 -0400 Subject: [PATCH] Moves filter settings from pz2 bean to search command --- .../indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java | 37 ----------- .../pz2utils4jsf/pazpar2/Pz2Interface.java | 42 +----------- .../indexdata/pz2utils4jsf/pazpar2/Pz2Session.java | 42 ------------ .../pazpar2/commands/RecordCommand.java | 5 +- .../pazpar2/commands/SearchCommand.java | 68 +++++++++++++++++++- 5 files changed, 68 insertions(+), 126 deletions(-) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index fe63d6e..845f3d9 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -77,43 +77,6 @@ public class Pz2Bean implements Pz2Interface, Serializable { public String update(String commands) { return pz2.update(commands); } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setTargetFilter(java.lang.String, java.lang.String) - */ - public void setSingleTargetFilter(String targetId, String targetName) { - pz2.setSingleTargetFilter(targetId, targetName); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getTargetFilter() - */ - public SingleTargetFilter getSingleTargetFilter() { - return pz2.getSingleTargetFilter(); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#removeTargetFilter() - */ - public void removeSingleTargetFilter () { - pz2.removeSingleTargetFilter(); - } - - /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#hasTargetFilter() - */ - public boolean hasSingleTargetFilter() { - return pz2.hasSingleTargetFilter(); - } - - - public String getFilter () { - return pz2.getFilter(); - } - - public void setFilter (String filterExpression) { - pz2.setFilter(filterExpression); - } /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#toggleRecord(java.lang.String) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java index d33b114..0c509fc 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java @@ -50,47 +50,7 @@ public interface Pz2Interface extends Serializable { * */ public String update (String commands); - - - public void setFilter(String filterExpression); - - public String getFilter(); - - - /** - * Adds a single target filter to restrict the current query by, - * then executes the current search. - * - * This is a special case of the general setFilter function, - * allowing to associate a descriptive target name with the - * filter expression for display in UI. - * - * @param targetId pazpar2's ID for the target to limit by - * @param targetName a descriptive name for the target - */ - public void setSingleTargetFilter (String targetId, String targetName); - - /** - * Removes the current target filter from the search - * - */ - public void removeSingleTargetFilter (); - - /** - * - * @return The target filter set on the current search command - */ - public SingleTargetFilter getSingleTargetFilter(); - - /** - * Resolves if the current search command has a target filter - to - * be used by the UI for conditional rendering of target filter info. - * - * @return true if the current search command is limited by a target - * filter - */ - public boolean hasSingleTargetFilter(); - + /** * Will retrieve or remove the record with the given recid from memory. * diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index 654f3c8..7c0cc86 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -160,30 +160,6 @@ public class Pz2Session implements Pz2Interface, StateListener { } - public void setSingleTargetFilter (String targetId, String targetName) { - if (hasSingleTargetFilter(new SingleTargetFilter(targetId,targetName))) { - logger.debug("Already using target filter " + this.singleTargetFilter.getFilterExpression()); - } else { - this.singleTargetFilter = new SingleTargetFilter(targetId,targetName); - setCommandParameter("search",new CommandParameter("filter","=",this.singleTargetFilter.getFilterExpression())); - doSearch(); - } - } - - public SingleTargetFilter getSingleTargetFilter () { - return singleTargetFilter; - } - - public void removeSingleTargetFilter () { - logger.debug("Removing target filter " + singleTargetFilter.getFilterExpression()); - this.singleTargetFilter = null; - removeCommandParameter("search","filter"); - doSearch(); - } - - public boolean hasSingleTargetFilter() { - return singleTargetFilter != null; - } public String toggleRecord (String recId) { if (hasRecord(recId)) { @@ -287,11 +263,6 @@ public class Pz2Session implements Pz2Interface, StateListener { error.setErrorHelper(errorHelper); return error; } - - - protected boolean hasSingleTargetFilter(SingleTargetFilter targetFilter) { - return hasSingleTargetFilter() && targetFilter.equals(this.singleTargetFilter); - } protected boolean hasQuery() { return req.getSearch().getParameter("query") != null && req.getSearch().getParameter("query").getValueWithExpressions().length()>0; @@ -437,19 +408,6 @@ public class Pz2Session implements Pz2Interface, StateListener { dataObjects.put("search", new SearchResponse()); } - @Override - public void setFilter(String filterExpression) { - logger.debug("Setting filter to " + filterExpression); - setCommandParameter("search",new CommandParameter("filter","=",filterExpression)); - } - - public String getFilter() { - return getCommandParameterValue("search", "filter", ""); - } - - public boolean hasFilter () { - return getFilter().length()>0; - } @Override public void stateUpdated(String commandName) { diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/RecordCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/RecordCommand.java index 086cfa8..656f73f 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/RecordCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/RecordCommand.java @@ -17,6 +17,8 @@ public class RecordCommand extends Pazpar2Command { public String getRecordId () { return getParameterValue("id"); } + + @Override public RecordCommand copy () { @@ -26,7 +28,4 @@ public class RecordCommand extends Pazpar2Command { } return newCommand; } - - - } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java index a7f8168..6e3f500 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java @@ -5,6 +5,7 @@ import javax.enterprise.context.SessionScoped; import org.apache.log4j.Logger; import com.indexdata.pz2utils4jsf.pazpar2.Expression; +import com.indexdata.pz2utils4jsf.pazpar2.SingleTargetFilter; import com.indexdata.pz2utils4jsf.pazpar2.state.StateManager; @SessionScoped @@ -12,6 +13,7 @@ public class SearchCommand extends Pazpar2Command { private static final long serialVersionUID = -1888520867838597236L; private static Logger logger = Logger.getLogger(SearchCommand.class); + private SingleTargetFilter singleTargetFilter = null; public SearchCommand(StateManager stateMgr) { super("search",stateMgr); @@ -82,10 +84,69 @@ public class SearchCommand extends Pazpar2Command { public String getFilter() { return getParameter("filter") == null ? null : getParameter("filter").getValueWithExpressions(); } + + public boolean hasFilter () { + return getFilter().length()>0; + } + + /** + * Adds a single target filter to restrict the current query by, + * then executes the current search. + * + * This is a special case of the general setFilter function, + * allowing to associate a descriptive target name with the + * filter expression for display in UI. + * + * @param targetId pazpar2's ID for the target to limit by + * @param targetName a descriptive name for the target + */ + public void setSingleTargetFilter (String targetId, String targetName) { + if (hasSingleTargetFilter(new SingleTargetFilter(targetId,targetName))) { + logger.debug("Already using target filter " + this.singleTargetFilter.getFilterExpression()); + } else { + this.singleTargetFilter = new SingleTargetFilter(targetId,targetName); + setParameter(new CommandParameter("filter","=",this.singleTargetFilter.getFilterExpression())); + } + } + + public SingleTargetFilter getSingleTargetFilter () { + logger.debug("request to get the current single target filter"); + return singleTargetFilter; + } + + /** + * Removes the current target filter from the search + * + */ + public void removeSingleTargetFilter () { + logger.debug("Removing target filter " + singleTargetFilter.getFilterExpression()); + this.singleTargetFilter = null; + removeParameter("filter"); + } + + /** + * + * @return The target filter set on the current search command + */ + public boolean hasSingleTargetFilter() { + logger.debug("Checking if a single target filter is set: " + (singleTargetFilter != null)); + return singleTargetFilter != null; + } + + /** + * Resolves if the current search command has a target filter - to + * be used by the UI for conditional rendering of target filter info. + * + * @return true if the current search command is limited by a target + * filter + */ + protected boolean hasSingleTargetFilter(SingleTargetFilter targetFilter) { + return hasSingleTargetFilter() && targetFilter.equals(this.singleTargetFilter); + } public void setLimit (String limit) { - + // TODO } public void addFilter(String filterExpression) { @@ -104,12 +165,13 @@ public class SearchCommand extends Pazpar2Command { public void removeFilter(String filterExpression) { } - + public SearchCommand copy () { SearchCommand newCommand = new SearchCommand(stateMgr); for (String parameterName : parameters.keySet()) { newCommand.setParameterSilently(parameters.get(parameterName).copy()); - } + } + newCommand.singleTargetFilter = this.singleTargetFilter; return newCommand; } -- 1.7.10.4