From 7b71381e71db35eed511606e80c0d3e18cab4d2b Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Sun, 14 Apr 2013 16:19:29 -0400 Subject: [PATCH] Adds more parameters to commands To extend the Pazpar2 protocol support in form of named methods. It's possible, though, to set 'unsupported' parameters with the generic setParameter("command","param",param) method --- .../indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java | 3 +- .../pz2utils4jsf/pazpar2/commands/InitCommand.java | 14 ++- .../pazpar2/commands/Pazpar2Command.java | 9 ++ .../pz2utils4jsf/pazpar2/commands/PingCommand.java | 2 +- .../pazpar2/commands/RecordCommand.java | 4 +- .../pazpar2/commands/SearchCommand.java | 103 ++++++++++++-------- .../pz2utils4jsf/pazpar2/commands/ShowCommand.java | 9 ++ 7 files changed, 99 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index ad684b3..65706a9 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -20,7 +20,6 @@ import com.indexdata.pz2utils4jsf.errors.ConfigurationException; import com.indexdata.pz2utils4jsf.errors.ErrorHelper; import com.indexdata.pz2utils4jsf.errors.ErrorInterface; import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter; -import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandReadOnly; import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands; import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData; import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseParser; @@ -169,7 +168,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { pzresp.put("record", new RecordResponse()); return ""; } else { - pzreq.getRecord().setRecordId(recId); + pzreq.getRecord().setId(recId); return doCommand("record"); } } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/InitCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/InitCommand.java index 37fd8f1..09e1bee 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/InitCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/InitCommand.java @@ -10,10 +10,22 @@ public class InitCommand extends Pazpar2Command { super("init",stateMgr); } - public void setClear(String clear) { + public void setClear(String clear) { + setParameter(new CommandParameter("clear","=",clear)); } public void setService(String serviceId) { + setParameter(new CommandParameter("service","=",serviceId)); + } + + @Override + public void setSession (String sessionId) { + throw new UnsupportedOperationException("Cannot set session id on init command"); + } + + @Override + public String getSession () { + throw new UnsupportedOperationException("Cannot set or get session id on init command"); } } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java index e0680c7..296f2ef 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java @@ -125,6 +125,15 @@ public class Pazpar2Command implements CommandReadOnly, Serializable { return getParameter(parameterName).getEncodedQueryString(); } + public void setSession (String sessionId) { + setParameter(new CommandParameter("session","=",sessionId)); + } + + public String getSession() { + return getParameterValue("session"); + } + + } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/PingCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/PingCommand.java index a182db1..e7eda38 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/PingCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/PingCommand.java @@ -9,5 +9,5 @@ public class PingCommand extends Pazpar2Command { public PingCommand(StateManager stateMgr) { super("ping",stateMgr); } - + } 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 09e370c..a54433d 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/RecordCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/RecordCommand.java @@ -10,11 +10,11 @@ public class RecordCommand extends Pazpar2Command { super("record",stateMgr); } - public void setRecordId(String recId) { + public void setId(String recId) { setParameter(new CommandParameter("id","=",recId)); } - public String getRecordId () { + public String getId () { return getParameterValue("id"); } 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 1d2cb2b..4c6d9c5 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/SearchCommand.java @@ -16,11 +16,7 @@ public class SearchCommand extends Pazpar2Command { public SearchCommand(StateManager stateMgr) { super("search",stateMgr); } - - public void setSession (String sessionId) { - setParameter(new CommandParameter("session","=",sessionId)); - } - + public void setQuery(String query) { setParameter(new CommandParameter("query","=",query)); } @@ -29,6 +25,69 @@ public class SearchCommand extends Pazpar2Command { return getParameter("query") == null ? null : getParameter("query").getValueWithExpressions(); } + public void setFilter(String filterExpression) { + setParameter(new CommandParameter("filter","=",filterExpression)); + } + + public String getFilter() { + return getParameter("filter") == null ? null : getParameter("filter").getValueWithExpressions(); + } + + public void addFilter(String filterExpression) { + // TODO: implement + if (hasParameterSet("filter")) { + setFilter(filterExpression); + } else { + getParameter("filter"); + } + throw new UnsupportedOperationException("removeFilter(filterExpression) yet to be implemented."); + } + + public void removeFilters () { + removeParameter("filter"); + } + + public void removeFilter(String filterExpression) { + // TODO: implement + throw new UnsupportedOperationException("removeFilter(filterExpression) yet to be implemented."); + } + + public boolean hasFilter () { + return getFilter().length()>0; + } + + public void setLimit (String limitExpression) { + setParameter(new CommandParameter("limit","=",limitExpression)); + } + + public String getLimit () { + return getParameterValue("limit"); + } + + public void setStartrecs (String startrecs) { + setParameter(new CommandParameter("startrecs","=",startrecs)); + } + + public String getStartrecs () { + return getParameterValue("startrecs"); + } + + public void setMaxrecs (String maxrecs) { + setParameter(new CommandParameter("maxrecs","=",maxrecs)); + } + + public String getMaxrecs () { + return getParameterValue("maxrecs"); + } + + public void setSort () { + setParameter(new CommandParameter("sort","=","sort")); + } + + public String getSort () { + return getParameterValue("sort"); + } + /** * Sets a facet, in CQL, to restrict the current results, * then executes the search @@ -75,17 +134,6 @@ public class SearchCommand extends Pazpar2Command { } } - public void setFilter(String filterExpression) { - setParameter(new CommandParameter("filter","=",filterExpression)); - } - - 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, @@ -141,28 +189,6 @@ public class SearchCommand extends Pazpar2Command { protected boolean hasSingleTargetFilter(SingleTargetFilter targetFilter) { return hasSingleTargetFilter() && targetFilter.equals(this.singleTargetFilter); } - - - public void setLimit (String limit) { - // TODO - } - - public void addFilter(String filterExpression) { - if (hasParameterSet("filter")) { - setFilter(filterExpression); - } else { - //TODO - getParameter("filter"); - } - } - - public void removeFilters () { - - } - - public void removeFilter(String filterExpression) { - - } public SearchCommand copy () { SearchCommand newCommand = new SearchCommand(stateMgr); @@ -173,5 +199,4 @@ public class SearchCommand extends Pazpar2Command { return newCommand; } - } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java index 6522b08..12347c6 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/ShowCommand.java @@ -77,6 +77,15 @@ public class ShowCommand extends Pazpar2Command { public int getStart() { return getParameter("start") != null ? Integer.parseInt(getParameter("start").value) : 0; } + + public void setNum (int num) { + setParameter(new CommandParameter("num","=",num)); + } + + public int getNum () { + return getParameter("num") != null ? Integer.parseInt(getParameter("num").value) : 0; + } + public ShowCommand copy () { -- 1.7.10.4