Clears info response when clearing init response
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / commands / SearchCommand.java
index f2c53da..0c8d745 100644 (file)
@@ -9,11 +9,12 @@ import javax.inject.Named;
 import org.apache.log4j.Logger;\r
 \r
 import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.SearchCommandSp;\r
 import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
 import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
 \r
 /**\r
- * Represents a Pazpar2 <code>search</code> command, can be accessed by <code>pzreq.search</code> \r
+ * <b><code>search</code></b> Pazpar2 command, referenced as: <code>pzreq.search</code> \r
  * \r
  * @author Niels Erik\r
  *\r
@@ -69,16 +70,20 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand
   /**\r
    * Sets the <code>filter</code> parameter. See Pazpar2 documentation for details.\r
    */  \r
-  public void setFilter(String filterExpression) {\r
-    if (filterExpression != null && filterExpression.length()>0) {\r
-      if (filterExpression.split("[=~]").length==1) {\r
-        removeFilters(filterExpression.split("[=~]")[0]);\r
-      } else if (filterExpression.split("[=~]").length==2) {\r
-        setParameter(new FilterParameter(new Expression(filterExpression)));\r
-      } else {\r
-        logger.error("Could not parse filter expression [" + filterExpression + "]");\r
+  public void setFilter(String compoundExpression) {\r
+    if (getParameter("filter") != null) removeParameterInState("filter");\r
+    if (compoundExpression != null && compoundExpression.length()>0) {      \r
+      // Split expression by commas that are not escaped with backslash\r
+      String[] subExpressions = compoundExpression.split("(?<!\\\\),");\r
+      for (int i=0; i<subExpressions.length; i++) {\r
+        if (i==0) {\r
+          setParameterInState(new FilterParameter(new Expression(subExpressions[i])));\r
+        } else {\r
+          addExpressionInState("filter",new Expression(subExpressions[i]));\r
+        }\r
       }\r
     }\r
+    checkInState(this);\r
   }\r
   \r
   /**\r
@@ -214,10 +219,20 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand
   /**\r
    * Sets the <code>limit</code> parameter. See Pazpar2 documentation for details.\r
    */  \r
-  public void setLimit (String limitExpression) {   \r
-    if (limitExpression != null && limitExpression.length()>0) {\r
-      setParameter(new LimitParameter(new Expression(limitExpression)));\r
+  public void setLimit (String compoundExpression) {\r
+    if (getParameter("limit") != null) removeParameterInState("limit");\r
+    if (compoundExpression != null && compoundExpression.length()>0) {      \r
+      // Split expression by commas that are not escaped with backslash\r
+      String[] subExpressions = compoundExpression.split("(?<!\\\\),");\r
+      for (int i=0; i<subExpressions.length; i++) {\r
+        if (i==0) {\r
+          setParameterInState(new LimitParameter(new Expression(subExpressions[i])));\r
+        } else {\r
+          addExpressionInState("limit",new Expression(subExpressions[i]));\r
+        }\r
+      }\r
     }\r
+    checkInState(this);\r
   }\r
   \r
   /**\r
@@ -231,7 +246,7 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand
    * Returns the <code>limit</code> parameter value.\r
    */\r
   public String getLimit () {\r
-    return getParameter("limit") == null ? null : ((FilterParameter)getParameter("limit")).getValueWithExpressions();    \r
+    return getParameter("limit") == null ? null : ((LimitParameter)getParameter("limit")).getValueWithExpressions();    \r
   }\r
     \r
   /**\r
@@ -276,7 +291,7 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand
   }\r
   \r
   /**\r
-   * Returns a list of limit expressions with fields that matches on of <code>expressionFields</code>\r
+   * Returns a list of limit expressions with fields that matches one of <code>expressionFields</code>\r
    * \r
    * @param expressionFields limit expressions to look for\r
    */\r
@@ -487,7 +502,7 @@ public class SearchCommand extends Pazpar2Command implements ServiceProxyCommand
 \r
   @Override\r
   public ServiceProxyCommand getSp() {\r
-    return this;\r
+    return new SearchCommandSp(this);\r
   }\r
 \r
   @Override\r