From 33338bd223ec711264392b7768d89d0f3fbce677 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Thu, 4 Apr 2013 15:56:23 -0400 Subject: [PATCH] Adds filter attribute, renames target id filter attribute --- .../indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java | 34 +++++++++----- .../pz2utils4jsf/pazpar2/Pz2Interface.java | 24 +++++++--- .../pz2utils4jsf/pazpar2/Pz2ProxyBean.java | 25 ++++++++++- .../indexdata/pz2utils4jsf/pazpar2/Pz2Session.java | 47 +++++++++++++------- .../pz2utils4jsf/pazpar2/SingleTargetFilter.java | 47 ++++++++++++++++++++ .../pz2utils4jsf/pazpar2/TargetFilter.java | 47 -------------------- .../pazpar2/sp/ServiceProxySession.java | 17 ++++--- 7 files changed, 152 insertions(+), 89 deletions(-) create mode 100644 src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SingleTargetFilter.java delete mode 100644 src/main/java/com/indexdata/pz2utils4jsf/pazpar2/TargetFilter.java diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index 277876b..70dde92 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -115,30 +115,40 @@ public class Pz2Bean implements Pz2Interface, Serializable { /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#setTargetFilter(java.lang.String, java.lang.String) */ - public void setTargetFilter(String targetId, String targetName) { - pz2.setTargetFilter(targetId, targetName); + public void setSingleTargetFilter(String targetId, String targetName) { + pz2.setSingleTargetFilter(targetId, targetName); } /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#removeTargetFilter() + * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getTargetFilter() */ - public void removeTargetFilter () { - pz2.removeTargetFilter(); + public SingleTargetFilter getSingleTargetFilter() { + return pz2.getSingleTargetFilter(); } - + /* (non-Javadoc) - * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#getTargetFilter() + * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#removeTargetFilter() */ - public TargetFilter getTargetFilter() { - return pz2.getTargetFilter(); + public void removeSingleTargetFilter () { + pz2.removeSingleTargetFilter(); } - + /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#hasTargetFilter() */ - public boolean hasTargetFilter() { - return pz2.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#setSort(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 ef820da..8a59cfe 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java @@ -97,26 +97,36 @@ public interface Pz2Interface extends Serializable { */ public void setFacetOnQuery(String facetKey, String term); + + public void setFilter(String filterExpression); + + public String getFilter(); + + /** - * Adds a target filter to limit the current query by, then - * executes the current search. + * 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 setTargetFilter (String targetId, String targetName); + public void setSingleTargetFilter (String targetId, String targetName); /** * Removes the current target filter from the search * */ - public void removeTargetFilter (); + public void removeSingleTargetFilter (); /** * * @return The target filter set on the current search command */ - public TargetFilter getTargetFilter(); + public SingleTargetFilter getSingleTargetFilter(); /** * Resolves if the current search command has a target filter - to @@ -125,8 +135,8 @@ public interface Pz2Interface extends Serializable { * @return true if the current search command is limited by a target * filter */ - public boolean hasTargetFilter(); - + public boolean hasSingleTargetFilter(); + /** * Sets the ordering of records (hits) in the 'show' display object */ diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java index f8d8d08..72dbccb 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2ProxyBean.java @@ -11,6 +11,7 @@ import javax.inject.Named; import org.apache.log4j.Logger; +import com.indexdata.pz2utils4jsf.config.Configuration; import com.indexdata.pz2utils4jsf.config.ConfigurationReader; import com.indexdata.pz2utils4jsf.pazpar2.sp.ServiceProxyClient; import com.indexdata.pz2utils4jsf.pazpar2.sp.ServiceProxyInterface; @@ -50,6 +51,7 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface { @Override public void setInitFileName(String fileName) { + logger.info("Setting init file name: " + fileName); session().setInitFileName(fileName); } @@ -57,15 +59,26 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface { public String getInitFileName() { return session().getInitFileName(); } + + public void setAceFilter (String filterExpression) { + session().setAceFilter(filterExpression); + } + + public String getAceFilter () { + return session().getAceFilter(); + } @Override public String postInit() throws UnsupportedEncodingException, IOException { - return session().postInit(); + logger.info("Posting init: " + System.currentTimeMillis()); + session().postInit(); + return ""; } @Override public void setServiceProxyUrl(String url) { - session().setServiceProxyUrl(url); + logger.info("Setting Service Proxy url: " + url); + session().setServiceProxyUrl(url); } @Override @@ -81,5 +94,13 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface { public String getInitResponse() { return session().getInitResponse(); } + + public Configuration getClientConfiguration() { + return session().client().getConfiguration(); + } + + public String getInitDocPath () { + return session().client().getConfiguration().get("INIT_DOC_PATH"); + } } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index a4b1b68..ed4c088 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -42,7 +42,7 @@ public class Pz2Session implements Pz2Interface { protected List configurationErrors = null; protected SearchClient searchClient = null; - protected TargetFilter targetFilter = null; + protected SingleTargetFilter singleTargetFilter = null; protected ResultsPager pager = null; public Pz2Session () { @@ -78,6 +78,7 @@ public class Pz2Session implements Pz2Interface { public void doSearch() { queryStates.hasPendingStateChange("search",false); resetDataObjects(); + removeCommand("record"); setCommandParameter("show",new CommandParameter("start","=",0)); logger.debug(Utils.objectId(this) + " is searching using "+getCommand("search").getParameter("query").getEncodedQueryString()); doCommand("search"); @@ -173,29 +174,29 @@ public class Pz2Session implements Pz2Interface { doSearch(); } - public void setTargetFilter (String targetId, String targetName) { - if (hasTargetFilter(new TargetFilter(targetId,targetName))) { - logger.debug("Already using target filter " + this.targetFilter.getFilterExpression()); + public void setSingleTargetFilter (String targetId, String targetName) { + if (hasSingleTargetFilter(new SingleTargetFilter(targetId,targetName))) { + logger.debug("Already using target filter " + this.singleTargetFilter.getFilterExpression()); } else { - this.targetFilter = new TargetFilter(targetId,targetName); - setCommandParameter("search",new CommandParameter("filter","=",this.targetFilter.getFilterExpression())); + this.singleTargetFilter = new SingleTargetFilter(targetId,targetName); + setCommandParameter("search",new CommandParameter("filter","=",this.singleTargetFilter.getFilterExpression())); doSearch(); } } - public TargetFilter getTargetFilter () { - return targetFilter; + public SingleTargetFilter getSingleTargetFilter () { + return singleTargetFilter; } - public void removeTargetFilter () { - logger.debug("Removing target filter " + targetFilter.getFilterExpression()); - this.targetFilter = null; + public void removeSingleTargetFilter () { + logger.debug("Removing target filter " + singleTargetFilter.getFilterExpression()); + this.singleTargetFilter = null; removeCommandParameter("search","filter"); doSearch(); } - public boolean hasTargetFilter() { - return targetFilter != null; + public boolean hasSingleTargetFilter() { + return singleTargetFilter != null; } public void setSort (String sortOption) { @@ -347,8 +348,8 @@ public class Pz2Session implements Pz2Interface { } - protected boolean hasTargetFilter(TargetFilter targetFilter) { - return hasTargetFilter() && targetFilter.equals(this.targetFilter); + protected boolean hasSingleTargetFilter(SingleTargetFilter targetFilter) { + return hasSingleTargetFilter() && targetFilter.equals(this.singleTargetFilter); } protected boolean hasQuery() { @@ -379,7 +380,7 @@ public class Pz2Session implements Pz2Interface { protected void handleQueryStateChanges (String commands) { if (queryStates.hasPendingStateChange("search")) { - logger.debug("Found pending search change. Doing search before updating " + commands); + logger.debug("Found pending search change. Doing search before updating " + commands); doSearch(); } if (queryStates.hasPendingStateChange("record") && ! commands.equals("record")) { @@ -471,5 +472,19 @@ public class Pz2Session implements Pz2Interface { dataObjects.put("record", new RecordResponse()); 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 getCommandParameterValueSimple("search", "filter", ""); + } + + public boolean hasFilter () { + return getFilter().length()>0; + } } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SingleTargetFilter.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SingleTargetFilter.java new file mode 100644 index 0000000..7c0bcd8 --- /dev/null +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SingleTargetFilter.java @@ -0,0 +1,47 @@ +package com.indexdata.pz2utils4jsf.pazpar2; + +import java.io.Serializable; + +import com.indexdata.pz2utils4jsf.pazpar2.SingleTargetFilter; + +public class SingleTargetFilter implements Serializable { + + private static final long serialVersionUID = 2389085467202526537L; + + private String targetName; + private String targetId; + + public SingleTargetFilter (String targetId, String targetName) { + this.targetId = targetId; + this.targetName = targetName; + } + + public String getTargetName () { + return targetName; + } + + public String getTargetId () { + return targetId; + } + + public String getFilterExpression () { + return "pz:id="+targetId; + } + + @Override + public boolean equals(Object o) { + if (o instanceof SingleTargetFilter) { + return targetName.equals(((SingleTargetFilter) o).getTargetName()) && + targetId.equals(((SingleTargetFilter) o).getTargetId()); + } else { + return false; + } + } + + @Override + public int hashCode () { + return (targetId+targetName).hashCode(); + } + + +} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/TargetFilter.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/TargetFilter.java deleted file mode 100644 index f4d117c..0000000 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/TargetFilter.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.indexdata.pz2utils4jsf.pazpar2; - -import java.io.Serializable; - -import com.indexdata.pz2utils4jsf.pazpar2.TargetFilter; - -public class TargetFilter implements Serializable { - - private static final long serialVersionUID = 2389085467202526537L; - - private String targetName; - private String targetId; - - public TargetFilter (String targetId, String targetName) { - this.targetId = targetId; - this.targetName = targetName; - } - - public String getTargetName () { - return targetName; - } - - public String getTargetId () { - return targetId; - } - - public String getFilterExpression () { - return "pz:id="+targetId; - } - - @Override - public boolean equals(Object o) { - if (o instanceof TargetFilter) { - return targetName.equals(((TargetFilter) o).getTargetName()) && - targetId.equals(((TargetFilter) o).getTargetId()); - } else { - return false; - } - } - - @Override - public int hashCode () { - return (targetId+targetName).hashCode(); - } - - -} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java index e6c2a45..2a58af0 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java @@ -5,6 +5,7 @@ import java.io.UnsupportedEncodingException; import org.apache.log4j.Logger; +import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter; import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session; import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.ServiceProxyUser; import com.indexdata.pz2utils4jsf.utils.Utils; @@ -15,8 +16,8 @@ public class ServiceProxySession extends Pz2Session implements ServiceProxyInter private static final long serialVersionUID = -5770410029361522854L; private static Logger logger = Logger.getLogger(ServiceProxySession.class); private String initDocFileName = ""; - private String initDocResponse = ""; - + private String initDocResponse = ""; + public ServiceProxySession() { logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); } @@ -46,7 +47,7 @@ public class ServiceProxySession extends Pz2Session implements ServiceProxyInter } @Override - public String postInit() throws UnsupportedEncodingException, IOException { + public String postInit() throws UnsupportedEncodingException, IOException { String initDocPath = client().getInitDocPaths()[0]; logger.info("Paths: " + client().getInitDocPaths()); logger.info("Path: " + initDocPath); @@ -67,7 +68,7 @@ public class ServiceProxySession extends Pz2Session implements ServiceProxyInter return client().getServiceProxyUrl(); } - private ServiceProxyClient client () { + public ServiceProxyClient client () { return (ServiceProxyClient)searchClient; } @@ -76,6 +77,12 @@ public class ServiceProxySession extends Pz2Session implements ServiceProxyInter return initDocResponse; } + public void setAceFilter(String filterExpression) { + setCommandParameter("record",new CommandParameter("acefilter","=",filterExpression)); + } + + public String getAceFilter () { + return getCommandParameterValue("record","acefilter",""); + } - } -- 1.7.10.4