Fixes bug in state mutation in record command
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / commands / RecordCommand.java
index e9c4b54..8991dde 100644 (file)
@@ -11,15 +11,30 @@ import com.indexdata.mkjsf.pazpar2.data.RecordResponse;
 import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
 \r
+/**\r
+ * Represents a Pazpar2 <code>record</code> command, can be accessed by <code>pzreq.record</code>\r
+ * \r
+ * @author Niels Erik\r
+ *\r
+ */\r
 public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand {\r
 \r
   private static final long serialVersionUID = 2817539422114569506L;\r
   private static Logger logger = Logger.getLogger(RecordCommand.class);\r
+  private RecordCommandSp spCommand = null;\r
 \r
   public RecordCommand() {\r
     super("record");\r
   }\r
   \r
+  /**\r
+   * Special handling of record responses since they come in three distinctly different ways\r
+   * <ol>\r
+   *  <li>As a regular &lt;record&gt; document</li>\r
+   *  <li>In arbitrary XML format, in case of an offset request to get the native format</li>\r
+   *  <li>In binary (non XML) format</li>\r
+   * </ol> \r
+   */\r
   @Override\r
   public ResponseDataObject run() {\r
     ResponseDataObject responseObject = null;\r
@@ -56,58 +71,102 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand
     return responseObject;\r
   }\r
   \r
+  /**\r
+   * Sets the <code>id</code> parameter. See Pazpar2 documentation for details.\r
+   * \r
+   * @param recId record ID\r
+   */\r
   public void setId(String recId) {\r
     setParameter(new CommandParameter("id","=",recId));\r
   }\r
-  \r
+\r
+  /** \r
+   * Returns the <code>id</code> parameter value.\r
+   */\r
   public String getId () {\r
     return getParameterValue("id");\r
   }\r
-  \r
+\r
+  /**\r
+   * Sets the <code>offset</code> parameter. See Pazpar2 documentation for details.\r
+   */  \r
   public void setOffset (String offset) {\r
     setParameter(new CommandParameter("offset","=",offset));\r
   }\r
-  \r
+\r
+  /** \r
+   * Returns the <code>offset</code> parameter value.\r
+   */\r
   public String getOffset () {\r
     return getParameterValue("offset");\r
   }\r
   \r
+  /**\r
+   * Sets the <code>checksum</code> parameter. See Pazpar2 documentation for details.\r
+   */  \r
   public void setChecksum (String checksum) {\r
     setParameter(new CommandParameter("checksum","=",checksum));\r
   }\r
   \r
+  /** \r
+   * Returns the <code>checksum</code> parameter value.\r
+   */\r
   public String getChecksum () {\r
     return getParameterValue("checksum");\r
   }\r
   \r
+  /**\r
+   * Sets the <code>nativesyntax</code> parameter. See Pazpar2 documentation for details.\r
+   */    \r
   public void setNativesyntax (String nativesyntax) {\r
     setParameterInState(new CommandParameter("nativesyntax","=",nativesyntax));\r
   }\r
   \r
+  /** \r
+   * Returns the <code>nativesyntax</code> parameter value.\r
+   */\r
   public String getNativesyntax () {\r
     return getParameterValue("nativesyntax");\r
   }\r
   \r
+  /**\r
+   * Sets the <code>syntax</code> parameter. See Pazpar2 documentation for details.\r
+   */  \r
   public void setSyntax (String syntax) {\r
     setParameterInState(new CommandParameter("syntax","=",syntax));    \r
   }\r
   \r
+  /** \r
+   * Returns the <code>syntax</code> parameter value.\r
+   */\r
   public String getSyntax () {\r
     return getParameterValue("syntax");\r
   }\r
   \r
+  /**\r
+   * Sets the <code>esn</code> parameter. See Pazpar2 documentation for details.\r
+   */  \r
   public void setEsn (String esn) {\r
     setParameter(new CommandParameter("esn","=",esn));\r
   }\r
   \r
+  /** \r
+   * Returns the <code>esn</code> parameter value.\r
+   */\r
   public String getEsn () {\r
     return getParameterValue("esn");\r
   }\r
   \r
+  /**\r
+   * Sets the <code>binary</code> parameter. See Pazpar2 documentation for details.\r
+   */  \r
   public void setBinary (String binary) {\r
     setParameter(new CommandParameter("binary","=",binary));\r
   }\r
   \r
+  /** \r
+   * Returns the <code>binary</code> parameter value.\r
+   */\r
   public String getBinary () {\r
     return getParameterValue("binary");\r
   }\r
@@ -118,6 +177,7 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand
     for (String parameterName : parameters.keySet()) {\r
       newCommand.setParameterInState(parameters.get(parameterName).copy());      \r
     }    \r
+    newCommand.spCommand = new RecordCommandSp(newCommand);\r
     return newCommand;\r
   }\r
   \r
@@ -127,7 +187,10 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand
    * \r
    */\r
   public RecordCommandSp getSp () {\r
-    return new RecordCommandSp(this);\r
+    if (spCommand==null) {\r
+      spCommand = new RecordCommandSp(this);\r
+    } \r
+    return spCommand;\r
   }\r
 \r
   @Override\r